bottlenoselabs / c2cs

Generate C# bindings from a C header.
MIT License
250 stars 18 forks source link

Attempting to use `CBool.ToBoolean()` causes a `StackOverflowException` #66

Closed SpaceyChicken closed 2 years ago

SpaceyChicken commented 2 years ago

For example this code:

testCBool = true;
SDL2.SDL.Runtime.CBool.ToBoolean(testCBool);

Generates this error:

Stack overflow.
Repeat 9630 times:
--------------------------------
   at SDL2.SDL+Runtime+CBool.ToBoolean(CBool)
   at SDL2.SDL+Runtime+CBool.op_Implicit(CBool)
--------------------------------
   at VectorVenture.App.Initialize()
   at Katabasis.Game.DoInitialize()
   at Katabasis.Game.Run()
   at VectorVenture.Program.Main()

I can get around this by rewriting CBool.ToBoolean() like this:

public static bool ToBoolean(CBool value)
{
        //Workaround
        return value == CBool.FromBoolean(true);

        //Original code:
        //return Convert.ToBoolean(value);
}

But I'm assuming that's not identical to the C function.

lithiumtoast commented 2 years ago

Ah, thanks for that. It should be fixed with 34870f41483a1e69dd2295ea768f352d3f09c63c