raylib
raylib copied to clipboard
[rcore] Application crash on start-up when compiled with -march=native flag
WARNING: Please, read this note carefully before submitting a new issue:
It is important to realise that this is NOT A SUPPORT FORUM, this is for reproducible BUGS with raylib ONLY.
There are lots of generous and helpful people ready to help you out on raylib Discord forum or raylib reddit.
Remember that asking for support questions here actively takes developer time away from improving raylib.
Please, before submitting a new issue verify and check:
- [x] I tested it on latest raylib version from master branch
- [x] I checked there is no similar issue already reported
- [x] I checked the documentation on the wiki
- [x] My code has no errors or misuse of raylib
Issue description
when building any project with the flag "-march=native", at starting the built program, it crashes 2/3 of the time. Even the example projects in the site, simpler ones crash less often or never, but more complex ones do crash more.
Build command:
g++ main.cpp -o main.exe -lraylib -lopengl32 -lgdi32 -lwinmm -march=native -LC:\Users\XXX\Downloads\sampleProject -IC:\Users\XXX\Downloads\sampleProject
Build Structure:
the libraylib.a, raylib.h, main.cpp and main.exe in the same folder.
Steps to recreate:
grab any of the examples (like the split-screen one) and compile it with "-march=native" now it will crash or work sometimes when running.
Working Log:
INFO: Initializing raylib 5.5 INFO: Platform backend: DESKTOP (GLFW) INFO: Supported raylib modules: INFO: > rcore:..... loaded (mandatory) INFO: > rlgl:...... loaded (mandatory) INFO: > rshapes:... loaded (optional) INFO: > rtextures:. loaded (optional) INFO: > rtext:..... loaded (optional) INFO: > rmodels:... loaded (optional) INFO: > raudio:.... loaded (optional) INFO: DISPLAY: Device initialized successfully INFO: > Display size: 1920 x 1080 INFO: > Screen size: 800 x 440 INFO: > Render size: 800 x 440 INFO: > Viewport offsets: 0, 0 INFO: GLAD: OpenGL extensions loaded successfully INFO: GL: Supported extensions count: 230 INFO: GL: OpenGL device information: INFO: > Vendor: Intel INFO: > Renderer: Intel(R) UHD Graphics INFO: > Version: 3.3.0 - Build 27.20.100.8190 INFO: > GLSL: 3.30 - Build 27.20.100.8190 INFO: GL: VAO extension detected, VAO functions loaded successfully INFO: GL: NPOT textures extension detected, full NPOT textures supported INFO: GL: DXT compressed textures supported INFO: GL: ETC2/EAC compressed textures supported INFO: GL: ASTC compressed textures supported INFO: PLATFORM: DESKTOP (GLFW - Win32): Initialized successfully INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps) INFO: TEXTURE: [ID 1] Default texture loaded successfully INFO: SHADER: [ID 1] Vertex shader compiled successfully INFO: SHADER: [ID 2] Fragment shader compiled successfully INFO: SHADER: [ID 3] Program shader loaded successfully INFO: SHADER: [ID 3] Default shader loaded successfully INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU) INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU) INFO: RLGL: Default OpenGL state initialized successfully INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps) INFO: FONT: Default font loaded successfully (224 glyphs) INFO: SYSTEM: Working Directory: C:\Users\jeroc\Downloads\sampleProject INFO: TEXTURE: [ID 3] Texture loaded successfully (400x440 | R8G8B8A8 | 1 mipmaps) INFO: TEXTURE: [ID 1] Depth renderbuffer loaded successfully (32 bits) INFO: FBO: [ID 1] Framebuffer object created successfully INFO: TEXTURE: [ID 4] Texture loaded successfully (400x440 | R8G8B8A8 | 1 mipmaps) INFO: TEXTURE: [ID 2] Depth renderbuffer loaded successfully (32 bits) INFO: FBO: [ID 2] Framebuffer object created successfully INFO: TIMER: Target time per frame: 16.667 milliseconds INFO: FBO: [ID 1] Unloaded framebuffer from VRAM (GPU) INFO: FBO: [ID 2] Unloaded framebuffer from VRAM (GPU) INFO: TEXTURE: [ID 2] Unloaded texture data from VRAM (GPU) INFO: SHADER: [ID 3] Default shader unloaded successfully INFO: TEXTURE: [ID 1] Default texture unloaded successfully INFO: Window closed successfully
Not working Log:
INFO: Initializing raylib 5.5 INFO: Platform backend: DESKTOP (GLFW)
INFO: Supported raylib modules: INFO: > rcore:..... loaded (mandatory) INFO: > rlgl:...... loaded (mandatory) INFO: > rshapes:... loaded (optional) INFO: > rtextures:. loaded (optional) INFO: > rtext:..... loaded (optional) INFO: > rmodels:... loaded (optional) INFO: > raudio:.... loaded (optional) INFO: DISPLAY: Device initialized successfully
INFO: > Display size: 1920 x 1080 INFO: > Screen size: 800 x 440 INFO: > Render size: 800 x 440 INFO: > Viewport offsets: 0, 0 INFO: GLAD: OpenGL extensions loaded successfully INFO: GL: Supported extensions count: 230
INFO: GL: OpenGL device information: INFO: > Vendor: Intel INFO: > Renderer: Intel(R) UHD Graphics
INFO: > Version: 3.3.0 - Build 27.20.100.8190 INFO: > GLSL: 3.30 - Build 27.20.100.8190 INFO: GL: VAO extension detected, VAO functions loaded successfully INFO: GL: NPOT textures extension detected, full NPOT textures supported INFO: GL: DXT compressed textures supported INFO: GL: ETC2/EAC compressed textures supported INFO: GL: ASTC compressed textures supported INFO: PLATFORM: DESKTOP (GLFW - Win32): Initialized successfully INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps) INFO: TEXTURE: [ID 1] Default texture loaded successfully INFO: SHADER: [ID 1] Vertex shader compiled successfully INFO: SHADER: [ID 2] Fragment shader compiled successfully INFO: SHADER: [ID 3] Program shader loaded successfully INFO: SHADER: [ID 3] Default shader loaded successfully INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU) INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU) INFO: RLGL: Default OpenGL state initialized successfully INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps) INFO: FONT: Default font loaded successfully (224 glyphs) INFO: SYSTEM: Working Directory: C:\Users\jeroc\Downloads\sampleProject INFO: TEXTURE: [ID 3] Texture loaded successfully (400x440 | R8G8B8A8 | 1 mipmaps) INFO: TEXTURE: [ID 1] Depth renderbuffer loaded successfully (32 bits) INFO: FBO: [ID 1] Framebuffer object created successfully INFO: TEXTURE: [ID 4] Texture loaded successfully (400x440 | R8G8B8A8 | 1 mipmaps) INFO: TEXTURE: [ID 2] Depth renderbuffer loaded successfully (32 bits) INFO: FBO: [ID 2] Framebuffer object created successfully INFO: TIMER: Target time per frame: 16.667 milliseconds
Environment
Desktop Laptop Win10 OpenGl 4.6 and OpenGl ES 3.1 compatible. W64devkit gcc compiler. i5-10300H cpu Nividia gtx 1650 ti GPU
Issue Screenshot
Image of the app mere milliseconds before closing forcefully when just run:
Code Example
https://www.raylib.com/examples/core/loader.html?name=core_2d_camera_split_screen ^^^ The example of split-screen is one of the many crash causers.
Update Im not very knowledgeable in this stuff but this might be helpful: (split-screen example)
Thread 1 received signal SIGSEGV, Segmentation fault. 0x00007ff75b811729 in main () at main.cpp:87 87 BeginTextureMode(screenCamera1); Thread 1 received signal SIGSEGV, Segmentation fault. 0x00007ff75b811729 in main () at main.cpp:87 87 BeginTextureMode(screenCamera1); [Thread 6832.0x24a0 exited with code 3221225477] [Thread 6832.0x2958 exited with code 3221225477] [Thread 6832.0x2274 exited with code 3221225477] [Thread 6832.0x8a0 exited with code 3221225477]
Exception thrown at 0x00007FF75B811729 in main.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
https://discord.com/channels/426912293134270465/661385466766950403/1320127460708454532
For now im just going go with -O3
@Infinityridr Mmmh... no idea what can cause this crash but it seems it could be related to glfw and not raylib itself... could you try with another backend like SDL?
Im sorry but i couldnt find how to do that in the wiki, and setting the platform to SDL when building just gives error after errors.
You're running into a GCC bug, namely that GCC does not yet fully support AVX on Windows. It will produce aligned loads/stores on local variables which it has not aligned appropriately. Your example crashes for me on such a misaligned load, a 0xc0000005 error, which in GDB displays as "SIGSEGV" and which VS incorrectly displays address 0xFFFF…FFFF as the culprit. You can spot this by looking at the disassembly in any debugger (try layout asm in GDB), with RIP pointing right at the culprit.
Fortunately there's a workaround: Ask the assembler to assemble aligned loads/stores into unaligned loads/stores: pass -Wa,-muse-unaligned-vector-move alongside -march. When I use this the program no longer crashes. (I've considered hacking GNU as in w64devkit to always do this with at least AVX, to nip this in the bud at a relatively tiny cost.)
You can't reliably distribute a -march=native application, but you'll need this workaround for a more reasonable target like -march=x86-64-v3.
There's an added spin, a second GCC bug for x86 (not x64) that can crash similarly: GCC requires calls are made with a 16-byte-aligned stack, which is incompatible with all x86 calling conventions. Callbacks do not necessarily receive a 16-byte-aligned stack, and such callbacks include GLFW's windowProc, as seen in your stack trace. So on x86 you can wind up with similar misaligned loads/stores during callbacks when you use -march=native and similar. I've patched GCC to fix this in the next w64devkit release.
@skeeto Wow! Thank you very much for the detailed explanation!
PS. I'm a big fan of your work! Not only the w64devkit but also your amazing collection of articles! 💯
I think this issue can be closed.
Thanks for the kind words, @raysan5! I'm pleased w64devkit has had such a useful role in raylib.
I may have just fixed the GCC bug (https://github.com/skeeto/w64devkit/pull/196), so in the next w64devkit release this should no longer crash. I just confirmed it fixes this particular crash with the raylib example. At the very least your crash report here was useful as another test for my GCC patch, so thanks for taking the time to report it!
@skeeto Great! Thank you very much for the fix!