We have a problem with an application crashing when it calls a method that uses Double.MaxValue
. This is true running in the debugger as well as in the release version, and happens under 32-bit XP as well as under 64-bit Win 7.
If in the debugger I have a breakpoint on a line calling a method using Double.MaxValue
, any attempt to execute that method (F11, F10, F5) will stop the application with the friendly windows message that it has caused a problem and needs to be terminated.
Replacing Double.MaxValue with 9999999999 - which is ok for our application - makes the problem go away. Looking at the IL, literally all that changes is the constant.
The C# classes are being called from native code via a little C++ mixed mode bridge that has a native and a managed part. Our first idea was that the native part might have destroyed managed memory areas - but after replacing MaxValue with 9999999999 the application runs fine, and happily jumps back and forth between native and managed part.
We don't like to deliver trial & error software to the customer, and would love to hear any ideas about what could be going on??
--EDIT--
Here is the most cut-down version of the bridge that still crashes:
#include <stdio.h>
#include <tchar.h>
#include <vcclr.h>
// -------------------------------------------------------------
// Managed
// -------------------------------------------------------------
#pragma managed
using namespace System;
using namespace OurCompany::Tools;
// ACtion Move text window
__int32 AktionTextfensterMove (__int32 i32HNCTeil, __int32 i32Ansicht, void* pvoid)
{
return GUEManagedWrapper::TextfensterVerschieben (i32HNCTeil, i32Ansicht, nullptr);
}
// -------------------------------------------------------------
// Native
// -------------------------------------------------------------
#pragma unmanaged
#define DLLExport __declspec(dllexport)
extern "C"
{
// Action Move text window
DLLExport __int32 GUENMBridgeTextfensterMove (__int32 i32HNCTeil, __int32 i32Ansicht, void* pvoid)
{
return AktionTextfensterMove (i32HNCTeil, i32Ansicht, pvoid);
} }
---EDIT 2---
...and here is the C# code:
public static class GUEManagedWrapper
{
public static Int32 TextfensterVerschieben (Int32 i32HNCTeil, Int32 i32Ansicht, FizzBuzz fzzBzz)
{
fzzBzz= new FizzBuzz();
fzzBzz.fd = Double.MaxValue;
return 0;
}
}
public class FizzBuzz
{
public Double fd;
}
This crashes; replacing Double.MaxValue
with 9999999999 fixes the crash.