fjvallarino/monomer

Unable to make GL context current.

Closed this issue · 5 comments

Hi, getting this on NixOS with nix run at latest master.

lc@nixos ~/monomer (main)> nix run

Renderer: NVIDIA GeForce RTX 3060/PCIe/SSE2
Version: 3.2.0 NVIDIA 510.39.01
tutorial: SDLCallFailed {sdlExceptionCaller = "SDL.Video.OpenGL.glMakeCurrent", sdlFunction = "SDL_GL_MakeCurrent", sdlExceptionError = "Unable to make GL context current"}

Hi @locallycompact!

This seems to be an issue with NVIDIA's driver on Linux, which fails when creating a GL context in a thread. Using a secondary thread allows content to dynamically adjust to the size of the window when the latter is being resized.

Adding appRenderOnMainThread to the application startup options should solve the issue (although content will only adjust to the new window size after the resize action is complete). Taking the monomer-starter application as an example, it should be something like:

main :: IO ()
main = do
  startApp model handleEvent buildUI config
  where
    config = [
      ...
      appInitEvent AppInit,
      appRenderOnMainThread
      ]
    model = AppModel 0

I just pushed a branch, fix/gl-make-current, that implements a fallback mechanism to use main thread rendering when the driver fails to make the rendering context active on a secondary thread.

Using this branch, the solution I mentioned in the previous comment should not be necessary, and the examples are expected to work without changes.

Thank you very much. The examples work except for the opengl one which doesn't seem to show whatever should be there. Just a gray box.

I pushed an additional commit to the same branch which fixes the issue on the OpenGL example running in single-threaded mode. I think it should work now.

After testing on Windows, Linux, and macOS, these changes have been merged to main. A new release, 1.4.0.0, has been created today including these changes.

I'll close the issue now. Please re-open or create a new one if you think something is missing. Thanks!