From 63b1e4497776509d3ead67c4d4e2f0015b894ad4 Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 29 Mar 2018 14:11:21 +0200 Subject: [PATCH] framework: fix pview crash when exit is called inside render_frame This can happen when a system event (eg. on macOS) triggers a terminate from within process_events. This is a workaround for a common error; the proper fix is not to put PandaFramework in the global scope. --- panda/src/framework/pandaFramework.cxx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/panda/src/framework/pandaFramework.cxx b/panda/src/framework/pandaFramework.cxx index d5c6b49829..30968e70b3 100644 --- a/panda/src/framework/pandaFramework.cxx +++ b/panda/src/framework/pandaFramework.cxx @@ -1391,11 +1391,17 @@ AsyncTask::DoneStatus PandaFramework:: task_igloop(GenericAsyncTask *task, void *data) { PandaFramework *self = (PandaFramework *)data; - if (self->_engine != (GraphicsEngine *)NULL) { - self->_engine->render_frame(); + // This exists to work around a crash that happens when the PandaFramework + // is destructed because the application is exited during render_frame(). + // The proper fix is not to instantiate PandaFramework in the global scope + // but many C++ applications (including pview) do this anyway. + PT(GraphicsEngine) engine = self->_engine; + if (engine != nullptr) { + engine->render_frame(); + return AsyncTask::DS_cont; + } else { + return AsyncTask::DS_done; } - - return AsyncTask::DS_cont; } /**