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

Unexpected behavior when trying to load font in another thread #47

Open
maximilian-mueller67 opened this issue Apr 17, 2020 · 1 comment

Comments

@maximilian-mueller67
Copy link

It seems trying to load a font (FC_LoadFont(...)) on a thread that isn't the main rendering one will cause an exception.

If i try to use a thread: std::thread(&SWindow::doFrame, this, onFrame).detach(); i get an access violation exception in nvd3dumx.dll, which is caused by the FC_LoadFont function.
The strange thing is if i debug through my function step by step no exception is thrown, however the debugger doesn't jump to the next line of code, it just does nothing.

@grimfang4
Copy link
Owner

Doing multithreaded graphics is currently perilous. D3D and OpenGL require some careful attention to the rendering context or else you'll get crashes like this. SDL does not implement that level of care needed for it to support multithreaded access to GPU resources. I don't think you can unbind an SDL_Renderer. Vulkan is much better designed in this regard, but I don't know if SDL's access pattern using that renderer supports multithreading anyway.
https://www.khronos.org/opengl/wiki/OpenGL_and_multithreading

When using SDL_Renderer, it is best to keep all of your calls to the GPU on the main thread. Things like loading an SDL_Surface or game logic can be done in a separate thread and communicated back to the main thread. You can do multithreaded work if you control the rendering context, using D3D, OpenGL, or Vulkan directly, but then using SDL_FontCache might not be ideal.

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

2 participants