Job #19766 BUG: Stop or reload all scripts crashes interface fix, part 2.

Keep the scriptUrl internal to the ScriptEngine class and refer to it
externally by the file name string.

Change the ScriptEngine constructor to accept a filename QString,
instead of a QUrl. Resolve constructor ambiguity in Particle, which
creates anonymous ScriptEngine.
This commit is contained in:
matsukaze 2014-06-09 23:15:45 -04:00
parent c8c8bccbf3
commit b4e9840865
4 changed files with 11 additions and 14 deletions

View file

@ -3492,9 +3492,8 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript
scriptEngine = new ScriptEngine(NO_SCRIPT, "", &_controllerScriptingInterface); scriptEngine = new ScriptEngine(NO_SCRIPT, "", &_controllerScriptingInterface);
} else { } else {
// start the script on a new thread... // start the script on a new thread...
QUrl scriptUrl(scriptName); scriptEngine = new ScriptEngine(scriptName, &_controllerScriptingInterface);
scriptEngine = new ScriptEngine(scriptUrl, &_controllerScriptingInterface); _scriptEnginesHash.insert(scriptName, scriptEngine);
_scriptEnginesHash.insert(scriptUrl.toString(), scriptEngine);
if (!scriptEngine->hasScript()) { if (!scriptEngine->hasScript()) {
qDebug() << "Application::loadScript(), script failed to load..."; qDebug() << "Application::loadScript(), script failed to load...";

View file

@ -873,7 +873,7 @@ void Particle::endParticleScriptContext(ScriptEngine& engine, ParticleScriptObje
void Particle::executeUpdateScripts() { void Particle::executeUpdateScripts() {
// Only run this particle script if there's a script attached directly to the particle. // Only run this particle script if there's a script attached directly to the particle.
if (!_script.isEmpty()) { if (!_script.isEmpty()) {
ScriptEngine engine(_script); ScriptEngine engine(_script, QString(""));
ParticleScriptObject particleScriptable(this); ParticleScriptObject particleScriptable(this);
startParticleScriptContext(engine, particleScriptable); startParticleScriptContext(engine, particleScriptable);
particleScriptable.emitUpdate(); particleScriptable.emitUpdate();
@ -884,7 +884,7 @@ void Particle::executeUpdateScripts() {
void Particle::collisionWithParticle(Particle* other, const glm::vec3& penetration) { void Particle::collisionWithParticle(Particle* other, const glm::vec3& penetration) {
// Only run this particle script if there's a script attached directly to the particle. // Only run this particle script if there's a script attached directly to the particle.
if (!_script.isEmpty()) { if (!_script.isEmpty()) {
ScriptEngine engine(_script); ScriptEngine engine(_script, QString(""));
ParticleScriptObject particleScriptable(this); ParticleScriptObject particleScriptable(this);
startParticleScriptContext(engine, particleScriptable); startParticleScriptContext(engine, particleScriptable);
ParticleScriptObject otherParticleScriptable(other); ParticleScriptObject otherParticleScriptable(other);
@ -896,7 +896,7 @@ void Particle::collisionWithParticle(Particle* other, const glm::vec3& penetrati
void Particle::collisionWithVoxel(VoxelDetail* voxelDetails, const glm::vec3& penetration) { void Particle::collisionWithVoxel(VoxelDetail* voxelDetails, const glm::vec3& penetration) {
// Only run this particle script if there's a script attached directly to the particle. // Only run this particle script if there's a script attached directly to the particle.
if (!_script.isEmpty()) { if (!_script.isEmpty()) {
ScriptEngine engine(_script); ScriptEngine engine(_script, QString(""));
ParticleScriptObject particleScriptable(this); ParticleScriptObject particleScriptable(this);
startParticleScriptContext(engine, particleScriptable); startParticleScriptContext(engine, particleScriptable);
particleScriptable.emitCollisionWithVoxel(*voxelDetails, penetration); particleScriptable.emitCollisionWithVoxel(*voxelDetails, penetration);

View file

@ -93,7 +93,7 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam
{ {
} }
ScriptEngine::ScriptEngine(const QUrl& scriptURL, ScriptEngine::ScriptEngine(const QString& fileNameString,
AbstractControllerScriptingInterface* controllerScriptingInterface) : AbstractControllerScriptingInterface* controllerScriptingInterface) :
_scriptContents(), _scriptContents(),
_isFinished(false), _isFinished(false),
@ -110,21 +110,19 @@ ScriptEngine::ScriptEngine(const QUrl& scriptURL,
_controllerScriptingInterface(controllerScriptingInterface), _controllerScriptingInterface(controllerScriptingInterface),
_avatarData(NULL), _avatarData(NULL),
_scriptName(), _scriptName(),
_fileNameString(), _fileNameString(fileNameString),
_quatLibrary(), _quatLibrary(),
_vec3Library(), _vec3Library(),
_uuidLibrary(), _uuidLibrary(),
_animationCache(this) _animationCache(this)
{ {
QString scriptURLString = scriptURL.toString(); QUrl url(fileNameString);
_fileNameString = scriptURLString; QString scriptUrlString = url.toString();
QUrl url(scriptURL);
// if the scheme length is one or lower, maybe they typed in a file, let's try // if the scheme length is one or lower, maybe they typed in a file, let's try
const int WINDOWS_DRIVE_LETTER_SIZE = 1; const int WINDOWS_DRIVE_LETTER_SIZE = 1;
if (url.scheme().size() <= WINDOWS_DRIVE_LETTER_SIZE) { if (url.scheme().size() <= WINDOWS_DRIVE_LETTER_SIZE) {
url = QUrl::fromLocalFile(scriptURLString); url = QUrl::fromLocalFile(scriptUrlString);
} }
// ok, let's see if it's valid... and if so, load it // ok, let's see if it's valid... and if so, load it

View file

@ -40,7 +40,7 @@ const unsigned int SCRIPT_DATA_CALLBACK_USECS = floor(((1.0 / 60.0f) * 1000 * 10
class ScriptEngine : public QObject { class ScriptEngine : public QObject {
Q_OBJECT Q_OBJECT
public: public:
ScriptEngine(const QUrl& scriptURL, ScriptEngine(const QString& fileNameString,
AbstractControllerScriptingInterface* controllerScriptingInterface = NULL); AbstractControllerScriptingInterface* controllerScriptingInterface = NULL);
ScriptEngine(const QString& scriptContents = NO_SCRIPT, ScriptEngine(const QString& scriptContents = NO_SCRIPT,