Fix crash on shutdown

a) make sure the context is deselected on destruction, so that
   CStdGL::Clear() destructor doesn't try to deselect a non-existing context.
b) Calling Clear() in CStdGLCtx::~CStdGLCtx() does only call
   CStdGLCtx::Clear(), even though Clear() is virtual. The reason is that by
   the time the CStdGLCtx destructor is executed, the CStdGLCtxQt part of the
   object has already been destructed. Therefore, make CStdGLCtx::Clear() safe
   to be run without the context ever having been initialized, and explicitly
   call CStdGLCtxQt::Clear() in CStdGLCtxQt::~CStdGLCtxQt(). This is certainly
   not the most elegant way to handle this, but it should do the job for now.
qteditor
Armin Burgmeier 2016-03-25 21:02:31 -07:00
parent cf708a7cb1
commit 208cb12b2e
2 changed files with 6 additions and 3 deletions

View File

@ -152,7 +152,7 @@ class CStdGLCtxQt : public CStdGLCtx
{
public:
CStdGLCtxQt();
//~CStdGLCtxQt();
virtual ~CStdGLCtxQt() { Clear(); }
void Clear(bool multisample_change = false) override; // clear objects
bool Init(C4Window * pWindow, C4AbstractApp *pApp) override;

View File

@ -570,11 +570,12 @@ bool CStdGLCtx::PageFlip()
#elif defined(USE_SDL_MAINLOOP)
CStdGLCtx::CStdGLCtx(): pWindow(0), this_context(contexts.end()) { }
CStdGLCtx::CStdGLCtx(): pWindow(0), this_context(contexts.end()) { ctx = NULL; }
void CStdGLCtx::Clear(bool multisample_change)
{
SDL_GL_DeleteContext(ctx);
Deselect();
if (ctx) SDL_GL_DeleteContext(ctx);
ctx = 0;
pWindow = 0;
@ -659,6 +660,8 @@ CStdGLCtxQt::CStdGLCtxQt() { context = NULL; surface = NULL; }
void CStdGLCtxQt::Clear(bool multisample_change)
{
Deselect();
if (context)
{
if (!pWindow->glwidget) delete context;