From 2c4361b8300ff271a8adb97ecf3667c712d519a1 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Tue, 16 May 2017 09:20:52 -0400 Subject: [PATCH 1/2] Fix refreshTargets race condition --- src/engine/runtime.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 2708ebe7e..c4ea2b358 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -645,7 +645,6 @@ class Runtime extends EventEmitter { * inactive threads after each iteration. */ _step () { - this._refreshTargets = false; // Find all edge-activated hats, and add them to threads to be evaluated. for (const hatType in this._hats) { if (!this._hats.hasOwnProperty(hatType)) continue; @@ -663,7 +662,10 @@ class Runtime extends EventEmitter { // @todo: Only render when this.redrawRequested or clones rendered. this.renderer.draw(); } - if (this._refreshTargets) this.emit(Runtime.TARGETS_UPDATE); + if (this._refreshTargets) { + this.emit(Runtime.TARGETS_UPDATE); + this._refreshTargets = false; + } } /** From beaef901a72d075ded2e262bfb676db3ba058c6c Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Thu, 18 May 2017 09:12:12 -0400 Subject: [PATCH 2/2] Add failing test for gui issues 370 Fix rename increment when renamed to itself --- src/virtual-machine.js | 3 +-- test/unit/virtual-machine.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 79c16d2fc..adbeba640 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -329,9 +329,8 @@ class VirtualMachine extends EventEmitter { } if (newName && RESERVED_NAMES.indexOf(newName) === -1) { const names = this.runtime.targets - .filter(runtimeTarget => runtimeTarget.isSprite()) + .filter(runtimeTarget => runtimeTarget.isSprite() && runtimeTarget.id !== target.id) .map(runtimeTarget => runtimeTarget.sprite.name); - sprite.name = StringUtil.unusedName(newName, names); } this.emitTargetsUpdate(); diff --git a/test/unit/virtual-machine.js b/test/unit/virtual-machine.js index 73cefb8a2..37a62ff69 100644 --- a/test/unit/virtual-machine.js +++ b/test/unit/virtual-machine.js @@ -94,3 +94,18 @@ test('renameSprite increments from existing sprite names', t => { t.equal(vm.runtime.targets[0].sprite.name, 'that name2'); t.end(); }); + +test('renameSprite does not increment when renaming to the same name', t => { + const vm = new VirtualMachine(); + vm.emitTargetsUpdate = () => {}; + vm.runtime.targets = [{ + id: 'id1', + isSprite: () => true, + sprite: { + name: 'this name' + } + }]; + vm.renameSprite('id1', 'this name'); + t.equal(vm.runtime.targets[0].sprite.name, 'this name'); + t.end(); +});