Showing the changes to interface/src/Application.cpp (1 of 3 files). Show all
Unified · Split
| @@ -4416,10 +4416,11 @@ void Application::loadScript() { · 4415 unmodified lines | ||
| 4416 | 4416 | file.seekg( 0, std::ios::beg ); |
| 4417 | 4417 | |
| 4418 | 4418 | // read the entire file into a buffer, WHAT!? Why not. |
| 4419 | − char* entireFile = new char[fileLength]; | |
| 4419 | + char* entireFile = new char[fileLength+1]; | |
| 4420 | 4420 | file.read((char*)entireFile, fileLength); |
| 4421 | 4421 | file.close(); |
| 4422 | 4422 | |
| 4423 | + entireFile[fileLength] = 0;// null terminate | |
| 4423 | 4424 | QString script(entireFile); |
| 4424 | 4425 | delete[] entireFile; |
| 4425 | 4426 | |
| @@ -4435,13 +4436,19 @@ void Application::loadScript() { · 9 unmodified lines | ||
| 4435 | 4436 | //_scriptEngine->getParticleScriptingInterface()->setJurisdictionListener(); |
| 4436 | 4437 | |
| 4437 | 4438 | QThread* workerThread = new QThread(this); |
| 4438 | − | |
| 4439 | + | |
| 4440 | + // when the worker thread is started, call our engine's run.. | |
| 4439 | 4441 | connect(workerThread, SIGNAL(started()), _scriptEngine, SLOT(run())); |
| 4440 | 4442 | |
| 4441 | − //connect(_scriptEngine, SIGNAL(finished()), this, SLOT(assignmentCompleted())); | |
| 4442 | − //connect(_scriptEngine, SIGNAL(finished()), workerThread, SLOT(quit())); | |
| 4443 | − //connect(_scriptEngine, SIGNAL(finished()), _scriptEngine, SLOT(deleteLater())); | |
| 4444 | − //connect(_scriptEngine, SIGNAL(finished()), workerThread, SLOT(deleteLater())); | |
| 4443 | + // when the engine emits finished, call our threads quit | |
| 4444 | + connect(_scriptEngine, SIGNAL(finished()), workerThread, SLOT(quit())); | |
| 4445 | + | |
| 4446 | + // when the thread is terminated, add both _scriptEngine and thread to the deleteLater queue | |
| 4447 | + connect(workerThread, SIGNAL(terminated()), _scriptEngine, SLOT(deleteLater())); | |
| 4448 | + connect(workerThread, SIGNAL(terminated()), workerThread, SLOT(deleteLater())); | |
| 4449 | + | |
| 4450 | + // when the application is about to quit, stop our script engine so it unwinds properly | |
| 4451 | + connect(this, SIGNAL(aboutToQuit()), _scriptEngine, SLOT(stop())); | |
| 4445 | 4452 | |
| 4446 | 4453 | _scriptEngine->moveToThread(workerThread); |
| 4447 | 4454 | |