Fix 32-bit windows (use stdcall convention)#85
Open
bmmogensen wants to merge 1 commit into
Open
Conversation
On 32-bit Windows, OpenGL functions use the stdcall calling convention (APIENTRY/WINAPI), but the @glfunc macro generates ccall without specifying a convention, which defaults to cdecl. With cdecl, the caller adjusts the stack after the call. With stdcall, the callee pops the arguments before returning. When Julia calls a stdcall function assuming cdecl, both sides adjust the stack — corrupting it by the size of the arguments on every call. In a render loop with multiple GL calls per frame (glViewport, glClearColor, glClear, etc.), this quickly leads to EXCEPTION_ACCESS_VIOLATION crashes in unrelated Julia internals. On 64-bit Windows (and all other platforms) there is only one calling convention, so this was never observed there. The fix adds a stdcall convention to both ccall paths (static opengl32.dll symbols and dynamic getprocaddress pointers) when Sys.iswindows() && Sys.WORD_SIZE == 32.
Member
|
Thank you! I'm wondering though, didnt Julia stop supporting win32? |
Author
|
https://julialang.org/downloads/support/ well it's still listed as a Tier 1 support. There are still many legacy enterprise applications that use 32-bit - believe it or not. That is also what lead me down this windy road :-) |
Member
|
Fair enough 🤷 Well, I guess it wont hurt! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On 32-bit Windows, OpenGL functions use the stdcall calling convention (APIENTRY/WINAPI), but the @glfunc macro generates ccall without specifying a convention, which defaults to cdecl.
With cdecl, the caller adjusts the stack after the call. With stdcall, the callee pops the arguments before returning. When Julia calls a stdcall function assuming cdecl, both sides adjust the stack — corrupting it by the size of the arguments on every call. In a render loop with multiple GL calls per frame (glViewport, glClearColor, glClear, etc.), this quickly leads to EXCEPTION_ACCESS_VIOLATION crashes in unrelated Julia internals.
On 64-bit Windows (and all other platforms) there is only one calling convention, so this was never observed there.
The fix adds a stdcall convention to both ccall paths (static opengl32.dll symbols and dynamic getprocaddress pointers) when Sys.iswindows() && Sys.WORD_SIZE == 32.