editor: delete viewport widgets immediately

I don't know why the viewports are deleted with deleteLater(), but it leads
to an OpenGL context getting deselected behind our back, and so we don't know
when is a good time to re-select it. This leads to termination of the engine
when selecting File->Close (Ctrl+W) in the editor, because the graphics
re-initialization fails with no GL context active.

Instead, just delete the viewport widget immediately, which works fine at
least on Linux. This is also recommended by the Qt documentation at
http://doc.qt.io/qt-5/qopenglwidget.html.
console-destruction
Armin Burgmeier 2016-10-01 13:50:21 -10:00
parent 4e7b396d31
commit e39a3a40f7
3 changed files with 19 additions and 6 deletions

View File

@ -94,8 +94,8 @@ void C4ConsoleGUI::DeleteConsoleWindow()
{
if (Active)
{
state->DeleteConsoleWindow();
Active = false;
state->DeleteConsoleWindow();
}
}

View File

@ -755,8 +755,8 @@ void C4ConsoleGUIState::DeleteConsoleWindow()
auto vp = viewports.front();
viewports.erase(viewports.begin());
vp->deleteLater();
viewport_area->removeDockWidget(vp);
delete vp;
}
client_actions.clear();
@ -922,8 +922,15 @@ void C4ConsoleGUIState::RemoveViewport(C4ViewportWindow *cvp)
if (vp->GetViewportWindow() == cvp)
{
viewport_area->removeDockWidget(vp);
vp->deleteLater();
iter = viewports.erase(iter);
// cannot use deleteLater here because Qt will then
// still select/deselect the viewport's GL context
// behind the scenes, leaving us with an unselected
// GL context.
// Documented at http://doc.qt.io/qt-5/qopenglwidget.html
// Instead, delete the viewport widget directly.
delete vp;
}
else
{

View File

@ -524,9 +524,15 @@ void C4ConsoleQtViewportDockWidget::closeEvent(QCloseEvent * event)
QDockWidget::closeEvent(event);
if (event->isAccepted())
{
if (cvp) cvp->Close();
cvp = NULL;
deleteLater();
if (cvp)
{
// This causes "this" to be deleted:
cvp->Close();
}
else
{
deleteLater();
}
}
}