Examining the WebGLLayer cleanup code for the USE(ANGLE) path, it looks like textures can still be bound to IOSurfaces at the time the WebGLLayer is destroyed. Since the OpenGL context (provided via ANGLE) is going to be destroyed, it seems most prudent to unbind those textures if necessary, and delete them, in [WebGLLayer -dealloc].
Doing this work in -dealloc: turns out to not be a good idea. It looks like (from Bug 210213) the WebGLLayer is likely retained by the CALayer tree, so its lifetime is much longer than the GraphicsContextGL. There's a specific point just before deletion of the GraphicsContextGL's native context where these resources should be released.
Created attachment 396351 [details] Patch
Committed r260049: <https://trac.webkit.org/changeset/260049> All reviewed patches have been landed. Closing bug and clearing flags on attachment 396351 [details].
<rdar://problem/61745462>
+ryanhaddad@ who found the crashers previously from the fix for Bug 210213 - hope that this patch doesn't cause similar issues. Please revert if it does; thanks.
(In reply to Kenneth Russell from comment #5) > +ryanhaddad@ who found the crashers previously from the fix for Bug 210213 - > hope that this patch doesn't cause similar issues. Please revert if it does; > thanks. Thanks for the heads up!