JuliaGL / GLFW.jl

Julia interface to GLFW, a multi-platform library for creating windows with OpenGL contexts and managing input and events.
http://www.glfw.org/
MIT License
138 stars 32 forks source link

Going to fullscreen causes a crash on macOS (Apple M1) #221

Closed cafaxo closed 2 years ago

cafaxo commented 2 years ago

I am using the official 1.7.2 (still experimental?) Julia build for the Apple M1 processor on macOS 12.2.

When I run

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.7.2 (2022-02-06)
 _/ |\__'_|_|_|\__'_|  |  HEAD/bf53498635 (fork: 461 commits, 247 days)
|__/                   |

julia> using GLFW

julia> function try_debug()
           window = GLFW.CreateWindow(100, 100, "helloworld")
           GLFW.MakeContextCurrent(window)

           while !GLFW.WindowShouldClose(window)
               GLFW.SwapBuffers(window)
               GLFW.PollEvents()
           end

           GLFW.DestroyWindow(window)
       end
try_debug (generic function with 1 method)

julia> try_debug()

and then click on the green fullscreen button in the upper left corner, the window freezes.

Sometimes, I then additionally get

julia> try_debug()
2022-02-11 20:40:31.733 julia[1343:47970] *** Assertion failure in +[NSEvent startPeriodicEventsAfterDelay:withPeriod:], NSEvent.m:4457

This also happens when I add macOS-appropriate window hints like GLFW.WindowHint(GLFW.OPENGL_PROFILE, GLFW.OPENGL_CORE_PROFILE) and GLFW.WindowHint(GLFW.OPENGL_FORWARD_COMPAT, true).

This might be an upstream issue... I will try to figure that out and close this issue if it happens when directly invoking GLFW from C. Nope, there is no crash when using upstream GLFW 3.3.6 directly from C.

Edit: When I put the GLFW example code from https://www.glfw.org/documentation into a dylib and call this dylib using ccall, the crash/freeze issue also happens. Steps to reproduce:

  1. Put the example code from https://www.glfw.org/documentation into a file called main.c and comment out the glClear call (so that we don't have to link against any other libs).

  2. Install GLFW and pkg-config through homebrew and run cc $(pkg-config --cflags glfw3) -o main main.c $(pkg-config --libs glfw3).

  3. Run ./main. The window should go to fullscreen when clicking the green button without any problems.

  4. Now build a dylib using cc $(pkg-config --cflags glfw3) -dynamiclib -o main.dylib main.c $(pkg-config --libs glfw3)

  5. Run ccall((:main, "/path/to/main.dylib"), Cint, ()). Click on the green fullscreen button in the upper left corner. The window freezes/the macOS spinning wheel of death appears.

cafaxo commented 2 years ago

This issue does not occur with a more recent Julia build (https://github.com/JuliaLang/julia/commit/76fa182).