According to your description of SceneManager
's constructor in comments, your problem has to do with when the constructor is called.
I called it in the constructor of SceneManager, and as you can see it happens right after everything is created. Again to be on the safe side, I tried calling it before scenemanager, it didn't output anything. So it somehow gets destroyed in here somewhere?
At the beginning of whatever scope SceneManager scene
is declared, C++ implicitly constructs the object using the default constructor. Thus, scene
is actually constructed long before you get around to making a copy assignment on this line: scene = SceneManager ();
You are not "losing your OpenGL context", you simply do not have one when the scene
's constructor is called for the very first time. This why you usually declare these things like SceneManager* scene
and then defer instantiation of the object scene
points to until much later using new
. You can either do that, or stop doing this in the constructor. But you cannot do things the way you have them right now, or you will call GL functions before SDL even creates a context for them.