History

properly connect signals and slots to shut down script properly, fix null termination in script file load

ZappoMan committed 12 years ago

Commit a2208041 parent dacaade3 files · +16 −9Browse files

Showing the changes to interface/src/Application.cpp (1 of 3 files). Show all

Unified · Split

interface/src/Application.cpp+13−6
@@ -4416,10 +4416,11 @@ void Application::loadScript() { · 4415 unmodified lines
44164416 file.seekg( 0, std::ios::beg );
44174417
44184418 // read the entire file into a buffer, WHAT!? Why not.
4419− char* entireFile = new char[fileLength];
4419+ char* entireFile = new char[fileLength+1];
44204420 file.read((char*)entireFile, fileLength);
44214421 file.close();
44224422
4423+ entireFile[fileLength] = 0;// null terminate
44234424 QString script(entireFile);
44244425 delete[] entireFile;
44254426
@@ -4435,13 +4436,19 @@ void Application::loadScript() { · 9 unmodified lines
44354436 //_scriptEngine->getParticleScriptingInterface()->setJurisdictionListener();
44364437
44374438 QThread* workerThread = new QThread(this);
4438−
4439+
4440+ // when the worker thread is started, call our engine's run..
44394441 connect(workerThread, SIGNAL(started()), _scriptEngine, SLOT(run()));
44404442
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()));
44454452
44464453 _scriptEngine->moveToThread(workerThread);
44474454

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t