Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upHandle cancelAnimationFrame() when called within a requestAnimationFrame() callback #26251
Comments
|
Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the If you intend to work on this issue, then add |
|
I'd like to give this a try. @highfive assign me |
|
Hey @tigleym! Thanks for your interest in working on this issue. It's now assigned to you! |
|
@Manishearth I'll need some help finding a good way to execute each callback for So far, this is what I'm trying to do: Move the vector from mem::replace(
&mut *self.current_raf_callback_list.borrow_mut(),
mem::replace(&mut *self.raf_callback_list.borrow_mut(), vec![])
);Iterate over the callbacks stored on for (_, callback) in self.current_raf_callback_list.borrow().iter() {
if let Some(callback) = callback {
let _ = callback.Call__(time, &frame, ExceptionHandling::Report);
}
}In let mut list = self.raf_callback_list.borrow_mut();
// Find the entry in raf_callback_list, otherwise try finding it in current_raf_callback_list
if let Some(pair) = list.iter_mut().find(|pair| pair.0 == frame) {
pair.1 = None;
} else {
// Panic happens here because current_raf_callback_list is already borrowed.
if let Some(pair) = self.current_raf_callback_list.borrow_mut().iter_mut().find(|pair| pair.0 == frame) {
pair.1 = None;
}
}Perhaps what I can try doing is putting |
No, because then What needs to be done instead is that the loop |
|
@Manishearth thanks for the info! Unfortunately, I don't have a lot of time to work on this right now. So feel free to unassign me if you or someone else would like to finish it off. Thanks! |
|
Can I work on this? @highfive: assign me |
|
Hey @huangjiahua! Thanks for your interest in working on this issue. It's now assigned to you! |
|
@Manishearth This is my approach right now let len = self.current_raf_callback_list.borrow().len();
for i in 0..len {
let _ = self.current_raf_callback_list.borrow()[i]
.1
.as_ref()
.and_then(|callback| {
let _ = callback.Call__(time, &frame, ExceptionHandling::Report);
Some(())
});
}Will this work? And I'm trying to run tests right now, it seems that running all the tests is time consuming for my PC, so is there any subset of tests I should run to check this? |
|
Yes. |
Handle cancelAnimationFrame() when called within a requestAnimationFr… …ame() callback <!-- Please describe your changes on the following line: --> In order to handle `cancelAnimationFrame()` in the callback, the `raf_callback_list` is moved to `current_raf_callback_list`, and each callback is cloned in the iteration of `current_raf_callback_list` to avoid "borrowed twice". --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #26251 <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Spec change: immersive-web/webxr#1005 (comment)
Relevant code:
servo/components/script/dom/xrsession.rs
Lines 398 to 414 in b60c70b
Currently we take
self.raf_callback_listout and put it on the stack, and then iterate through it.Instead, we should have a second
current_raf_callback_listlist on the object, move the vector there, and use indexed iteration. Then, inCancelAnimationFrame, we check both lists.