Fixed script editor crash when script calls Script.stop(). Also made the

processEraseMessage wait until it can lock to ensure particles are
deleted.
This commit is contained in:
barnold1953 2014-05-22 12:45:36 -07:00
parent 4036f929c9
commit 5013c8c2fa
4 changed files with 22 additions and 10 deletions

View file

@ -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<ParticleTree*>(_tree)->processEraseMessage(dataByteArray, sourceNode);
}
}

View file

@ -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);
}
}

View file

@ -46,6 +46,7 @@ private slots:
void onScriptError(const QString& message);
void onScriptPrint(const QString& message);
void onScriptModified();
void onScriptEnding();
private:
Ui::ScriptEditorWidget* _scriptEditorWidgetUI;

View file

@ -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) {
//<write 1 bit>
byte = (byte << 1) | true;
xTest += sTest/2.0;
xTest += sTest/2.0f;
} else {
//<write 0 bit;>
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) {
//<write 1 bit>
byte = (byte << 1) | true;
yTest += sTest/2.0;
yTest += sTest/2.0f;
} else {
//<write 0 bit;>
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) {
//<write 1 bit>
byte = (byte << 1) | true;
zTest += sTest/2.0;
zTest += sTest/2.0f;
} else {
//<write 0 bit;>
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