Bug 214999 - [WebGL2] Assert when restoring lost context
Summary: [WebGL2] Assert when restoring lost context
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: James Darpinian
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-07-30 17:41 PDT by James Darpinian
Modified: 2020-08-03 13:38 PDT (History)
10 users (show)

See Also:


Attachments
Patch (1.67 KB, patch)
2020-07-30 17:42 PDT, James Darpinian
no flags Details | Formatted Diff | Diff
Patch (1.52 KB, patch)
2020-07-31 17:35 PDT, James Darpinian
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description James Darpinian 2020-07-30 17:41:51 PDT
[WebGL2] Assert when restoring lost context
Comment 1 James Darpinian 2020-07-30 17:42:34 PDT
Created attachment 405644 [details]
Patch
Comment 2 Darin Adler 2020-07-30 19:10:09 PDT
Comment on attachment 405644 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=405644&action=review

> Source/WebCore/html/canvas/WebGL2RenderingContext.cpp:215
> +    // If we're restoring a lost context, we should delete the old default VAO before creating the new one.
> +    m_defaultVertexArrayObject = nullptr;

This points to a design problem. Decrementing the reference count on a reference counted object is not guaranteed to delete the object. If we need control of timing of object deletion then it’s not good to be using reference counted objects.
Comment 3 Darin Adler 2020-07-30 19:11:20 PDT
Comment on attachment 405644 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=405644&action=review

>> Source/WebCore/html/canvas/WebGL2RenderingContext.cpp:215
>> +    m_defaultVertexArrayObject = nullptr;
> 
> This points to a design problem. Decrementing the reference count on a reference counted object is not guaranteed to delete the object. If we need control of timing of object deletion then it’s not good to be using reference counted objects.

I suppose we could just write in a comment here the reason why we are guaranteed there is no one else holding a reference to this. Or we could come up with a way to do the deletion explicitly other than destroying the C++ reference counted thing.
Comment 4 James Darpinian 2020-07-31 00:02:36 PDT
Comment on attachment 405644 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=405644&action=review

>>> Source/WebCore/html/canvas/WebGL2RenderingContext.cpp:215
>>> +    m_defaultVertexArrayObject = nullptr;
>> 
>> This points to a design problem. Decrementing the reference count on a reference counted object is not guaranteed to delete the object. If we need control of timing of object deletion then it’s not good to be using reference counted objects.
> 
> I suppose we could just write in a comment here the reason why we are guaranteed there is no one else holding a reference to this. Or we could come up with a way to do the deletion explicitly other than destroying the C++ reference counted thing.

Sorry, "delete" is the wrong word. The object does not need to be deleted, it just needs to be disassociated from the context. I will fix the comment.
Comment 5 Darin Adler 2020-07-31 11:04:13 PDT
Comment on attachment 405644 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=405644&action=review

>>>> Source/WebCore/html/canvas/WebGL2RenderingContext.cpp:215
>>>> +    m_defaultVertexArrayObject = nullptr;
>>> 
>>> This points to a design problem. Decrementing the reference count on a reference counted object is not guaranteed to delete the object. If we need control of timing of object deletion then it’s not good to be using reference counted objects.
>> 
>> I suppose we could just write in a comment here the reason why we are guaranteed there is no one else holding a reference to this. Or we could come up with a way to do the deletion explicitly other than destroying the C++ reference counted thing.
> 
> Sorry, "delete" is the wrong word. The object does not need to be deleted, it just needs to be disassociated from the context. I will fix the comment.

I’d like to understand what "disassociated" means. Does it literally just mean that m_defaultVertexArrayObject must be null?
Comment 6 Darin Adler 2020-07-31 11:04:44 PDT
Comment on attachment 405644 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=405644&action=review

>>>>> Source/WebCore/html/canvas/WebGL2RenderingContext.cpp:215
>>>>> +    m_defaultVertexArrayObject = nullptr;
>>>> 
>>>> This points to a design problem. Decrementing the reference count on a reference counted object is not guaranteed to delete the object. If we need control of timing of object deletion then it’s not good to be using reference counted objects.
>>> 
>>> I suppose we could just write in a comment here the reason why we are guaranteed there is no one else holding a reference to this. Or we could come up with a way to do the deletion explicitly other than destroying the C++ reference counted thing.
>> 
>> Sorry, "delete" is the wrong word. The object does not need to be deleted, it just needs to be disassociated from the context. I will fix the comment.
> 
> I’d like to understand what "disassociated" means. Does it literally just mean that m_defaultVertexArrayObject must be null?

Could you clarify what the specific issue is? I understand roughly but not fully.
Comment 7 James Darpinian 2020-07-31 15:48:31 PDT
Comment on attachment 405644 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=405644&action=review

>>>>>> Source/WebCore/html/canvas/WebGL2RenderingContext.cpp:215
>>>>>> +    m_defaultVertexArrayObject = nullptr;
>>>>> 
>>>>> This points to a design problem. Decrementing the reference count on a reference counted object is not guaranteed to delete the object. If we need control of timing of object deletion then it’s not good to be using reference counted objects.
>>>> 
>>>> I suppose we could just write in a comment here the reason why we are guaranteed there is no one else holding a reference to this. Or we could come up with a way to do the deletion explicitly other than destroying the C++ reference counted thing.
>>> 
>>> Sorry, "delete" is the wrong word. The object does not need to be deleted, it just needs to be disassociated from the context. I will fix the comment.
>> 
>> I’d like to understand what "disassociated" means. Does it literally just mean that m_defaultVertexArrayObject must be null?
> 
> Could you clarify what the specific issue is? I understand roughly but not fully.

There's just an assert in WebGLVertexArrayObject::create that m_defaultVertexArrayObject is null when creating an object with Type::Default, I suppose to prevent people accidentally specifying Type::Default when they didn't mean to. Since that seems unlikely, an alternative approach would be to simply remove the assert.
Comment 8 James Darpinian 2020-07-31 17:35:46 PDT
Created attachment 405763 [details]
Patch
Comment 9 EWS 2020-08-03 10:49:19 PDT
Committed r265205: <https://trac.webkit.org/changeset/265205>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 405763 [details].
Comment 10 Radar WebKit Bug Importer 2020-08-03 13:38:08 PDT
<rdar://problem/66489320>