loading fix

This commit is contained in:
HifiExperiments 2020-11-16 21:25:25 -08:00
parent 81940214bb
commit b6744588f4
4 changed files with 12 additions and 10 deletions

View file

@ -224,7 +224,7 @@ void EntityTreeRenderer::resetPersistentEntitiesScriptEngine() {
void EntityTreeRenderer::resetNonPersistentEntitiesScriptEngine() {
if (_nonPersistentEntitiesScriptEngine) {
_nonPersistentEntitiesScriptEngine->unloadAllEntityScripts(false);
_nonPersistentEntitiesScriptEngine->unloadAllEntityScripts(true);
_nonPersistentEntitiesScriptEngine->stop();
_nonPersistentEntitiesScriptEngine->waitTillDoneRunning();
_nonPersistentEntitiesScriptEngine->disconnectNonEssentialSignals();

View file

@ -451,7 +451,7 @@ void ScriptEngine::executeOnScriptThread(std::function<void()> function, const Q
function();
}
void ScriptEngine::waitTillDoneRunning() {
void ScriptEngine::waitTillDoneRunning(bool shutdown) {
// Engine should be stopped already, but be defensive
stop();
@ -520,12 +520,14 @@ void ScriptEngine::waitTillDoneRunning() {
}
}
// NOTE: This will be called on the main application thread (among other threads) from stopAllScripts.
// The thread will need to continue to process events, because
// the scripts will likely need to marshall messages across to the main thread, e.g.
// if they access Settings or Menu in any of their shutdown code. So:
// Process events for this thread, allowing invokeMethod calls to pass between threads.
QCoreApplication::processEvents();
if (shutdown) {
// NOTE: This will be called on the main application thread (among other threads) from stopAllScripts.
// The thread will need to continue to process events, because
// the scripts will likely need to marshall messages across to the main thread, e.g.
// if they access Settings or Menu in any of their shutdown code. So:
// Process events for this thread, allowing invokeMethod calls to pass between threads.
QCoreApplication::processEvents();
}
// Avoid a pure busy wait
QThread::yieldCurrentThread();

View file

@ -197,7 +197,7 @@ public:
Q_INVOKABLE void stop(bool marshal = false);
// Stop any evaluating scripts and wait for the scripting thread to finish.
void waitTillDoneRunning();
void waitTillDoneRunning(bool shutdown = false);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// NOTE - these are NOT intended to be public interfaces available to scripts, the are only Q_INVOKABLE so we can

View file

@ -182,7 +182,7 @@ void ScriptEngines::shutdownScripting() {
// want any of the scripts final "scriptEnding()" or pending "update()" methods from accessing
// any application state after we leave this stopAllScripts() method
qCDebug(scriptengine) << "waiting on script:" << scriptName;
scriptEngine->waitTillDoneRunning();
scriptEngine->waitTillDoneRunning(true);
qCDebug(scriptengine) << "done waiting on script:" << scriptName;
}
// Once the script is stopped, we can remove it from our set