Skip to content

Commit

Permalink
Merge pull request #1328 from OpenGeoscience/reinit-context
Browse files Browse the repository at this point in the history
fix: Attempt to reinitialize the webgl context when restored
  • Loading branch information
manthey authored Sep 3, 2024
2 parents 208c840 + b2b3ae1 commit f4b8f98
Showing 1 changed file with 3 additions and 1 deletion.
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

0 comments on commit f4b8f98

Please sign in to comment.