Skip to content

Commit

Permalink
fix: Engine.dispose()
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Feb 19, 2024
1 parent f955d33 commit e55f655
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1043,11 +1043,17 @@ O|===|* >________________>\n\
}

private _disposed = false;
/**
* Attempts to completely clean up excalibur resources, including removing the canvas from the dom.
*
* To start again you will need to new up an Engine.
*/
public dispose() {
if (!this._disposed) {
this._disposed = true;
this.stop();
this.input.toggleEnabled(false);
this.canvas.parentNode.removeChild(this.canvas);
this.canvas = null;
this.screen.dispose();
this.graphicsContext.dispose();
Expand Down
2 changes: 2 additions & 0 deletions src/engine/Screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ export class Screen {
if (!this._isDisposed) {
// Clean up handlers
this._isDisposed = true;
this.events.clear();
this._browser.window.off('resize', this._resizeHandler);
this._browser.window.clear();
if (this._resizeObserver) {
this._resizeObserver.disconnect();
}
Expand Down

0 comments on commit e55f655

Please sign in to comment.