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 requestAnimationFr… #26491
Conversation
|
r? @Manishearth |
|
@bors-servo r+ thanks! |
|
|
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. -->
|
Would be nice if we could add a test for this behavior. I might do that later. |
|
@bors-servo r- |
| @@ -395,7 +398,10 @@ impl XRSession { | |||
| // Step 3: XXXManishearth handle inline session | |||
|
|
|||
| // Step 4-5 | |||
| let mut callbacks = mem::replace(&mut *self.raf_callback_list.borrow_mut(), vec![]); | |||
| mem::replace( | |||
This comment has been minimized.
This comment has been minimized.
Manishearth
May 12, 2020
•
Member
I think here we should instead just swap current and raf_callback_list (asserting that current is empty), and after the for loop we should clear current
Something like
let mut current = self.current_raf_callback_list.borrow_mut();
assert!(current.is_empty());
mem::swap(&mut *self.raf_callback_list.borrow_mut(), &mut *current);
drop(current);
.....
*self.current_raf_callback_list.borrow_mut() = vec![];
This comment has been minimized.
This comment has been minimized.
Manishearth
May 12, 2020
Member
This basically ensures we don't hold on to RAF callbacks longer than necessary
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Manishearth
May 12, 2020
Member
Yes, because otherwise the guard will be borrowed for too long. You can also do this by inserting an enclosing scope.
|
|
|
Nice, this makes us pass some tests
|
|
You'll also need to update test expectations for those two listed tests. Run |
…ame() callback
|
Hmm, we should not be getting a crash with that test. |
|
Tested it locally, I'm not getting a crash. Just delete |
|
OK. It seems that I use a system with no GUI to run these tests. |
|
@bors-servo r+ servo should be able to run headless just fine, but yeah there can be weird GL issues |
|
|
|
|
huangjiahua commentedMay 12, 2020
…ame() callback
In order to handle
cancelAnimationFrame()in the callback, theraf_callback_listis moved tocurrent_raf_callback_list, and each callback is cloned in the iteration ofcurrent_raf_callback_listto avoid "borrowed twice"../mach build -ddoes not report any errors./mach test-tidydoes not report any errors