Monogame: PInvokeStackImbalance in GL.ClearDepth

Created on 3 Feb 2017  Â·  6Comments  Â·  Source: MonoGame/MonoGame

So we had two developers using the DesktopGL build of MG run into the PInvokeStackImbalance debug assist warning when testing their game in the debugger.

For one it happened on the first call to render a scene. The other developer was able to render 1000s of frames in the game's UI before getting into gameplay where suddenly PInvokeStackImbalance errors started occurring.

For both the error only occurred on GL.ClearDepth and for both disabling the PInvokeStackImbalance debug assistant feature allows the game to run seemingly like normal.

Still I see information out there that this is a real bug that needs fixing:

http://codenition.blogspot.com/2010/05/pinvokestackimbalance-in-net-40i-beg.html

But it seems curious that it didn't occur on the first calls to GL.ClearDepth for one of the developers.

Help Wanted OpenGL

Most helpful comment

You can use something similar to what I did for the mobile side of the
house

https://github.com/MonoGame/MonoGame/pull/5410/files#diff-2590f64f9edb856d8dfa1f1000e5f84aR1115
https://github.com/MonoGame/MonoGame/pull/5410/files#diff-2590f64f9edb856d8dfa1f1000e5f84aR1270

And have overrides for float/double

On 3 February 2017 at 11:35, Thomas Altenburger notifications@github.com
wrote:

Our code doesn't reach GL.ClearDepth() so I never encountered this, but a
quick look at the GL documentation and the binding shows an imbalance in
the signature:

public delegate void ClearDepthDelegate (float depth); uses a float while
the loaded entry point is glClearDepth which according to the GL
documentation
https://www.opengl.org/sdk/docs/man/html/glClearDepth.xhtml, takes a
double.

glClearDepthf`exists, but only since GL 4.1, so I believe that the best route would be to update the delegate to usedouble to keep it GL
2.0.

I'll be able to push a PR later today.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/MonoGame/MonoGame/issues/5455#issuecomment-277227088,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAxeeeFbFhU25Am42MMMKSQihN9PkhOSks5rYxD-gaJpZM4L17A0
.

All 6 comments

@cra0zy @mrhelmut @dellis1972 ?

The OpenGL calls are all using the default CallingConvention for the platform.

Our code doesn't reach GL.ClearDepth() so I never encountered this, but a quick look at the GL documentation and the binding shows an imbalance in the signature:

public delegate void ClearDepthDelegate (float depth); uses a float while the loaded entry point is glClearDepth which according to the GL documentation, takes a double.

glClearDepthf exists, but only since GL 4.1, so I believe that the best route would be to update the delegate to use double to keep it GL 2.0.

Would you like me to push a PR?

You can use something similar to what I did for the mobile side of the
house

https://github.com/MonoGame/MonoGame/pull/5410/files#diff-2590f64f9edb856d8dfa1f1000e5f84aR1115
https://github.com/MonoGame/MonoGame/pull/5410/files#diff-2590f64f9edb856d8dfa1f1000e5f84aR1270

And have overrides for float/double

On 3 February 2017 at 11:35, Thomas Altenburger notifications@github.com
wrote:

Our code doesn't reach GL.ClearDepth() so I never encountered this, but a
quick look at the GL documentation and the binding shows an imbalance in
the signature:

public delegate void ClearDepthDelegate (float depth); uses a float while
the loaded entry point is glClearDepth which according to the GL
documentation
https://www.opengl.org/sdk/docs/man/html/glClearDepth.xhtml, takes a
double.

glClearDepthf`exists, but only since GL 4.1, so I believe that the best route would be to update the delegate to usedouble to keep it GL
2.0.

I'll be able to push a PR later today.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/MonoGame/MonoGame/issues/5455#issuecomment-277227088,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAxeeeFbFhU25Am42MMMKSQihN9PkhOSks5rYxD-gaJpZM4L17A0
.

an imbalance in the signature

That would certainly cause the PInvokeStackImbalance warning. Thanks @mrhelmut !

@mrhelmut - I don't think this ever got fixed right?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Halofreak1990 picture Halofreak1990  Â·  4Comments

tomspilman picture tomspilman  Â·  4Comments

bjornenalfa picture bjornenalfa  Â·  5Comments

Jjagg picture Jjagg  Â·  5Comments

dazinator picture dazinator  Â·  5Comments