History

more hacking on script shutdown behavior

ZappoMan committed 11 years ago

Commit fd93b991 parent 6be8f4c4 files · +231 −57Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 4 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+214−50
@@ -94,33 +94,32 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam · 93 unmodified lines
9494 _isUserLoaded(false),
9595 _arrayBufferClass(new ArrayBufferClass(this))
9696 {
97− qDebug() << "ScriptEngine::ScriptEngine() " << getFilename() << "[" << ((void*)this) << "]" << " -------- BEGIN -----------";
9897 _allScriptsMutex.lock();
9998 _allKnownScriptEngines.insert(this);
10099 _allScriptsMutex.unlock();
101− qDebug() << "ScriptEngine::ScriptEngine() " << getFilename() << " -------- DONE -----------";
102100 }
103101
104102 ScriptEngine::~ScriptEngine() {
105− qDebug() << "ScriptEngine::~ScriptEngine() " << getFilename() << "[" << ((void*)this) << "]" << " -------- BEGIN -----------";
103+ qDebug() << "ScriptEngine::~ScriptEngine() ------- BEGIN ------- script:" << getFilename();
104+ // If we're not already in the middle of stopping all scripts, then we should remove ourselves
105+ // from the list of running scripts. We don't do this if we're in the process of stopping all scripts
106+ // because that method removes scripts from its list as it iterates them
106107 if (!_stoppingAllScripts) {
107108 _allScriptsMutex.lock();
108− qDebug() << "ScriptEngine::~ScriptEngine() " << getFilename() << " removing from list of scripts";
109109 _allKnownScriptEngines.remove(this);
110110 _allScriptsMutex.unlock();
111− } else {
112− qDebug() << "ScriptEngine::~ScriptEngine() " << getFilename() << " NOT removing from list of scripts here...";
113111 }
114− qDebug() << "ScriptEngine::~ScriptEngine() " << getFilename() << " -------- DONE -----------";
112+ qDebug() << "ScriptEngine::~ScriptEngine() ------- END ------- script:" << getFilename();
115113 }
116114
117115 QSet<ScriptEngine*> ScriptEngine::_allKnownScriptEngines;
118116 QMutex ScriptEngine::_allScriptsMutex;
119117 bool ScriptEngine::_stoppingAllScripts = false;
118+bool ScriptEngine::_doneRunningThisScript = false;
120119
121120 void ScriptEngine::stopAllScripts(QObject* application) {
121+ qDebug() << "ScriptEngine::stopAllScripts() ------- BEGIN -------";
122122
123− qDebug() << "ScriptEngine::stopAllScripts() -------- BEGIN -----------";
124123 _allScriptsMutex.lock();
125124 _stoppingAllScripts = true;
126125
@@ -128,44 +127,92 @@ void ScriptEngine::stopAllScripts(QObject* application) { · 1 unmodified line
128127 while (i.hasNext()) {
129128 ScriptEngine* scriptEngine = i.next();
130129
131− qDebug() << "ScriptEngine::stopAllScripts() scriptEngine: " << (void*)scriptEngine;
132−
133130 QString scriptName = scriptEngine->getFilename();
134131
135− qDebug() << "ScriptEngine::stopAllScripts() considering script: " << scriptName << "evaluatePending:" << scriptEngine->evaluatePending();
132+ qDebug() << "ScriptEngine::stopAllScripts() considering:" << scriptName
133+ << "isRunning():" << scriptEngine->isRunning()
134+ << "evaluatePending():" << scriptEngine->evaluatePending();
136135
137136 // NOTE: typically all script engines are running. But there's at least one known exception to this, the
138137 // "entities sandbox" which is only used to evaluate entities scripts to test their validity before using
139138 // them. We don't need to stop scripts that aren't running.
140139 if (scriptEngine->isRunning()) {
140+
141+ // If the script is running, but still evaluating then we need to wait for its evaluation step to
142+ // complete. After that we can handle the stop process appropriately
141143 if (scriptEngine->evaluatePending()) {
142− qDebug() << "ScriptEngine::stopAllScripts() handling script: " << scriptName << "line:" << __LINE__ << "waiting for evaluation to complete....";
143− QEventLoop loop;
144− QObject::connect(scriptEngine, &ScriptEngine::evaluationFinished, &loop, &QEventLoop::quit);
145− loop.exec();
146− qDebug() << "ScriptEngine::stopAllScripts() handling script: " << scriptName << "line:" << __LINE__ << "evaluation complete....";
144+ while (scriptEngine->evaluatePending()) {
145+ QEventLoop loop;
146+ QObject::connect(scriptEngine, &ScriptEngine::evaluationFinished, &loop, &QEventLoop::quit);
147+ qDebug() << "ScriptEngine::stopAllScripts() while(evaluatePending()) STARTING loop.exec() script:" << scriptName;
148+ loop.exec();
149+ qDebug() << "ScriptEngine::stopAllScripts() while(evaluatePending()) AFTER loop.exec() script:" << scriptName;
150+ }
147151 }
148152
149− qDebug() << "ScriptEngine::stopAllScripts() handling script: " << scriptName << "line:" << __LINE__;
150−
151− QEventLoop loop;
152− QObject::connect(scriptEngine, &ScriptEngine::doneRunning, &loop, &QEventLoop::quit);
153−
154− qDebug() << "ScriptEngine::stopAllScripts() handling script: " << scriptName << "line:" << __LINE__;
155153 scriptEngine->disconnect(application);
156− qDebug() << "ScriptEngine::stopAllScripts() handling script: " << scriptName << "line:" << __LINE__;
157154 scriptEngine->stop();
158− qDebug() << "ScriptEngine::stopAllScripts() handling script: " << scriptName << "line:" << __LINE__;
159− loop.exec();
160− qDebug() << "ScriptEngine::stopAllScripts() handling script: " << scriptName << "line:" << __LINE__;
155+
156+ qDebug() << "ScriptEngine::stopAllScripts() -- WAITING for waitTillDoneRunning() script:" << scriptName;
157+ scriptEngine->waitTillDoneRunning();
158+ qDebug() << "ScriptEngine::stopAllScripts() -- AFTER waitTillDoneRunning() script:" << scriptName;
161159 i.remove();
162160 } else {
163− qDebug() << "ScriptEngine::stopAllScripts() script: " << scriptName << " was not running... skipping it's stop() call.";
164161 }
165162 }
166163 _stoppingAllScripts = false;
167164 _allScriptsMutex.unlock();
168− qDebug() << "ScriptEngine::stopAllScripts() -------- DONE -----------";
165+ qDebug() << "ScriptEngine::stopAllScripts() ------- DONE -------";
166+}
167+
168+
169+void ScriptEngine::waitTillDoneRunning() {
170+ QString scriptName = getFilename();
171+ qDebug() << "ScriptEngine::waitTillDoneRunning() ------- BEGIN ------- script:" << scriptName;
172+ qDebug() << " _isFinished:" << _isFinished;
173+ qDebug() << " _isRunning:" << _isRunning;
174+ qDebug() << " _isInitialized:" << _isInitialized;
175+ qDebug() << " _evaluatesPending:" << _evaluatesPending;
176+
177+ if (_isRunning) {
178+ qDebug() << "ScriptEngine::waitTillDoneRunning() SETTING _doneRunningThisScript = false ################################### line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
179+ _doneRunningThisScript = false;
180+ _isWaitingForDoneRunning = true;
181+
182+ // What can we do here???
183+ // we will be calling this on the main Application thread, inside of stopAllScripts()
184+ // we want the application thread to continue to process events, because the script will
185+ // likely need to marshall messages across to the main thread.
186+ while (!_doneRunningThisScript && _isRunning) {
187+
188+ // and run a QEventLoop???
189+ QEventLoop loop;
190+ QObject::connect(this, &ScriptEngine::doneRunning, &loop, &QEventLoop::quit);
191+ qDebug() << "ScriptEngine::waitTillDoneRunning() STARTING loop.exec() script:" << scriptName;
192+ qDebug() << " _doneRunningThisScript:" << _doneRunningThisScript;
193+ qDebug() << " _isRunning:" << _isRunning;
194+ qDebug() << " _isWaitingForDoneRunning:" << _isWaitingForDoneRunning;
195+ qDebug() << " _isFinished:" << _isFinished;
196+ qDebug() << " _isInitialized:" << _isInitialized;
197+ qDebug() << " _evaluatesPending:" << _evaluatesPending;
198+ loop.exec();
199+ qDebug() << "ScriptEngine::waitTillDoneRunning() AFTER loop.exec() script:" << scriptName;
200+
201+ // process events
202+ qDebug() << "ScriptEngine::waitTillDoneRunning() STARTING QCoreApplication::processEvents() script:" << scriptName;
203+ QCoreApplication::processEvents();
204+ qDebug() << "ScriptEngine::waitTillDoneRunning() AFTER QCoreApplication::processEvents() script:" << scriptName;
205+
206+ if (_doneRunningThisScript) {
207+ qDebug() << "ScriptEngine::waitTillDoneRunning() _doneRunningThisScript after processEvents... breaking!!! script:" << scriptName;
208+ break;
209+ }
210+ }
211+
212+ _isWaitingForDoneRunning = false;
213+ }
214+
215+ qDebug() << "ScriptEngine::waitTillDoneRunning() ------- DONE ------- script:" << scriptName;
169216 }
170217
171218 QString ScriptEngine::getFilename() const {
@@ -377,12 +424,23 @@ void ScriptEngine::registerGetterSetter(const QString& name, QScriptEngine::Func · 205 unmodified lines
377424 }
378425
379426 void ScriptEngine::evaluate() {
427+ if (_stoppingAllScripts) {
428+ qDebug() << "ScriptEngine::evaluate() while shutting down is ignored...";
429+ qDebug() << " parent script:" << getFilename() << "[" << this << "]";
430+ return; // bail early
431+ }
432+
433+ qDebug() << "ScriptEngine::evaluate() -- BEGIN script:" << getFilename() << "[" << this << "]";
380434 if (!_isInitialized) {
381435 init();
382436 }
383437
438+ qDebug() << "ScriptEngine::evaluate() -- about to call own evaluate(program) script:" << getFilename() << "[" << this << "]";
384439 QScriptValue result = evaluate(_scriptContents);
440+ qDebug() << "ScriptEngine::evaluate() -- AFTER own evaluate(program) script:" << getFilename() << "[" << this << "]";
385441
442+ // TODO: why do we check this twice? It seems like the call to clearExcpetions() in the lower level evaluate call
443+ // will cause this code to never actually run...
386444 if (hasUncaughtException()) {
387445 int line = uncaughtExceptionLineNumber();
388446 qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString();
@@ -392,17 +450,30 @@ void ScriptEngine::evaluate() { · 3 unmodified lines
392450 }
393451
394452 QScriptValue ScriptEngine::evaluate(const QString& program, const QString& fileName, int lineNumber) {
395− qDebug() << "ScriptEngine::evaluate() " << getFilename() << " line:" << __LINE__;
396− _evaluatePending = true;
453+ if (_stoppingAllScripts) {
454+ qDebug() << "ScriptEngine::evaluate(program) while shutting down is ignored...";
455+ qDebug() << " parent script:" << getFilename() << "[" << this << "]";
456+ return QScriptValue(); // bail early
457+ }
458+
459+ qDebug() << "ScriptEngine::evaluate(program) -- BEGIN script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";
460+ _evaluatesPending++;
461+ qDebug() << "ScriptEngine::evaluate(program) -- after _evaluatesPending++ script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";
462+ qDebug() << "ScriptEngine::evaluate(program) -- BEFORE QScriptEngine::evaluate() script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";
397463 QScriptValue result = QScriptEngine::evaluate(program, fileName, lineNumber);
464+ qDebug() << "ScriptEngine::evaluate(program) -- AFTER QScriptEngine::evaluate() script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";
398465 if (hasUncaughtException()) {
399466 int line = uncaughtExceptionLineNumber();
400467 qDebug() << "Uncaught exception at (" << _fileNameString << " : " << fileName << ") line" << line << ": " << result.toString();
401468 }
469+ _evaluatesPending--;
470+ qDebug() << "ScriptEngine::evaluate(program) -- after _evaluatesPending-- script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";
471+
472+ qDebug() << "ScriptEngine::evaluate(program) -- ABOUT TO emit evaluationFinished() script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";
402473 emit evaluationFinished(result, hasUncaughtException());
474+ qDebug() << "ScriptEngine::evaluate(program) -- AFTER emit evaluationFinished() script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";
403475 clearExceptions();
404− _evaluatePending = false;
405− qDebug() << "ScriptEngine::evaluate() " << getFilename() << " line:" << __LINE__;
476+ qDebug() << "ScriptEngine::evaluate(program) -- DONE script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";
406477 return result;
407478 }
408479
@@ -419,49 +490,60 @@ void ScriptEngine::sendAvatarBillboardPacket() { · 10 unmodified lines
419490 }
420491
421492 void ScriptEngine::run() {
422− qDebug() << "ScriptEngine::run() " << getFilename() << " -------- BEGIN -----------";
493+ // TODO: can we add a short circuit for _stoppingAllScripts here? What does it mean to not start running if
494+ // we're in the process of stopping?
423495
496+ qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
424497 if (!_isInitialized) {
425− qDebug() << "ScriptEngine::run() " << getFilename() << " line:" << __LINE__;
426498 init();
427− qDebug() << "ScriptEngine::run() " << getFilename() << " line:" << __LINE__;
428499 }
429− qDebug() << "ScriptEngine::run() " << getFilename() << " line:" << __LINE__;
500+ qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
430501 _isRunning = true;
431502 _isFinished = false;
432− qDebug() << "ScriptEngine::run() " << getFilename() << " line:" << __LINE__;
433503 emit runningStateChanged();
434− qDebug() << "ScriptEngine::run() " << getFilename() << " line:" << __LINE__;
435504
436− qDebug() << "ScriptEngine::run() " << getFilename() << " line:" << __LINE__;
505+ qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
437506 QScriptValue result = evaluate(_scriptContents);
438− qDebug() << "ScriptEngine::run() " << getFilename() << " line:" << __LINE__;
507+ qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
439508
440− qDebug() << "ScriptEngine::run() " << getFilename() << " line:" << __LINE__;
441509 QElapsedTimer startTime;
442510 startTime.start();
443511
444512 int thisFrame = 0;
445513
446− qDebug() << "ScriptEngine::run() " << getFilename() << " line:" << __LINE__;
447514 auto nodeList = DependencyManager::get<NodeList>();
448515
449516 qint64 lastUpdate = usecTimestampNow();
450517
451− qDebug() << "ScriptEngine::run() " << getFilename() << " line:" << __LINE__;
518+ qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
519+
452520 while (!_isFinished) {
521+ if (_isWaitingForDoneRunning) {
522+ qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
523+ }
524+
453525 int usecToSleep = (thisFrame++ * SCRIPT_DATA_CALLBACK_USECS) - startTime.nsecsElapsed() / 1000; // nsec to usec
454526 if (usecToSleep > 0) {
455527 usleep(usecToSleep);
456528 }
457529
458530 if (_isFinished) {
531+ qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
459532 break;
460533 }
461534
535+ if (_isWaitingForDoneRunning) {
536+ qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
537+ }
538+
462539 QCoreApplication::processEvents();
463540
541+ if (_isWaitingForDoneRunning) {
542+ qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
543+ }
544+
464545 if (_isFinished) {
546+ qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
465547 break;
466548 }
467549
@@ -589,16 +671,38 @@ void ScriptEngine::run() { · 121 unmodified lines
589671 emit update(deltaTime);
590672 }
591673 lastUpdate = now;
674+
675+ if (_isWaitingForDoneRunning) {
676+ qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
677+ }
678+
679+ }
680+
681+ if (_isWaitingForDoneRunning) {
682+ qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
592683 }
593− qDebug() << "ScriptEngine::run() " << getFilename() << " line:" << __LINE__;
684+
685+ qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
594686
595687 stopAllTimers(); // make sure all our timers are stopped if the script is ending
688+ qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename();
689+
690+ if (_isWaitingForDoneRunning) {
691+ qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
692+ }
596693
597694 emit scriptEnding();
695+ qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
598696
599697 // kill the avatar identity timer
600698 delete _avatarIdentityTimer;
601699
700+ qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
701+
702+ if (_isWaitingForDoneRunning) {
703+ qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
704+ }
705+
602706 if (_entityScriptingInterface.getEntityPacketSender()->serversExist()) {
603707 // release the queue of edit entity messages.
604708 _entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages();
@@ -609,19 +713,44 @@ void ScriptEngine::run() { · 4 unmodified lines
609713 }
610714 }
611715
716+ qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
717+
612718 // If we were on a thread, then wait till it's done
613719 if (thread()) {
720+ qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
614721 thread()->quit();
722+ qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
723+ }
724+
725+ qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
726+
727+ if (_isWaitingForDoneRunning) {
728+ qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
615729 }
616730
617731 emit finished(_fileNameString);
618732
619− _isRunning = false;
733+ if (_isWaitingForDoneRunning) {
734+ qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
735+ }
620736
737+ _isRunning = false;
621738 emit runningStateChanged();
622739
740+ qDebug() << "ABOUT TO emit doneRunning() script:" << getFilename() << "[" << this << "]";
623741 emit doneRunning();
624− qDebug() << "ScriptEngine::run() " << getFilename() << " -------- DONE -----------" << " line:" << __LINE__;
742+ qDebug() << "AFTER emit doneRunning() script:" << getFilename() << "[" << this << "]";
743+
744+ if (_isWaitingForDoneRunning) {
745+ qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
746+ }
747+
748+ qDebug() << "ScriptEngine::run() SETTING _doneRunningThisScript = true ################################### line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
749+ _doneRunningThisScript = true;
750+
751+ if (_isWaitingForDoneRunning) {
752+ qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";
753+ }
625754 }
626755
627756 // NOTE: This is private because it must be called on the same thread that created the timers, which is why
@@ -636,9 +765,10 @@ void ScriptEngine::stopAllTimers() { · 8 unmodified lines
636765 }
637766
638767 void ScriptEngine::stop() {
639− qDebug() << "ScriptEngine::stop() " << getFilename() << "[" << ((void*)this) << "]";
768+ qDebug() << "ScriptEngine::stop() -- START -- line:" << __LINE__ << " script:" << getFilename();
640769 _isFinished = true;
641770 emit runningStateChanged();
771+ qDebug() << "ScriptEngine::stop() -- DONE -- line:" << __LINE__ << " script:" << getFilename();
642772 }
643773
644774 void ScriptEngine::timerFired() {
@@ -674,10 +804,22 @@ QObject* ScriptEngine::setupTimerWithInterval(const QScriptValue& function, int · 29 unmodified lines
674804 }
675805
676806 QObject* ScriptEngine::setInterval(const QScriptValue& function, int intervalMS) {
807+ if (_stoppingAllScripts) {
808+ qDebug() << "Script.setInterval() while shutting down is ignored...";
809+ qDebug() << " parent script:" << getFilename() << "[" << this << "]";
810+ return NULL; // bail early
811+ }
812+
677813 return setupTimerWithInterval(function, intervalMS, false);
678814 }
679815
680816 QObject* ScriptEngine::setTimeout(const QScriptValue& function, int timeoutMS) {
817+ if (_stoppingAllScripts) {
818+ qDebug() << "Script.setTimeout() while shutting down is ignored...";
819+ qDebug() << " parent script:" << getFilename() << "[" << this << "]";
820+ return NULL; // bail early
821+ }
822+
681823 return setupTimerWithInterval(function, timeoutMS, true);
682824 }
683825
@@ -723,6 +865,12 @@ void ScriptEngine::print(const QString& message) { · 39 unmodified lines
723865 // If no callback is specified, the included files will be loaded synchronously and will block execution until
724866 // all of the files have finished loading.
725867 void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callback) {
868+ if (_stoppingAllScripts) {
869+ qDebug() << "Script.include() while shutting down is ignored...";
870+ qDebug() << " includeFiles:" << includeFiles;
871+ qDebug() << " parent script:" << getFilename() << "[" << this << "]";
872+ return; // bail early
873+ }
726874 QList<QUrl> urls;
727875 for (QString file : includeFiles) {
728876 urls.append(resolvePath(file));
@@ -736,7 +884,9 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 7 unmodified lines
736884 if (contents.isNull()) {
737885 qDebug() << "Error loading file: " << url;
738886 } else {
887+ qDebug() << "ScriptEngine::include() BEFORE evaluate() line:" << __LINE__ << " parent script:" << getFilename() << "[" << this << "]" << " url:" << url << "_evaluatesPending:" << _evaluatesPending;
739888 QScriptValue result = evaluate(contents, url.toString());
889+ qDebug() << "ScriptEngine::include() AFTER evaluate() line:" << __LINE__ << " parent script:" << getFilename() << "[" << this << "]" << " url:" << url << "_evaluatesPending:" << _evaluatesPending;
740890 }
741891 }
742892
@@ -762,17 +912,31 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 19 unmodified lines
762912 }
763913
764914 void ScriptEngine::include(const QString& includeFile, QScriptValue callback) {
915+ if (_stoppingAllScripts) {
916+ qDebug() << "Script.include() while shutting down is ignored...";
917+ qDebug() << " includeFile:" << includeFile;
918+ qDebug() << " parent script:" << getFilename() << "[" << this << "]";
919+ return; // bail early
920+ }
921+
765922 QStringList urls;
766923 urls.append(includeFile);
767924 include(urls, callback);
768925 }
769926
927+// NOTE: The load() command is similar to the include() command except that it loads the script
928+// as a stand-alone script. To accomplish this, the ScriptEngine class just emits a signal which
929+// the Application or other context will connect to in order to know to actually load the script
770930 void ScriptEngine::load(const QString& loadFile) {
771− qDebug() << "ScriptEngine::load() " << getFilename() << "[" << ((void*)this) << "]" << "line:" << __LINE__;
931+ if (_stoppingAllScripts) {
932+ qDebug() << "Script.load() while shutting down is ignored...";
933+ qDebug() << " loadFile:" << loadFile;
934+ qDebug() << " parent script:" << getFilename() << "[" << this << "]";
935+ return; // bail early
936+ }
937+
772938 QUrl url = resolvePath(loadFile);
773− qDebug() << "ScriptEngine::load() " << getFilename() << "[" << ((void*)this) << "]" << "line:" << __LINE__;
774939 emit loadScript(url.toString(), false);
775− qDebug() << "ScriptEngine::load() " << getFilename() << "[" << ((void*)this) << "]" << "line:" << __LINE__;
776940 }
777941
778942 void ScriptEngine::nodeKilled(SharedNodePointer node) {