Skip to content

Commit 7fcd70c

Browse files
webgl context objects leak fix
Changing order of operations in ~WebGLRenderingContextBase Otherwise, WebGLContextGroup will not be able to release some of the 'group shared' resources that still have attachements when being removed via WebGLSharedObject destructor - it happens eg. for WebGLVertexArrayObjectBase objects that have buffers set on destruction time. The current behaviour in ~WebGLRenderingContextBase: - first, the reference to some WebGLSharedObject (like m_boundArrayBuffer) is nullified - since this decreases refcnt to 0, destructor for this WebGLSharedObject is executed - this goes via WebGLObject::runDestructor() -> WebGLObject::deleteObject. - WebGLObject::deleteObject checks for attachement count (m_attachmentCount) and if it's not 0 it will not execute deleteObjectImpl (where the actual removal from the context takes place). - So the reference to the object is destructed, and ~WebGLSharedObject removes the object from m_contextGroup as well. At this point the resource is leaked. With the fix, m_contextGroup->removeContext(*this) is executed at the beginning of ~WebGLRenderingContextBase - this calls detach() on all the objects (WebGLContextGroup::detachAndRemoveAllObjects) so is possible to release them.
1 parent f0b98a4 commit 7fcd70c

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,13 @@ void WebGLRenderingContextBase::removeActivityStateChangeObserver()
12381238

12391239
WebGLRenderingContextBase::~WebGLRenderingContextBase()
12401240
{
1241+
if (!m_isPendingPolicyResolution) {
1242+
// need to remove from the group first, before we destroy the graphics context
1243+
// othwerwise, in case this is the last context in the group, when the context group tries
1244+
// to cleanup the remaining objects, it will not call deleteImpl (see WebGLObject::deleteObject)
1245+
// since the context is no longer available
1246+
m_contextGroup->removeContext(*this);
1247+
}
12411248
// Remove all references to WebGLObjects so if they are the last reference
12421249
// they will be freed before the last context is removed from the context group.
12431250
m_boundArrayBuffer = nullptr;
@@ -1262,7 +1269,6 @@ WebGLRenderingContextBase::~WebGLRenderingContextBase()
12621269
detachAndRemoveAllObjects();
12631270
loseExtensions(LostContextMode::RealLostContext);
12641271
destroyGraphicsContextGL();
1265-
m_contextGroup->removeContext(*this);
12661272
}
12671273

12681274
{

0 commit comments

Comments
 (0)