Bicubic's picture

Disposing textures and other resources

I'm not sure if I missed something, but it seems like OpenTK doesn't allow threads other than the creator to work with resources like textures.
While implementing a higher level texture class I found that calling GL.DeleteTextures in the destructor resulted in the following crash when the GC hit them: "No context is current in the calling thread (ThreadId: 2)."

Is there a way to set the current context for the thread? If there is no way to dispose of these resources like this, it might be nice to have the GameWindow class take a list of resources to dispose and do it in the main loop, so that the destructors won't dispose of the resources straight away but tell the GameWindow to do it asap. That's what I will be doing if there is no better known way.