Skip to content

Commit d9c9e05

Browse files
Merge pull request #506 from akashic-games/fix-destroyed-check-for-e
Fix destroyed check for E
2 parents 40c7226 + 0a58923 commit d9c9e05

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# ChangeLog
22

3+
## 3.18.3
4+
* `g.E#destroy()` で破棄済みチェックを行うように修正
5+
36
## 3.18.2
47
* `OperationHandler#onOperaiton()``instanceof` での判定をやめ `Array.isArray()` を利用するように修正
58

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@akashic/akashic-engine",
3-
"version": "3.18.2",
3+
"version": "3.18.3",
44
"description": "The core library of Akashic Engine",
55
"main": "index.js",
66
"dependencies": {

src/__tests__/ESpec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,19 @@ describe("test E", () => {
360360
expect((e as any)._onPointUp).toBeUndefined();
361361
});
362362

363+
it("destroy - check for multiple executions", () => {
364+
const e2 = new E({ scene: runtime.scene });
365+
const spy = jest.spyOn(e2.scene, "unregister");
366+
367+
e2.destroy();
368+
expect(e2.destroyed()).toBeTruthy();
369+
expect(spy.mock.calls.length).toBe(1);
370+
371+
e2.destroy();
372+
expect(spy.mock.calls.length).toBe(1); // 破棄済みの場合、 destory() を実行しても呼ばれないのでカウントは増えない。
373+
spy.mockClear();
374+
});
375+
363376
it("modified", () => {
364377
resetUpdated(runtime);
365378
expect(runtime.game._modified).toBe(false);

src/entities/E.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,8 @@ export class E extends Object2D implements CommonArea {
513513
* 子孫を持っている場合、子孫も破棄される。
514514
*/
515515
destroy(): void {
516+
if (this.destroyed()) return;
517+
516518
if (this.parent) this.remove();
517519

518520
if (this.children) {

0 commit comments

Comments
 (0)