Skip to content

Commit 7c9f079

Browse files
committed
Group.setProperty will now check if the property exists before setting it, this applies to Group.setAll and anything else using setProperty internally.
1 parent b77c034 commit 7c9f079

3 files changed

Lines changed: 6 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Version 2.0.4 - "Mos Shirare" - in development
6565
* AnimationManager.destroy now iterates through child animations calling destroy on all of them, avoiding a memory leak (thanks stauzs)
6666
* AnimationManager.play will now call Animation.stop on the current animation before switching to the new one (thanks @nihakue, #713)
6767
* ArcadePhysics.Body.phase is checked in postUpdate to prevent it from being called multiple times in a single frame.
68+
* Group.setProperty will now check if the property exists before setting it, this applies to Group.setAll and anything else using setProperty internally.
6869

6970

7071
### New Features
634 KB
Loading

src/core/Group.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,7 @@ Phaser.Group.prototype.setProperty = function (child, key, value, operation) {
635635

636636
operation = operation || 0;
637637

638-
// As ugly as this approach looks, and although it's limited to a depth of only 4, it's extremely fast.
639-
// Much faster than a for loop or object iteration. There are no checks, so if the key isn't valid then it'll fail
640-
// but as you are likely to call this from inner loops that have to perform well, I'll take that trade off.
638+
// As ugly as this approach looks, and although it's limited to a depth of only 4, it's much faster than a for loop or object iteration.
641639

642640
// 0 = Equals
643641
// 1 = Add
@@ -647,31 +645,31 @@ Phaser.Group.prototype.setProperty = function (child, key, value, operation) {
647645

648646
var len = key.length;
649647

650-
if (len == 1)
648+
if (len === 1 && child.hasOwnProperty(key[0]))
651649
{
652650
if (operation === 0) { child[key[0]] = value; }
653651
else if (operation == 1) { child[key[0]] += value; }
654652
else if (operation == 2) { child[key[0]] -= value; }
655653
else if (operation == 3) { child[key[0]] *= value; }
656654
else if (operation == 4) { child[key[0]] /= value; }
657655
}
658-
else if (len == 2)
656+
else if (len === 2 && child.hasOwnProperty(key[0]) && child[key[0]].hasOwnProperty(key[1]))
659657
{
660658
if (operation === 0) { child[key[0]][key[1]] = value; }
661659
else if (operation == 1) { child[key[0]][key[1]] += value; }
662660
else if (operation == 2) { child[key[0]][key[1]] -= value; }
663661
else if (operation == 3) { child[key[0]][key[1]] *= value; }
664662
else if (operation == 4) { child[key[0]][key[1]] /= value; }
665663
}
666-
else if (len == 3)
664+
else if (len === 3 && child.hasOwnProperty(key[0]) && child[key[0]].hasOwnProperty(key[1]) && child[key[0]][key[1]].hasOwnProperty(key[2]))
667665
{
668666
if (operation === 0) { child[key[0]][key[1]][key[2]] = value; }
669667
else if (operation == 1) { child[key[0]][key[1]][key[2]] += value; }
670668
else if (operation == 2) { child[key[0]][key[1]][key[2]] -= value; }
671669
else if (operation == 3) { child[key[0]][key[1]][key[2]] *= value; }
672670
else if (operation == 4) { child[key[0]][key[1]][key[2]] /= value; }
673671
}
674-
else if (len == 4)
672+
else if (len === 4 && child.hasOwnProperty(key[0]) && child[key[0]].hasOwnProperty(key[1]) && child[key[0]][key[1]].hasOwnProperty(key[2]) && child[key[0]][key[1]][key[2]].hasOwnProperty(key[3]))
675673
{
676674
if (operation === 0) { child[key[0]][key[1]][key[2]][key[3]] = value; }
677675
else if (operation == 1) { child[key[0]][key[1]][key[2]][key[3]] += value; }

0 commit comments

Comments
 (0)