mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 06:23:35 +02:00
properly connect signals and slots to shut down script properly, fix null termination in script file load
This commit is contained in:
parent
dacaade9ed
commit
a220804fb0
3 changed files with 16 additions and 9 deletions
|
@ -4416,10 +4416,11 @@ void Application::loadScript() {
|
||||||
file.seekg( 0, std::ios::beg );
|
file.seekg( 0, std::ios::beg );
|
||||||
|
|
||||||
// read the entire file into a buffer, WHAT!? Why not.
|
// read the entire file into a buffer, WHAT!? Why not.
|
||||||
char* entireFile = new char[fileLength];
|
char* entireFile = new char[fileLength+1];
|
||||||
file.read((char*)entireFile, fileLength);
|
file.read((char*)entireFile, fileLength);
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
entireFile[fileLength] = 0;// null terminate
|
||||||
QString script(entireFile);
|
QString script(entireFile);
|
||||||
delete[] entireFile;
|
delete[] entireFile;
|
||||||
|
|
||||||
|
@ -4435,13 +4436,19 @@ void Application::loadScript() {
|
||||||
//_scriptEngine->getParticleScriptingInterface()->setJurisdictionListener();
|
//_scriptEngine->getParticleScriptingInterface()->setJurisdictionListener();
|
||||||
|
|
||||||
QThread* workerThread = new QThread(this);
|
QThread* workerThread = new QThread(this);
|
||||||
|
|
||||||
|
// when the worker thread is started, call our engine's run..
|
||||||
connect(workerThread, SIGNAL(started()), _scriptEngine, SLOT(run()));
|
connect(workerThread, SIGNAL(started()), _scriptEngine, SLOT(run()));
|
||||||
|
|
||||||
//connect(_scriptEngine, SIGNAL(finished()), this, SLOT(assignmentCompleted()));
|
// when the engine emits finished, call our threads quit
|
||||||
//connect(_scriptEngine, SIGNAL(finished()), workerThread, SLOT(quit()));
|
connect(_scriptEngine, SIGNAL(finished()), workerThread, SLOT(quit()));
|
||||||
//connect(_scriptEngine, SIGNAL(finished()), _scriptEngine, SLOT(deleteLater()));
|
|
||||||
//connect(_scriptEngine, SIGNAL(finished()), workerThread, SLOT(deleteLater()));
|
// when the thread is terminated, add both _scriptEngine and thread to the deleteLater queue
|
||||||
|
connect(workerThread, SIGNAL(terminated()), _scriptEngine, SLOT(deleteLater()));
|
||||||
|
connect(workerThread, SIGNAL(terminated()), workerThread, SLOT(deleteLater()));
|
||||||
|
|
||||||
|
// when the application is about to quit, stop our script engine so it unwinds properly
|
||||||
|
connect(this, SIGNAL(aboutToQuit()), _scriptEngine, SLOT(stop()));
|
||||||
|
|
||||||
_scriptEngine->moveToThread(workerThread);
|
_scriptEngine->moveToThread(workerThread);
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,8 @@ void ScriptEngine::run() {
|
||||||
// let the VoxelPacketSender know how frequently we plan to call it
|
// let the VoxelPacketSender know how frequently we plan to call it
|
||||||
_voxelScriptingInterface.getVoxelPacketSender()->setProcessCallIntervalHint(VISUAL_DATA_CALLBACK_USECS);
|
_voxelScriptingInterface.getVoxelPacketSender()->setProcessCallIntervalHint(VISUAL_DATA_CALLBACK_USECS);
|
||||||
_particleScriptingInterface.getParticlePacketSender()->setProcessCallIntervalHint(VISUAL_DATA_CALLBACK_USECS);
|
_particleScriptingInterface.getParticlePacketSender()->setProcessCallIntervalHint(VISUAL_DATA_CALLBACK_USECS);
|
||||||
|
|
||||||
|
qDebug() << "Script:\n" << _scriptContents << "\n";
|
||||||
|
|
||||||
QScriptValue result = engine.evaluate(_scriptContents);
|
QScriptValue result = engine.evaluate(_scriptContents);
|
||||||
qDebug() << "Evaluated script.\n";
|
qDebug() << "Evaluated script.\n";
|
||||||
|
@ -112,7 +114,6 @@ void ScriptEngine::run() {
|
||||||
int line = engine.uncaughtExceptionLineNumber();
|
int line = engine.uncaughtExceptionLineNumber();
|
||||||
qDebug() << "Uncaught exception at line" << line << ":" << engine.uncaughtException().toString() << "\n";
|
qDebug() << "Uncaught exception at line" << line << ":" << engine.uncaughtException().toString() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
emit finished();
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ public slots:
|
||||||
void run();
|
void run();
|
||||||
void stop() {
|
void stop() {
|
||||||
_isFinished = true;
|
_isFinished = true;
|
||||||
emit finished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
Loading…
Reference in a new issue