Closed Naios closed 3 years ago
Thanks for this pull request and the analysis. I can confirm that this can be an issue. I think this is related to the general problems around static usage of memory. However, if we're providing an interface to initialize static memory, we should provide an interface for deinitialization as well.
For an even more sustainable solution in the long run, I'm thinking about less usage of static memory (even if this comes with less convenience for the users) and some convenience functionality to patch the usage to the old behavior.
I'll merge this PR and add you to the list of contributors.
The
destroy
API function makes it possible to cleanup the internal library state safely, it does not cleanup any resources.This is required because we are allowed to pass
std::function
like callables to the API which have a vtable that is placed inside the users code and could be possibly kept referenced while the user code was unloaded already.In the end it leads to a crash because the corresponding vtable placed in the users shared library is not present anymore on destruction of the glbinding library, because the using library was destroyed beforehand.
The main issue is that we can't reset
s_firstGetProcAddress()
properly when it was set initially because of:https://github.com/cginternals/glbinding/blob/2bcfb663651e0255db41690b0585baa5c8c29aab/source/glbinding/source/Binding.cpp#L172-L177
Maybe it could be also useful to provide a method for destroying the
thread_local
state of a calling thread, but it should be cleaned up when the corresponding thread exits anyway.