diff options
author | Mark Kuo <starryalley@gmail.com> | 2020-06-29 12:56:10 +1000 |
---|---|---|
committer | Mark Kuo <starryalley@gmail.com> | 2020-06-29 13:01:54 +1000 |
commit | e435d57758017ae7e92b052dcdd64488934998c1 (patch) | |
tree | 81175eb5946b2738240d4466eb55e2b4bc18b355 /scene | |
parent | 481151be09108a30002ae0a9df118eeddd3987be (diff) |
VideoPlayer: fix possible race condition
In set_stream() we write to 'playback' while accessing the same object
in _mix_audio() in audio thread. Protect the 'write' part in
set_stream() to avoid possible crash in _mix_audio() function.
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/video_player.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp index 881df06d8f..e118cb0d8d 100644 --- a/scene/gui/video_player.cpp +++ b/scene/gui/video_player.cpp @@ -201,10 +201,9 @@ bool VideoPlayer::has_expand() const { void VideoPlayer::set_stream(const Ref<VideoStream> &p_stream) { stop(); + AudioServer::get_singleton()->lock(); mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size()); - AudioServer::get_singleton()->unlock(); - stream = p_stream; if (stream.is_valid()) { stream->set_audio_track(audio_track); @@ -212,6 +211,7 @@ void VideoPlayer::set_stream(const Ref<VideoStream> &p_stream) { } else { playback = Ref<VideoStreamPlayback>(); } + AudioServer::get_singleton()->unlock(); if (!playback.is_null()) { playback->set_loop(loops); |