-
Notifications
You must be signed in to change notification settings - Fork 46
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
out-structs containing objects and refcounting #326
Comments
Generally speaking, just because there's a pointer value for a WGPUTexture in WGPUSurfaceTexture doesn't mean that's a valid reference. It could have been Released already and the app didn't zero out the pointer because they knew they were about to overwrite it: wgpuTextureRelease(s.texture);
wgpuSurfaceGetCurrentTexture(&s); // double free I think it's the reality of the C API that we don't know what the intent was so we should just overwrite the pointer without releasing it. It's unfortunate that the overwrite is hard to see (vs. if we just did In our C++ API, we do know whether the ref is still there because the RAII wrapper already needs to know. If we implemented the C++ API in C++ that would happen automatically, because we'd write |
Sep 12 meeting:
|
Closed, still needs docs. |
We should define what happens to objects contained in out-structs that will be overwritten. I had the following code and it was leaking quite unexpectedly:
The issue is that the second
wgpuSurfaceGetCurrentTexture
call overwritess.texture
without decrementing the refcount, which means thatwgpuSurfaceTextureFreeMembers
doesn't know to unref it. (or maybe it is a C++ism of Dawn that we need to fix, but in all cases the behavior is surprising).In all cases I'd suggest that if an object is passed in an out-struct, it must be either null or valid, and if valid it will be released once.
The text was updated successfully, but these errors were encountered: