Skip to content

Commit bb4f88b

Browse files
antondcavelad
authored andcommitted
fix: avoid uiTextDisplayer.destroy crashing if called more than once (#6022)
1 parent d3081f6 commit bb4f88b

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Alugha GmbH <*@alugha.com>
2121
Alvaro Velad Galvan <ladvan91@hotmail.com>
2222
Amila Sampath <lucksy@gmail.com>
2323
Anthony Stansbridge <github@anthonystansbridge.co.uk>
24+
Antonio Diaz Correa <hello@antoniodiaz.me>
2425
Armand Zangue <armand.zangue@gmail.com>
2526
Benjamin Wallberg <me@bwallberg.com>
2627
Bonnier Broadcasting <*@bonnierbroadcasting.com>

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Alvaro Velad Galvan <ladvan91@hotmail.com>
3232
Amila Sampath <lucksy@gmail.com>
3333
Andy Hochhaus <ahochhaus@samegoal.com>
3434
Anthony Stansbridge <github@anthonystansbridge.co.uk>
35+
Antonio Diaz Correa <hello@antoniodiaz.me>
3536
Armand Zangue <armand.zangue@gmail.com>
3637
Ashutosh Kumar Mukhiya <ashukm4@gmail.com>
3738
Benjamin Wallberg <benjamin.wallberg@bonnierbroadcasting.com>

lib/text/ui_text_displayer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ shaka.text.UITextDisplayer = class {
154154
* @export
155155
*/
156156
destroy() {
157+
// Return resolved promise if destroy() has been called.
158+
if (!this.textContainer_) {
159+
return Promise.resolve();
160+
}
161+
157162
// Remove the text container element from the UI.
158163
this.videoContainer_.removeChild(this.textContainer_);
159164
this.textContainer_ = null;
@@ -176,6 +181,8 @@ shaka.text.UITextDisplayer = class {
176181
this.resizeObserver_.disconnect();
177182
this.resizeObserver_ = null;
178183
}
184+
185+
return Promise.resolve();
179186
}
180187

181188

test/text/ui_text_displayer_unit.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,4 +605,13 @@ describe('UITextDisplayer', () => {
605605
(e) => e.nodeType == Node.ELEMENT_NODE);
606606
expect(childrenOfTwo.length).toBe(3);
607607
});
608+
609+
it('textDisplayer does not crash if destroy is called more than once', () => {
610+
expect(videoContainer.childNodes.length).toBe(1);
611+
612+
textDisplayer.destroy();
613+
textDisplayer.destroy();
614+
615+
expect(videoContainer.childNodes.length).toBe(0);
616+
});
608617
});

0 commit comments

Comments
 (0)