From d67044f220d47791a5ff18d6caa04356b942ea53 Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Wed, 14 Mar 2018 13:32:48 -0700 Subject: [PATCH 1/2] EntityScriptServer should wait for script engine to finish when stopping Script engine will still running and using EntityEditPacketSender, which is owned by EntityScriptServer, which was destroyed. https://highfidelity.manuscript.com/f/cases/11071/ --- assignment-client/src/scripts/EntityScriptServer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/assignment-client/src/scripts/EntityScriptServer.cpp b/assignment-client/src/scripts/EntityScriptServer.cpp index 60cb1e349b..8276807be7 100644 --- a/assignment-client/src/scripts/EntityScriptServer.cpp +++ b/assignment-client/src/scripts/EntityScriptServer.cpp @@ -476,6 +476,7 @@ void EntityScriptServer::clear() { // do this here (instead of in deleter) to avoid marshalling unload signals back to this thread _entitiesScriptEngine->unloadAllEntityScripts(); _entitiesScriptEngine->stop(); + _entitiesScriptEngine->waitTillDoneRunning(); } _entityViewer.clear(); From 4fd6eb559bda55ecc7869174fa50bf4dabc8e8ca Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Wed, 14 Mar 2018 17:06:38 -0700 Subject: [PATCH 2/2] Remove dangling packet sender pointer before it's invalid. --- assignment-client/src/scripts/EntityScriptServer.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/assignment-client/src/scripts/EntityScriptServer.cpp b/assignment-client/src/scripts/EntityScriptServer.cpp index 8276807be7..1255c18e71 100644 --- a/assignment-client/src/scripts/EntityScriptServer.cpp +++ b/assignment-client/src/scripts/EntityScriptServer.cpp @@ -566,8 +566,15 @@ void EntityScriptServer::handleOctreePacket(QSharedPointer mess void EntityScriptServer::aboutToFinish() { shutdownScriptEngine(); + auto entityScriptingInterface = DependencyManager::get(); // our entity tree is going to go away so tell that to the EntityScriptingInterface - DependencyManager::get()->setEntityTree(nullptr); + entityScriptingInterface->setEntityTree(nullptr); + + // Should always be true as they are singletons. + if (entityScriptingInterface->getPacketSender() == &_entityEditSender) { + // The packet sender is about to go away. + entityScriptingInterface->setPacketSender(nullptr); + } DependencyManager::get()->cleanup();