Skip to content
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

fix: avoid uiTextDisplayer.destroy crashing if called more than once #6022

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Alugha GmbH <*@alugha.com>
Alvaro Velad Galvan <ladvan91@hotmail.com>
Amila Sampath <lucksy@gmail.com>
Anthony Stansbridge <github@anthonystansbridge.co.uk>
Antonio Diaz Correa <hello@antoniodiaz.me>
Armand Zangue <armand.zangue@gmail.com>
Benjamin Wallberg <me@bwallberg.com>
Bonnier Broadcasting <*@bonnierbroadcasting.com>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Alvaro Velad Galvan <ladvan91@hotmail.com>
Amila Sampath <lucksy@gmail.com>
Andy Hochhaus <ahochhaus@samegoal.com>
Anthony Stansbridge <github@anthonystansbridge.co.uk>
Antonio Diaz Correa <hello@antoniodiaz.me>
Armand Zangue <armand.zangue@gmail.com>
Ashutosh Kumar Mukhiya <ashukm4@gmail.com>
Benjamin Wallberg <benjamin.wallberg@bonnierbroadcasting.com>
Expand Down
7 changes: 7 additions & 0 deletions lib/text/ui_text_displayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ shaka.text.UITextDisplayer = class {
* @export
*/
destroy() {
// Return resolved promise if destroy() has been called.
if (!this.textContainer_) {
return Promise.resolve();
}

// Remove the text container element from the UI.
this.videoContainer_.removeChild(this.textContainer_);
this.textContainer_ = null;
Expand All @@ -176,6 +181,8 @@ shaka.text.UITextDisplayer = class {
this.resizeObserver_.disconnect();
this.resizeObserver_ = null;
}

return Promise.resolve();
}


Expand Down
9 changes: 9 additions & 0 deletions test/text/ui_text_displayer_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,4 +605,13 @@ describe('UITextDisplayer', () => {
(e) => e.nodeType == Node.ELEMENT_NODE);
expect(childrenOfTwo.length).toBe(3);
});

it('textDisplayer does not crash if destroy is called more than once', () => {
expect(videoContainer.childNodes.length).toBe(1);

textDisplayer.destroy();
textDisplayer.destroy();

expect(videoContainer.childNodes.length).toBe(0);
});
});