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

s_framebuffer isn't thread safe #6

Open
wtholliday opened this issue Jun 7, 2018 · 7 comments
Open

s_framebuffer isn't thread safe #6

wtholliday opened this issue Jun 7, 2018 · 7 comments

Comments

@wtholliday
Copy link

s_framebuffer is a global variable and isn't thread safe.

Furthermore, mnvgDeleteFramebuffer leaves s_framebuffer dangling.

@olliwang
Copy link
Member

olliwang commented Jun 7, 2018

nanovg itself is not thread safe as mentioned in memononen/nanovg#292.

s_framebuffer is only a weak reference to the currently binded framebuffer through mnvgBindFramebuffer(). Users should call mnvgBindFramebuffer(NULL) manually afterward. The logic behind mnvgCreateFramebuffer(), mnvgDeleteFramebuffer() and mnvgBindFramebuffer() basically follow the corresponded functions defined in nanovg_gl_utils.h.

@wtholliday
Copy link
Author

How unfortunate. Where is the global state in nanovg?

@wtholliday
Copy link
Author

I couldn't find any global state in nanovg itself. Perhaps it is ok to use different nanovg contexts on different threads? Obviously, you can't use a single context in multiple threads.

@olliwang
Copy link
Member

olliwang commented Jun 7, 2018

I didn't test multithreading environment. But I think it's ok to move the global s_framebuffer into MNVGcontext and renamed to bindedFramebuffer.

@wtholliday
Copy link
Author

boundFramebuffer would be the grammatically correct name :)

@olliwang
Copy link
Member

olliwang commented Jun 7, 2018

Thanks for correction. Do you have multithreading environment to test the result? There may need an additional mnvgUnbindFramebuffer() function to make the changes work. However, that would break the consistency of original nanovg APIs. Or, can you test the GL backend with multithreading environment? If it doesn't work anyway. Then no bother to make the changes.

@wtholliday
Copy link
Author

I'm only rendering on a single thread at a time.

The way I did it, calling mnvgBindFramebuffer(nvg, 0) unbinds.

Here's my change: wtholliday@e2c9b99

I think it's ok for the backend APIs to differ a little.

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