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
4416 file.seekg( 0, std::ios::beg );4416 file.seekg( 0, std::ios::beg );
4417 4417
4418 // read the entire file into a buffer, WHAT!? Why not.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 file.read((char*)entireFile, fileLength);4420 file.read((char*)entireFile, fileLength);
4421 file.close();4421 file.close();
4422 4422
4423 entireFile[fileLength] = 0;// null terminate
4423 QString script(entireFile);4424 QString script(entireFile);
4424 delete[] entireFile;4425 delete[] entireFile;
4425 4426
@@ -4435,13 +4436,19 @@ void Application::loadScript() { · 9 unmodified lines
4435 //_scriptEngine->getParticleScriptingInterface()->setJurisdictionListener();4436 //_scriptEngine->getParticleScriptingInterface()->setJurisdictionListener();
4436 4437
4437 QThread* workerThread = new QThread(this);4438 QThread* workerThread = new QThread(this);
4438 4439
4440 // when the worker thread is started, call our engine's run..
4439 connect(workerThread, SIGNAL(started()), _scriptEngine, SLOT(run()));4441 connect(workerThread, SIGNAL(started()), _scriptEngine, SLOT(run()));
4440 4442
4441 //connect(_scriptEngine, SIGNAL(finished()), this, SLOT(assignmentCompleted()));4443 // when the engine emits finished, call our threads quit
4442 //connect(_scriptEngine, SIGNAL(finished()), workerThread, SLOT(quit()));4444 connect(_scriptEngine, SIGNAL(finished()), workerThread, SLOT(quit()));
4443 //connect(_scriptEngine, SIGNAL(finished()), _scriptEngine, SLOT(deleteLater()));4445
4444 //connect(_scriptEngine, SIGNAL(finished()), workerThread, SLOT(deleteLater()));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 _scriptEngine->moveToThread(workerThread);4453 _scriptEngine->moveToThread(workerThread);
4447 4454

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