Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix events being fired after Map#remove has been called when the WebGL context is lost and restored (#726) #727

Merged
merged 2 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- Fix padding-top of the popup to improve readability of popup text (#354).
- Fix GeoJSONSource#loaded sometimes returning true while there are still pending loads (#669)
- Fix MapDataEvent#isSourceLoaded being true in GeoJSONSource "dataloading" event handlers (#694)
- Fix events being fired after Map#remove has been called when the WebGL context is lost and restored (#726)

## 1.15.2

Expand Down
2 changes: 2 additions & 0 deletions src/ui/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2677,6 +2677,8 @@ class Map extends Camera {

const extension = this.painter.context.gl.getExtension('WEBGL_lose_context');
if (extension) extension.loseContext();
this._canvas.removeEventListener('webglcontextrestored', this._contextRestored, false);
HarelM marked this conversation as resolved.
Show resolved Hide resolved
this._canvas.removeEventListener('webglcontextlost', this._contextLost, false);
DOM.remove(this._canvasContainer);
DOM.remove(this._controlContainer);
this._container.classList.remove('maplibregl-map', 'mapboxgl-map');
Expand Down
27 changes: 27 additions & 0 deletions test/unit/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,33 @@ test('Map', (t) => {
});
});

t.test('does not fire "webglcontextlost" after #remove has been called', (t) => {
const map = createMap(t);
const canvas = map.getCanvas();
map.once('webglcontextlost', () => t.fail('"webglcontextlost" fired after #remove has been called'));
map.remove();
// Dispatch the event manually because at the time of this writing, gl does not support
// the WEBGL_lose_context extension.
canvas.dispatchEvent(new window.Event('webglcontextlost'));
t.end();
});

t.test('does not fire "webglcontextrestored" after #remove has been called', (t) => {
const map = createMap(t);
const canvas = map.getCanvas();

map.once('webglcontextlost', () => {
map.once('webglcontextrestored', () => t.fail('"webglcontextrestored" fired after #remove has been called'));
map.remove();
canvas.dispatchEvent(new window.Event('webglcontextrestored'));
t.end();
});

// Dispatch the event manually because at the time of this writing, gl does not support
// the WEBGL_lose_context extension.
canvas.dispatchEvent(new window.Event('webglcontextlost'));
});

t.test('#redraw', (t) => {
const map = createMap(t);

Expand Down