Skip to content

Commit 09d1fb6

Browse files
authored
Merge pull request #28 from maxakuru/master
check index before remove, check bbox exists in non-updating methods
2 parents d8eb780 + f4f171e commit 09d1fb6

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

code/simple.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ export class Simple {
6161
* @return {Array} array
6262
*/
6363
removeList(array: DisplayObjectWithCullingArray): DisplayObjectWithCullingArray {
64-
this.lists.splice(this.lists.indexOf(array), 1)
64+
const index = this.lists.indexOf(array)
65+
if(index === -1){
66+
return array
67+
}
68+
this.lists.splice(index, 1)
6569
return array
6670
}
6771

@@ -92,7 +96,11 @@ export class Simple {
9296
* @return {DisplayObjectWithCulling} object
9397
*/
9498
remove(object: DisplayObjectWithCulling): DisplayObjectWithCulling {
95-
this.lists[0].splice(this.lists[0].indexOf(object), 1)
99+
const index = this.lists[0].indexOf(object)
100+
if(index === -1){
101+
return object
102+
}
103+
this.lists[0].splice(index, 1)
96104
return object
97105
}
98106

@@ -174,7 +182,8 @@ export class Simple {
174182
for (let list of this.lists) {
175183
for (let object of list) {
176184
const box = object.AABB
177-
if (box.x + box.width > bounds.x && box.x - box.width < bounds.x + bounds.width &&
185+
if (box &&
186+
box.x + box.width > bounds.x && box.x - box.width < bounds.x + bounds.width &&
178187
box.y + box.height > bounds.y && box.y - box.height < bounds.y + bounds.height) {
179188
results.push(object)
180189
}
@@ -194,7 +203,8 @@ export class Simple {
194203
for (let list of this.lists) {
195204
for (let object of list) {
196205
const box = object.AABB
197-
if (box.x + box.width > bounds.x && box.x - box.width < bounds.x + bounds.width &&
206+
if (box &&
207+
box.x + box.width > bounds.x && box.x - box.width < bounds.x + bounds.width &&
198208
box.y + box.height > bounds.y && box.y - box.height < bounds.y + bounds.height) {
199209
if (callback(object)) {
200210
return true

0 commit comments

Comments
 (0)