From 5013c8c2fab31353f6e49dc44c9a73d0da243d1a Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Thu, 22 May 2014 12:45:36 -0700 Subject: [PATCH] Fixed script editor crash when script calls Script.stop(). Also made the processEraseMessage wait until it can lock to ensure particles are deleted. --- .../src/particles/ParticleTreeRenderer.cpp | 3 ++- interface/src/ui/ScriptEditorWidget.cpp | 10 ++++++++++ interface/src/ui/ScriptEditorWidget.h | 1 + libraries/shared/src/SharedUtil.cpp | 18 +++++++++--------- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/interface/src/particles/ParticleTreeRenderer.cpp b/interface/src/particles/ParticleTreeRenderer.cpp index 781fc2bfc8..c89adab65d 100644 --- a/interface/src/particles/ParticleTreeRenderer.cpp +++ b/interface/src/particles/ParticleTreeRenderer.cpp @@ -127,7 +127,8 @@ void ParticleTreeRenderer::renderElement(OctreeElement* element, RenderArgs* arg } void ParticleTreeRenderer::processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) { - if (_tree->tryLockForWrite()) { + if (_tree){ + _tree->lockForWrite(); static_cast(_tree)->processEraseMessage(dataByteArray, sourceNode); } } diff --git a/interface/src/ui/ScriptEditorWidget.cpp b/interface/src/ui/ScriptEditorWidget.cpp index 07c6e72226..be5577e0e8 100644 --- a/interface/src/ui/ScriptEditorWidget.cpp +++ b/interface/src/ui/ScriptEditorWidget.cpp @@ -57,6 +57,11 @@ void ScriptEditorWidget::onScriptModified() { } } +void ScriptEditorWidget::onScriptEnding() { + // signals will automatically be disonnected when the _scriptEngine is deleted later + _scriptEngine = NULL; +} + bool ScriptEditorWidget::isModified() { return _scriptEditorWidgetUI->scriptEdit->document()->isModified(); } @@ -69,11 +74,13 @@ bool ScriptEditorWidget::setRunning(bool run) { if (run && !save()) { return false; } + // Clean-up old connections. if (_scriptEngine != NULL) { disconnect(_scriptEngine, &ScriptEngine::runningStateChanged, this, &ScriptEditorWidget::runningStateChanged); disconnect(_scriptEngine, &ScriptEngine::errorMessage, this, &ScriptEditorWidget::onScriptError); disconnect(_scriptEngine, &ScriptEngine::printedMessage, this, &ScriptEditorWidget::onScriptPrint); + disconnect(_scriptEngine, &ScriptEngine::scriptEnding, this, &ScriptEditorWidget::onScriptEnding); } if (run) { @@ -83,6 +90,7 @@ bool ScriptEditorWidget::setRunning(bool run) { // Make new connections. connect(_scriptEngine, &ScriptEngine::errorMessage, this, &ScriptEditorWidget::onScriptError); connect(_scriptEngine, &ScriptEngine::printedMessage, this, &ScriptEditorWidget::onScriptPrint); + connect(_scriptEngine, &ScriptEngine::scriptEnding, this, &ScriptEditorWidget::onScriptEnding); } else { Application::getInstance()->stopScript(_currentScript); _scriptEngine = NULL; @@ -125,6 +133,7 @@ void ScriptEditorWidget::loadFile(const QString& scriptPath) { disconnect(_scriptEngine, &ScriptEngine::runningStateChanged, this, &ScriptEditorWidget::runningStateChanged); disconnect(_scriptEngine, &ScriptEngine::errorMessage, this, &ScriptEditorWidget::onScriptError); disconnect(_scriptEngine, &ScriptEngine::printedMessage, this, &ScriptEditorWidget::onScriptPrint); + disconnect(_scriptEngine, &ScriptEngine::scriptEnding, this, &ScriptEditorWidget::onScriptEnding); } } else { QNetworkAccessManager* networkManager = new QNetworkAccessManager(this); @@ -144,6 +153,7 @@ void ScriptEditorWidget::loadFile(const QString& scriptPath) { connect(_scriptEngine, &ScriptEngine::runningStateChanged, this, &ScriptEditorWidget::runningStateChanged); connect(_scriptEngine, &ScriptEngine::errorMessage, this, &ScriptEditorWidget::onScriptError); connect(_scriptEngine, &ScriptEngine::printedMessage, this, &ScriptEditorWidget::onScriptPrint); + connect(_scriptEngine, &ScriptEngine::scriptEnding, this, &ScriptEditorWidget::onScriptEnding); } } diff --git a/interface/src/ui/ScriptEditorWidget.h b/interface/src/ui/ScriptEditorWidget.h index 1a96661cf7..3e95ea322b 100644 --- a/interface/src/ui/ScriptEditorWidget.h +++ b/interface/src/ui/ScriptEditorWidget.h @@ -46,6 +46,7 @@ private slots: void onScriptError(const QString& message); void onScriptPrint(const QString& message); void onScriptModified(); + void onScriptEnding(); private: Ui::ScriptEditorWidget* _scriptEditorWidgetUI; diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index 1136d49dd4..f29e8e3345 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -276,7 +276,7 @@ unsigned char* pointToOctalCode(float x, float y, float z, float s) { unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, unsigned char g, unsigned char b ) { // special case for size 1, the root node - if (s >= 1.0) { + if (s >= 1.0f) { unsigned char* voxelOut = new unsigned char; *voxelOut = 0; return voxelOut; @@ -289,7 +289,7 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, // voxel of size S. unsigned int voxelSizeInOctets = 1; while (sTest > s) { - sTest /= 2.0; + sTest /= 2.0f; voxelSizeInOctets++; } @@ -314,11 +314,11 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, if (x >= xTest) { // byte = (byte << 1) | true; - xTest += sTest/2.0; + xTest += sTest/2.0f; } else { // byte = (byte << 1) | false; - xTest -= sTest/2.0; + xTest -= sTest/2.0f; } bitInByteNDX++; // If we've reached the last bit of the byte, then we want to copy this byte @@ -333,11 +333,11 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, if (y >= yTest) { // byte = (byte << 1) | true; - yTest += sTest/2.0; + yTest += sTest/2.0f; } else { // byte = (byte << 1) | false; - yTest -= sTest/2.0; + yTest -= sTest/2.0f; } bitInByteNDX++; // If we've reached the last bit of the byte, then we want to copy this byte @@ -352,11 +352,11 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, if (z >= zTest) { // byte = (byte << 1) | true; - zTest += sTest/2.0; + zTest += sTest/2.0f; } else { // byte = (byte << 1) | false; - zTest -= sTest/2.0; + zTest -= sTest/2.0f; } bitInByteNDX++; // If we've reached the last bit of the byte, then we want to copy this byte @@ -369,7 +369,7 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, } octetsDone++; - sTest /= 2.0; + sTest /= 2.0f; } // If we've got here, and we didn't fill the last byte, we need to zero pad this