Changes to src/virtual-machine based on minor bugs found during testing. This was supposed to be included with the previous commit.

This commit is contained in:
Karishma Chadha 2017-11-08 15:49:51 -05:00
parent bf6b78137a
commit 70081132cb

View file

@ -495,7 +495,11 @@ class VirtualMachine extends EventEmitter {
// Ensure editing target is switched if we are deleting it.
if (clone === currentEditingTarget) {
const nextTargetIndex = Math.min(this.runtime.targets.length - 1, targetIndexBeforeDelete);
this.setEditingTarget(this.runtime.targets[nextTargetIndex].id);
if (this.runtime.targets.length > 0){
this.setEditingTarget(this.runtime.targets[nextTargetIndex].id);
} else {
this.editingTarget = null;
}
}
}
// Sprite object should be deleted by GC.
@ -518,7 +522,7 @@ class VirtualMachine extends EventEmitter {
} else if (!target.sprite) {
throw new Error('No sprite associated with this target.');
}
target.duplicate().then(newTarget => {
return target.duplicate().then(newTarget => {
this.runtime.targets.push(newTarget);
this.setEditingTarget(newTarget.id);
});