Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on Windows #13

Open
shining-luna opened this issue Feb 15, 2025 · 21 comments
Open

Crash on Windows #13

shining-luna opened this issue Feb 15, 2025 · 21 comments

Comments

@shining-luna
Copy link

Hi, I tried to setup this library on Windows but when I try to run the basic-window example, it crashes with the following message

CORRUPTION WARNING in SBCL pid 1392834716:
Memory fault at 0000000000000000 (pc=0000000000000000, fp=00000000005ff3a0, sp=00000000005ff368)34716
The integrity of this image is possibly compromised.
Continuing with fingers crossed.

debugger invoked on a SB-SYS:MEMORY-FAULT-ERROR in thread
#<THREAD tid=34716 "main thread" RUNNING {1100BA8093}>:
  Unhandled memory fault at #x0.

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit debugger, returning to top level.

("bogus stack frame")
Backtrace for: #<SB-THREAD:THREAD tid=34716 "main thread" RUNNING {1100BA8093}>
0: ("bogus stack frame")
1: ("foreign function: #x7FFC3FDCD71E")
2: ("foreign function: #x2000000C")
3: (SB-INT:SIMPLE-EVAL-IN-LEXENV (BASIC-WINDOW) #<NULL-LEXENV>)
4: (EVAL (BASIC-WINDOW))
@bohonghuang
Copy link
Owner

Could you provide more details? Please clear the cache in %AppData%/Local/cache/common-lisp, then evaluate (proclaim '(optimize (speed 0) (debug 3) (safety 0))) before (ql:quickload :claw-raylib) in the REPL, and check the errors. Also, which toolchain are you using? MSYS2's UCRT64 is tested.

@shining-luna
Copy link
Author

shining-luna commented Feb 15, 2025

Thank you for the quick reply! I've tried reinstalling everything a couple times. Now I get the error

Error opening shared object "C:\\Users\\...\\claw-raylib\\lib\\libraylib-adapter.dll": The specified module could not be found.

during (ql:quickload :claw-raylib).

Even though the dll is right there, it even shows its path!

I compiled the adapter using this command from a MSYS2 UCRT64 console:

gcc -O3 -fPIC -shared -o libraylib-adapter.dll libraylib-adapter.x86_64-pc-windows-gnu.c -I /c/raylib/raylib/src -L /c/raylib/raylib/src -lraylib -lwinmm -lgdi32

Google isn't showing anything relevant for that message. Do you have any clue how to go on?

@bohonghuang
Copy link
Owner

Could you please try out the following steps to help troubleshoot the issue?

  1. Run ldd <path-to-dll-file> in the MSYS2 terminal to check if the dynamic library has been compiled and linked successfully.
  2. Evaluate (cffi:load-foreign-library "<path-to-dll-file>") after (cffi:load-foreign-library "libraylib.dll") in the REPL, to test whether the DLL can be found and loaded by CFFI.

@shining-luna
Copy link
Author

I got it to find all the libraries again by moving all the dlls to System32.

ldd looks fine:

$ ldd /c/Windows/System32/libraylib-adapter.dll
        ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7ffd3b290000)
        KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7ffd390a0000)
        KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll (0x7ffd38990000)
        msvcrt.dll => /c/WINDOWS/System32/msvcrt.dll (0x7ffd3ada0000)
        ucrtbase.dll => /c/WINDOWS/System32/ucrtbase.dll (0x7ffd387d0000)
        WINMM.dll => /c/Windows/System32/WINMM.dll (0x7ffd301d0000)
        raylib.dll => /c/Windows/System32/raylib.dll (0x7ffc672c0000)
        GDI32.dll => /c/WINDOWS/System32/GDI32.dll (0x7ffd39cf0000)
        win32u.dll => /c/WINDOWS/System32/win32u.dll (0x7ffd38ea0000)
        gdi32full.dll => /c/WINDOWS/System32/gdi32full.dll (0x7ffd386b0000)
        msvcp_win.dll => /c/WINDOWS/System32/msvcp_win.dll (0x7ffd388f0000)
        USER32.dll => /c/WINDOWS/System32/USER32.dll (0x7ffd3aa90000)
        SHELL32.dll => /c/WINDOWS/System32/SHELL32.dll (0x7ffd39170000)
        IMM32.DLL => /c/WINDOWS/System32/IMM32.DLL (0x7ffd39d20000)

There are no errors at compilation, even with all debug flags turned on. Although the error at runtime still persists:

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: 2560 x 1440
INFO:     > Screen size:  1920 x 1080
INFO:     > Render size:  1920 x 1080
INFO:     > Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: GL: Supported extensions count: 403
INFO: GL: OpenGL device information:
INFO:     > Vendor:   NVIDIA Corporation
INFO:     > Renderer: NVIDIA GeForce RTX 3070/PCIe/SSE2
INFO:     > Version:  3.3.0 NVIDIA 572.16
INFO:     > GLSL:     3.30 NVIDIA via Cg compiler
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: 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\***
INFO: TIMER: Target time per frame: 16.667 milliseconds
CORRUPTION WARNING in SBCL pid 552835900:
Memory fault at 0000000000000000 (pc=0000000000000000, fp=00000000005ff4f8, sp=00000000005fee78)35900
The integrity of this image is possibly compromised.
Continuing with fingers crossed.

debugger invoked on a SB-SYS:MEMORY-FAULT-ERROR in thread
#<THREAD tid=35900 "main thread" RUNNING {1100B98093}>:
  Unhandled memory fault at #x0.

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit debugger, returning to top level.

("bogus stack frame")
***

@bohonghuang
Copy link
Owner

This is strange. Raylib seems properly initialized, and the GLFW window is created, but SBCL doesn’t capture stack info when the error happens. Not sure about the cause, but could you try:

  1. Run (raylib:vector2-zero) in REPL to check if libraylib-adapter.dll works.
  2. Test if the C version of Raylib compiles and runs, since the null pointer doesn’t seem Lisp-related.
  3. Get SBCL to output full stack info if possible (e.g., try compiling with (debug 3)).

@shining-luna
Copy link
Author

Thank you for your support! No luck yet, I'm afraid.

  1. Seems to work: #<RAYLIB:VECTOR2 :X 0.0 :Y 0.0 @0x00000000010227A0>
  2. I tried compiling the "Basic Window" Example from the raylib website using gcc -O3 -fpic -o test.exe test.c -I /c/raylib/raylib/src/ -L /c/raylib/raylib/src/ -lraylib -lwinmm -lgdi32 and that runs without any problems. So I guess C Raylib is not at fault here
  3. Unfortunately I am unable to get any stack info at all. Not even with (debug 3) proclaimed

@bohonghuang
Copy link
Owner

I would try to replicate this issue on Windows later. It would be helpful if you could narrow down the function where the error occurs in the example.

@shining-luna
Copy link
Author

Thank you! It seems to be raylib:clear-background that's causing the crash. This code runs without issue (although the text is not visible):

(raylib:with-window ("test" (200 200))
  (loop :until (raylib:window-should-close)
        :do (raylib:with-drawing 
             (raylib:draw-text "Congrats!" 0 0 20 raylib:+lightgray+))))

@shining-luna
Copy link
Author

Oh I'm not sure if that's relevant but I cloned the prebuild branch and not master. Just in case that changes something.

@bohonghuang
Copy link
Owner

Thank you! It seems to be raylib:clear-background that's causing the crash. This code runs without issue (although the text is not visible):

(raylib:with-window ("test" (200 200))
  (loop :until (raylib:window-should-close)
        :do (raylib:with-drawing 
             (raylib:draw-text "Congrats!" 0 0 20 raylib:+lightgray+))))

Could (raylib:clear-background (raylib:make-color)) work?

@shining-luna
Copy link
Author

Could (raylib:clear-background (raylib:make-color)) work?

Nope, same crash sadly

@bohonghuang
Copy link
Owner

Oh I'm not sure if that's relevant but I cloned the prebuild branch and not master. Just in case that changes something.

As long as the adapters can be compiled, linked, and loaded by Lisp, that won't be a problem.

@bohonghuang
Copy link
Owner

bohonghuang commented Feb 16, 2025

If raylib:clear-background is the only function that doesn't work for you, you could try out the combination of these 2 functions: https://github.com/raysan5/raylib/blob/b49c079b1d493bc84bd570a6d01ed4a4c1a499f0/src/rcore.c#L877-L878, which can be accessed via package rlgl, as a temporary workaround.

@shining-luna
Copy link
Author

Hm, this clears the screen and does not crash. But the text is not showing at all:

(raylib:with-window ("test" (800 600))
  (loop :until (raylib:window-should-close) 
    :do 
    (raylib:with-drawing 
      (rlgl:clear-color 255 255 255 255) 
      (rlgl:clear-screen-buffers) 
      (raylib:draw-text "Congrats!" 190 200 20 raylib:+lightgray+))))

@bohonghuang
Copy link
Owner

Unfortunately, unable to reproduce your issue 😰. Tested with the latest version of MSYS2 distribution (UCRT64) and SBCL 2.5.1 on Windows 11.

Image

Image

@bohonghuang
Copy link
Owner

bohonghuang commented Feb 18, 2025

@shining-luna How about you try the adpaters I compiled?

dlls.zip

@Ulhar
Copy link

Ulhar commented Feb 21, 2025

Been having similar issues to OP and here's something I'm confused about: what's libraylib.dll? I assumed that it would just be raylib.dll but renamed, but there isn't much to support that assumption either 😅
Maybe a full list of required DLLs/shared objects (and how to get them) would be good for clarity, hmm...

@bohonghuang
Copy link
Owner

bohonghuang commented Feb 21, 2025

The problem is that I cannot reproduce the issue in my MSYS2 environment at all. I've published a game on itch.io using SBCL + claw-raylib with MSYS2, but no voter reported this issue, so I suspect it might be a problem with the shared libraries, and the compiled adapters I provided above are worth a try. If anyone is willing to help diagnose the issue, I am ready to provide any support within my capabilities.

Been having similar issues to OP and here's something I'm confused about: what's libraylib.dll? I assumed that it would just be raylib.dll but renamed, but there isn't much to support that assumption either 😅

If you've properly installed raylib on MSYS2, the file should just lie in place (<path-to-msys2>/ucrt64/bin).

@Ulhar
Copy link

Ulhar commented Feb 21, 2025

If the DLLs are being put inside ucrt64/bin, does that mean SBCL or [other common lisp implementation of choice] needs to be run from within MSYS2? My existing SBCL installation is outside of MSYS2 (using the windows installer from http://www.sbcl.org/platform-table.html), so maybe running it "outside" is how this issue comes up?
(I'm going to try to get SBCL running "inside" MSYS2 to see if that makes a difference, I'll report back after)

@bohonghuang
Copy link
Owner

If the DLLs are being put inside ucrt64/bin, does that mean SBCL or [other common lisp implementation of choice] needs to be run from within MSYS2?

As long as you add ucrt64/bin and usr/bin to PATH, you can run SBCL in Emacs or Windows Terminal.

@Ulhar
Copy link

Ulhar commented Feb 22, 2025

I moreso mean whether there's a difference between running the Windows release of SBCL versus compiling it from source in the MSYS2 environment and running that. That said, it didn't seem to yield any difference, so that probably isn't the issue...

Also, I forgot to mention, but Nano Towers does work without issues; I tried borrowing the DLLs from there to see if they'd work better (and switched claw-raylib to the prebuild-5.0 branch) but it still errors in the same fashion, so I'm thinking it might actually be an issue with the Lisp code in the prebuild branches. When you were trying to reproduce, did you go through the full process of generating the bindings from step 1, or did you use the prebuild branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants