mirror of
https://github.com/lubosz/overte.git
synced 2025-08-18 20:14:18 +02:00
Merge pull request #3930 from ZappoMan/crashOnSwitch
fix to crash on rapidly switching domains
This commit is contained in:
commit
68c7985412
1 changed files with 13 additions and 6 deletions
|
@ -151,12 +151,19 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) {
|
||||||
return QScriptValue(); // no entity...
|
return QScriptValue(); // no entity...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: we keep local variables for the entityID and the script because
|
||||||
|
// below in loadScriptContents() it's possible for us to execute the
|
||||||
|
// application event loop, which may cause our entity to be deleted on
|
||||||
|
// us. We don't really need access the entity after this point, can
|
||||||
|
// can accomplish all we need to here with just the script "text" and the ID.
|
||||||
EntityItemID entityID = entity->getEntityItemID();
|
EntityItemID entityID = entity->getEntityItemID();
|
||||||
|
QString entityScript = entity->getScript();
|
||||||
|
|
||||||
if (_entityScripts.contains(entityID)) {
|
if (_entityScripts.contains(entityID)) {
|
||||||
EntityScriptDetails details = _entityScripts[entityID];
|
EntityScriptDetails details = _entityScripts[entityID];
|
||||||
|
|
||||||
// check to make sure our script text hasn't changed on us since we last loaded it
|
// check to make sure our script text hasn't changed on us since we last loaded it
|
||||||
if (details.scriptText == entity->getScript()) {
|
if (details.scriptText == entityScript) {
|
||||||
return details.scriptObject; // previously loaded
|
return details.scriptObject; // previously loaded
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,18 +171,18 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) {
|
||||||
// has changed and so we need to reload it.
|
// has changed and so we need to reload it.
|
||||||
_entityScripts.remove(entityID);
|
_entityScripts.remove(entityID);
|
||||||
}
|
}
|
||||||
if (entity->getScript().isEmpty()) {
|
if (entityScript.isEmpty()) {
|
||||||
return QScriptValue(); // no script
|
return QScriptValue(); // no script
|
||||||
}
|
}
|
||||||
|
|
||||||
QString scriptContents = loadScriptContents(entity->getScript());
|
QString scriptContents = loadScriptContents(entityScript);
|
||||||
|
|
||||||
QScriptSyntaxCheckResult syntaxCheck = QScriptEngine::checkSyntax(scriptContents);
|
QScriptSyntaxCheckResult syntaxCheck = QScriptEngine::checkSyntax(scriptContents);
|
||||||
if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {
|
if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {
|
||||||
qDebug() << "EntityTreeRenderer::loadEntityScript() entity:" << entityID;
|
qDebug() << "EntityTreeRenderer::loadEntityScript() entity:" << entityID;
|
||||||
qDebug() << " " << syntaxCheck.errorMessage() << ":"
|
qDebug() << " " << syntaxCheck.errorMessage() << ":"
|
||||||
<< syntaxCheck.errorLineNumber() << syntaxCheck.errorColumnNumber();
|
<< syntaxCheck.errorLineNumber() << syntaxCheck.errorColumnNumber();
|
||||||
qDebug() << " SCRIPT:" << entity->getScript();
|
qDebug() << " SCRIPT:" << entityScript;
|
||||||
return QScriptValue(); // invalid script
|
return QScriptValue(); // invalid script
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,12 +191,12 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) {
|
||||||
if (!entityScriptConstructor.isFunction()) {
|
if (!entityScriptConstructor.isFunction()) {
|
||||||
qDebug() << "EntityTreeRenderer::loadEntityScript() entity:" << entityID;
|
qDebug() << "EntityTreeRenderer::loadEntityScript() entity:" << entityID;
|
||||||
qDebug() << " NOT CONSTRUCTOR";
|
qDebug() << " NOT CONSTRUCTOR";
|
||||||
qDebug() << " SCRIPT:" << entity->getScript();
|
qDebug() << " SCRIPT:" << entityScript;
|
||||||
return QScriptValue(); // invalid script
|
return QScriptValue(); // invalid script
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue entityScriptObject = entityScriptConstructor.construct();
|
QScriptValue entityScriptObject = entityScriptConstructor.construct();
|
||||||
EntityScriptDetails newDetails = { entity->getScript(), entityScriptObject };
|
EntityScriptDetails newDetails = { entityScript, entityScriptObject };
|
||||||
_entityScripts[entityID] = newDetails;
|
_entityScripts[entityID] = newDetails;
|
||||||
|
|
||||||
return entityScriptObject; // newly constructed
|
return entityScriptObject; // newly constructed
|
||||||
|
|
Loading…
Reference in a new issue