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: Attempt to reinitialize the webgl context when restored #1328

Merged
merged 1 commit into from
Sep 3, 2024
Merged
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
4 changes: 3 additions & 1 deletion src/webgl/webglRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ var webglRenderer = function (arg) {
m_viewer.init();
m_contextRenderer = m_viewer.renderWindow().activeRenderer();
m_contextRenderer.setResetScene(false);
canvas.get(0).addEventListener('webglcontextlost', (evt) => evt.preventDefault(), false);
canvas.get(0).addEventListener('webglcontextrestored', () => m_viewer.renderWindow()._init(), false);

if (m_viewer.renderWindow().renderers().length > 0) {
m_contextRenderer.setLayer(m_viewer.renderWindow().renderers().length);
Expand Down Expand Up @@ -140,7 +142,7 @@ var webglRenderer = function (arg) {
/* If we are already scheduled to render, don't schedule again. Rather,
* mark that we should render after other animation frame requests occur.
* It would be nice if we could just reschedule the call by removing and
* readding the animation frame request, but this doesn't work for if the
* re-adding the animation frame request, but this doesn't work for if the
* reschedule occurs during another animation frame callback (it then waits
* until a subsequent frame). */
m_this.layer().map().scheduleAnimationFrame(m_this._renderFrame, true);
Expand Down