History

removed extra debugging

ZappoMan committed 11 years ago

Commit 25ae0011 parent 9dcea381 file · +1 −118Browse files

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

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+1−118
@@ -42,12 +42,6 @@ · 41 unmodified lines
4242 #include "MIDIEvent.h"
4343
4444
45−#ifdef WANT_DEBUG_SCRIPT_ENDING
46−#define DEBUG_SCRIPT_ENDING(X) X
47−#else
48−#define DEBUG_SCRIPT_ENDING(x)
49−#endif
50−
5145 EntityScriptingInterface ScriptEngine::_entityScriptingInterface;
5246
5347 static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){
@@ -107,7 +101,6 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam · 53 unmodified lines
107101 }
108102
109103 ScriptEngine::~ScriptEngine() {
110− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::~ScriptEngine() ------- BEGIN ------- script:" << getFilename();)
111104 // If we're not already in the middle of stopping all scripts, then we should remove ourselves
112105 // from the list of running scripts. We don't do this if we're in the process of stopping all scripts
113106 // because that method removes scripts from its list as it iterates them
@@ -116,7 +109,6 @@ ScriptEngine::~ScriptEngine() { · 2 unmodified lines
116109 _allKnownScriptEngines.remove(this);
117110 _allScriptsMutex.unlock();
118111 }
119− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::~ScriptEngine() ------- END ------- script:" << getFilename();)
120112 }
121113
122114 QSet<ScriptEngine*> ScriptEngine::_allKnownScriptEngines;
@@ -136,8 +128,6 @@ void ScriptEngine::stopAllScripts(QObject* application) { · 13 unmodified lines
136128
137129 QString scriptName = scriptEngine->getFilename();
138130
139− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::stopAllScripts() considering:" << scriptName << "isRunning():" << scriptEngine->isRunning() << "evaluatePending():" << scriptEngine->evaluatePending();)
140−
141131 // NOTE: typically all script engines are running. But there's at least one known exception to this, the
142132 // "entities sandbox" which is only used to evaluate entities scripts to test their validity before using
143133 // them. We don't need to stop scripts that aren't running.
@@ -149,18 +139,14 @@ void ScriptEngine::stopAllScripts(QObject* application) { · 5 unmodified lines
149139 while (scriptEngine->evaluatePending()) {
150140 QEventLoop loop;
151141 QObject::connect(scriptEngine, &ScriptEngine::evaluationFinished, &loop, &QEventLoop::quit);
152− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::stopAllScripts() while(evaluatePending()) STARTING loop.exec() script:" << scriptName;)
153142 loop.exec();
154− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::stopAllScripts() while(evaluatePending()) AFTER loop.exec() script:" << scriptName;)
155143 }
156144 }
157145
158146 scriptEngine->disconnect(application);
159147 scriptEngine->stop();
160148
161− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::stopAllScripts() -- WAITING for waitTillDoneRunning() script:" << scriptName;)
162149 scriptEngine->waitTillDoneRunning();
163− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::stopAllScripts() -- AFTER waitTillDoneRunning() script:" << scriptName;)
164150 i.remove();
165151 } else {
166152 qDebug() << "ScriptEngine::stopAllScripts() " << scriptName << " - will be freed on it's own.";
@@ -175,10 +161,8 @@ void ScriptEngine::stopAllScripts(QObject* application) { · 8 unmodified lines
175161
176162 void ScriptEngine::waitTillDoneRunning() {
177163 QString scriptName = getFilename();
178− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() ------- BEGIN ------- script:" << scriptName;)
179164
180165 if (_isRunning) {
181− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() SETTING _doneRunningThisScript = false ################################### line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
182166 _doneRunningThisScript = false;
183167 _isWaitingForDoneRunning = true;
184168
@@ -191,31 +175,18 @@ void ScriptEngine::waitTillDoneRunning() { · 6 unmodified lines
191175 // and run a QEventLoop???
192176 QEventLoop loop;
193177 QObject::connect(this, &ScriptEngine::doneRunning, &loop, &QEventLoop::quit);
194− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() STARTING loop.exec() script:" << scriptName;)
195− DEBUG_SCRIPT_ENDING(qDebug() << " _doneRunningThisScript:" << _doneRunningThisScript;)
196− DEBUG_SCRIPT_ENDING(qDebug() << " _isRunning:" << _isRunning;)
197− DEBUG_SCRIPT_ENDING(qDebug() << " _isWaitingForDoneRunning:" << _isWaitingForDoneRunning;)
198− DEBUG_SCRIPT_ENDING(qDebug() << " _isFinished:" << _isFinished;)
199− DEBUG_SCRIPT_ENDING(qDebug() << " _isInitialized:" << _isInitialized;)
200− DEBUG_SCRIPT_ENDING(qDebug() << " _evaluatesPending:" << _evaluatesPending;)
201178 loop.exec();
202− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() AFTER loop.exec() script:" << scriptName;)
203179
204180 // process events
205− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() STARTING QCoreApplication::processEvents() script:" << scriptName;)
206181 QCoreApplication::processEvents();
207− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() AFTER QCoreApplication::processEvents() script:" << scriptName;)
208182
209183 if (_doneRunningThisScript) {
210− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() _doneRunningThisScript after processEvents... breaking!!! script:" << scriptName;)
211184 break;
212185 }
213186 }
214187
215188 _isWaitingForDoneRunning = false;
216189 }
217−
218− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() ------- DONE ------- script:" << scriptName;)
219190 }
220191
221192 QString ScriptEngine::getFilename() const {
@@ -428,25 +399,20 @@ void ScriptEngine::registerGetterSetter(const QString& name, QScriptEngine::Func · 206 unmodified lines
428399
429400 void ScriptEngine::evaluate() {
430401 if (_stoppingAllScripts) {
431− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate() while shutting down is ignored...";)
432− DEBUG_SCRIPT_ENDING(qDebug() << " parent script:" << getFilename() << "[" << this << "]";)
433402 return; // bail early
434403 }
435404
436− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate() -- BEGIN script:" << getFilename() << "[" << this << "]";)
437405 if (!_isInitialized) {
438406 init();
439407 }
440408
441− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate() -- about to call own evaluate(program) script:" << getFilename() << "[" << this << "]";)
442409 QScriptValue result = evaluate(_scriptContents);
443− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate() -- AFTER own evaluate(program) script:" << getFilename() << "[" << this << "]";)
444410
445411 // TODO: why do we check this twice? It seems like the call to clearExcpetions() in the lower level evaluate call
446412 // will cause this code to never actually run...
447413 if (hasUncaughtException()) {
448414 int line = uncaughtExceptionLineNumber();
449− DEBUG_SCRIPT_ENDING(qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString();)
415+ qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString();
450416 emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString());
451417 clearExceptions();
452418 }
@@ -454,29 +420,18 @@ void ScriptEngine::evaluate() { · 1 unmodified line
454420
455421 QScriptValue ScriptEngine::evaluate(const QString& program, const QString& fileName, int lineNumber) {
456422 if (_stoppingAllScripts) {
457− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) while shutting down is ignored...";)
458− DEBUG_SCRIPT_ENDING(qDebug() << " parent script:" << getFilename() << "[" << this << "]";)
459423 return QScriptValue(); // bail early
460424 }
461425
462− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- BEGIN script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";)
463426 _evaluatesPending++;
464− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- after _evaluatesPending++ script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";)
465− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- BEFORE QScriptEngine::evaluate() script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";)
466427 QScriptValue result = QScriptEngine::evaluate(program, fileName, lineNumber);
467− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- AFTER QScriptEngine::evaluate() script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";)
468428 if (hasUncaughtException()) {
469429 int line = uncaughtExceptionLineNumber();
470430 qDebug() << "Uncaught exception at (" << _fileNameString << " : " << fileName << ") line" << line << ": " << result.toString();
471431 }
472432 _evaluatesPending--;
473− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- after _evaluatesPending-- script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";)
474−
475− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- ABOUT TO emit evaluationFinished() script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";)
476433 emit evaluationFinished(result, hasUncaughtException());
477− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- AFTER emit evaluationFinished() script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";)
478434 clearExceptions();
479− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- DONE script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";)
480435 return result;
481436 }
482437
@@ -496,18 +451,14 @@ void ScriptEngine::run() { · 13 unmodified lines
496451 // TODO: can we add a short circuit for _stoppingAllScripts here? What does it mean to not start running if
497452 // we're in the process of stopping?
498453
499− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
500454 if (!_isInitialized) {
501455 init();
502456 }
503− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
504457 _isRunning = true;
505458 _isFinished = false;
506459 emit runningStateChanged();
507460
508− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
509461 QScriptValue result = evaluate(_scriptContents);
510− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
511462
512463 QElapsedTimer startTime;
513464 startTime.start();
@@ -518,35 +469,19 @@ void ScriptEngine::run() { · 4 unmodified lines
518469
519470 qint64 lastUpdate = usecTimestampNow();
520471
521− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
522−
523472 while (!_isFinished) {
524− if (_isWaitingForDoneRunning) {
525− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
526− }
527−
528473 int usecToSleep = (thisFrame++ * SCRIPT_DATA_CALLBACK_USECS) - startTime.nsecsElapsed() / 1000; // nsec to usec
529474 if (usecToSleep > 0) {
530475 usleep(usecToSleep);
531476 }
532477
533478 if (_isFinished) {
534− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
535479 break;
536480 }
537481
538− if (_isWaitingForDoneRunning) {
539− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
540− }
541−
542482 QCoreApplication::processEvents();
543483
544− if (_isWaitingForDoneRunning) {
545− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
546− }
547−
548484 if (_isFinished) {
549− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
550485 break;
551486 }
552487
@@ -675,37 +610,14 @@ void ScriptEngine::run() { · 122 unmodified lines
675610 }
676611 lastUpdate = now;
677612
678− if (_isWaitingForDoneRunning) {
679− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
680− }
681−
682− }
683−
684− if (_isWaitingForDoneRunning) {
685− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
686613 }
687614
688− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
689−
690615 stopAllTimers(); // make sure all our timers are stopped if the script is ending
691− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename();)
692−
693− if (_isWaitingForDoneRunning) {
694− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
695− }
696−
697616 emit scriptEnding();
698− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
699617
700618 // kill the avatar identity timer
701619 delete _avatarIdentityTimer;
702620
703− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
704−
705− if (_isWaitingForDoneRunning) {
706− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
707− }
708−
709621 if (_entityScriptingInterface.getEntityPacketSender()->serversExist()) {
710622 // release the queue of edit entity messages.
711623 _entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages();
@@ -716,44 +628,19 @@ void ScriptEngine::run() { · 4 unmodified lines
716628 }
717629 }
718630
719− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
720−
721631 // If we were on a thread, then wait till it's done
722632 if (thread()) {
723− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
724633 thread()->quit();
725− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
726− }
727−
728− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
729−
730− if (_isWaitingForDoneRunning) {
731− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
732634 }
733635
734636 emit finished(_fileNameString);
735637
736− if (_isWaitingForDoneRunning) {
737− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
738− }
739−
740638 _isRunning = false;
741639 emit runningStateChanged();
742640
743− DEBUG_SCRIPT_ENDING(qDebug() << "ABOUT TO emit doneRunning() script:" << getFilename() << "[" << this << "]";)
744641 emit doneRunning();
745− DEBUG_SCRIPT_ENDING(qDebug() << "AFTER emit doneRunning() script:" << getFilename() << "[" << this << "]";)
746642
747− if (_isWaitingForDoneRunning) {
748− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
749− }
750−
751− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() SETTING _doneRunningThisScript = true ################################### line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
752643 _doneRunningThisScript = true;
753−
754− if (_isWaitingForDoneRunning) {
755− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";)
756− }
757644 }
758645
759646 // NOTE: This is private because it must be called on the same thread that created the timers, which is why
@@ -768,10 +655,8 @@ void ScriptEngine::stopAllTimers() { · 8 unmodified lines
768655 }
769656
770657 void ScriptEngine::stop() {
771− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::stop() -- START -- line:" << __LINE__ << " script:" << getFilename();)
772658 _isFinished = true;
773659 emit runningStateChanged();
774− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::stop() -- DONE -- line:" << __LINE__ << " script:" << getFilename();)
775660 }
776661
777662 void ScriptEngine::timerFired() {
@@ -887,9 +772,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 109 unmodified lines
887772 if (contents.isNull()) {
888773 qDebug() << "Error loading file: " << url;
889774 } else {
890− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::include() BEFORE evaluate() line:" << __LINE__ << " parent script:" << getFilename() << "[" << this << "]" << " url:" << url << "_evaluatesPending:" << _evaluatesPending;)
891775 QScriptValue result = evaluate(contents, url.toString());
892− DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::include() AFTER evaluate() line:" << __LINE__ << " parent script:" << getFilename() << "[" << this << "]" << " url:" << url << "_evaluatesPending:" << _evaluatesPending;)
893776 }
894777 }
895778