script: Move WebGLProgram Drop implementation to a member type#37622
Conversation
| #[no_trace] | ||
| id: WebGLProgramId, | ||
| is_in_use: Cell<bool>, | ||
| marked_for_deletion: Cell<bool>, | ||
| fragment_shader: MutNullableDom<WebGLShader>, |
There was a problem hiding this comment.
Any Dom value like this is JS-owned and unsafe to use from the destructor. We'll need to look more closely at this.
There was a problem hiding this comment.
I don't know how to use WeakRef instead of it...
There was a problem hiding this comment.
Could the solution be creating a WeakNullableRef struct or trait?
There was a problem hiding this comment.
Does RefCell<Option<WeakRef<WebGLShader>>> work? Sorry for missing this question; I was reminded of this PR by #40655.
There was a problem hiding this comment.
How can I solve this?
error[E0277]: the trait bound `dom::webgl::webglshader::WebGLShader: script_bindings::weakref::WeakReferenceable` is not satisfied
--> components\script\dom\webgl\webglprogram.rs:38:37
|
38 | fragment_shader: RefCell<Option<WeakRef<WebGLShader>>>,
| ^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
There was a problem hiding this comment.
Add a new entry like https://github.com/willypuzzle/servo/blob/af27c801b1db0c0da93f380f46bdeb957828eb56/components/script_bindings/codegen/Bindings.conf#L678 for the WebGLShader interface.
…0725) Many WebGL objects refer to a `WebGLRenderingContext` and rely on it for messaging to the `WebGLThread`. This poses a problem, because WebGL objects often need to send a message to the `WebGLThread` during their `Drop` implementation. If the `Drop` is triggered as part of garbage collection, references to the `WebGLRenderingContext` might be invalid, if they were garbage collected first as part of the same harvest. This change makes it so that all of these objects store a `WeakRef` instead of a `Dom<>`. The `WeakRef` is only used if it can be rooted, otherwise a `ContextLost` error is given. In cases where only messaging is needed, a cloned `WebGLMsgSender` is used to perform messages regardless of whether the context is garbage collected or not. This isn't a replacement for #37622, but should make it easier to implement as the `WebGLMsgSender` and the `WeakRef` could be stored in the droppable portion of the DOM object. Testing: This fixes a use-after-free issue which is mainly detectable via ASAN builds. Since we do not run ASAN on CI, this is a bit hard to create automated tests for. I verified that this fixed the issue manually. Fixes: #40655. Signed-off-by: Martin Robinson <[email protected]>
|
@jdm I pulled the new modifications of repository and I found this:
Inside a routine called from I haven't found a way to call that from a Droppable struct (that is the struct that should implement |
3af944a to
a00f290
Compare
| return; | ||
| } | ||
| self.marked_for_deletion.set(true); | ||
| self.upcast().send_with_fallibility(WebGLCommand::DeleteProgram(self.id()), operation_fallibility); |
There was a problem hiding this comment.
This is the new code of the mark_for_deletion method, but there is not way to call something of similar to upcast() here @jdm
There was a problem hiding this comment.
The droppable struct will need a webgl_sender to do its own communication instead of calling self.upcast().send_with_fallibility.
There was a problem hiding this comment.
Where do I get a webgl_sender? I instance a new one?
There was a problem hiding this comment.
Clone it from the WebGLObject in the WebGLProgram constructor.
There was a problem hiding this comment.
I modified it, tell me if the solution is good for you and after I'll try to replace MutNullableDom<*> with RefCell<Option<WeakRef<*>>>
|
a00f290 to
af27c80
Compare
|
Yeah, that looks like it should work! |
db6451d to
a3650ca
Compare
|
@jdm the PR is formally correct, that is, it compiles. I pass the ball to you. |
jdm
left a comment
There was a problem hiding this comment.
Looking pretty good! I think we can cut down on some of the simple getters and setters to make the code more clear.
a3650ca to
6a7a6b5
Compare
|
@jdm I applied your suggestions, please take a look :) |
6a7a6b5 to
61bc92d
Compare
1062720 to
b871007
Compare
|
@jdm see, if you like my implementation, in my local machine tests seem to pass. |
459a234 to
14939de
Compare
|
@jdm how can I remove this error? https://github.com/servo/servo/actions/runs/19935448487/job/57158859243?pr=37622 I don't rimember how and can't figure out how |
8a0dce9 to
3f96680
Compare
jdm
left a comment
There was a problem hiding this comment.
Really close now! Thanks for sticking with this.
3f96680 to
9b5a69a
Compare
9b5a69a to
4b90663
Compare
Signed-off-by: Domenico Rizzo <[email protected]>
4b90663 to
df2096e
Compare
The handwritten Drop implementation was removed in #37622, so we can now remove the exception for it. Testing: Compile-time generated code can't be meaningfully tested. Fixes: part of #26488 Signed-off-by: Josh Matthews <[email protected]>
|
Thanks God! Finally! |
Testing: No new tests introduced
Fixes: Partially #26488