-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(google-maps): initialize deck in onDraw when onContextRestored is skipped #10179
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
base: master
Are you sure you want to change the base?
Changes from all commits
f60f378
3fa32fe
5028f51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,7 +164,7 @@ export default class GoogleMapsOverlay { | |
|
|
||
| // Create WebGL overlay for camera data (and GL context if interleaved) | ||
| const overlay = new google.maps.WebGLOverlayView(); | ||
| overlay.onAdd = noop; | ||
| overlay.onAdd = interleaved ? this._onAddInterleaved.bind(this) : noop; | ||
| overlay.onContextRestored = interleaved ? this._onContextRestored.bind(this) : noop; | ||
| overlay.onDraw = this._onDrawVector.bind(this); | ||
| overlay.onContextLost = interleaved ? this._onContextLost.bind(this) : noop; | ||
|
|
@@ -205,6 +205,23 @@ export default class GoogleMapsOverlay { | |
| this._deck = createDeckInstance(this._map, overlay, this._deck, this.props); | ||
| } | ||
|
|
||
| _onAddInterleaved() { | ||
| // When a WebGLOverlayView is removed and a new one is added to the same map, | ||
| // Google Maps may skip onContextRestored because the WebGL context was never | ||
| // actually lost. In that case, retrieve the existing GL context from the map's | ||
| // canvas and initialize the deck instance here in onAdd. | ||
| if (!this._map) { | ||
| return; | ||
| } | ||
| const mapCanvas = this._map.getDiv().querySelector('canvas'); | ||
| if (mapCanvas) { | ||
| const gl = mapCanvas.getContext('webgl2'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very suspicious... If the underlying context has not been created for any reason, this will return a new WebGL context AND break the base map because
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair concern. Two options I can take:
(1) feels safer to me if requestRedraw reliably triggers onContextRestored on a re-add. |
||
| if (gl) { | ||
| this._onContextRestored({gl}); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| _updateContainerSize() { | ||
| // Update positioning container size and position to match map | ||
| if (!this._map) return; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
onContextRestoredis also invoked on first add, doesn't this call_onContextRestoredtwice?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. On first add Google Maps does fire onContextRestored separately, so this would indeed double-init. The intent here was to cover the re-add case where the context was never lost and onContextRestored is skipped.
Thinking about the cleanest fix: track an
_overlayInitializedflag per overlay instance that_onContextRestoredsets (and_onContextLost/_onRemoveclears), then defer the fallback viaqueueMicrotaskso Google Maps' own onContextRestored can fire first. If it does, the flag gates out the duplicate. If it doesn't (the re-add case), we fetch the existing context.Does that approach sound right to you before I push?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still not convinced. As I commented before: