diff options
author | marcosjouron <marcosjouron@users.noreply.github.com> | 2019-10-11 19:03:49 +0200 |
---|---|---|
committer | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-11-27 16:40:16 +0100 |
commit | 6d2b21c6a40ba0303903a3a9ce59a01101e45fd8 (patch) | |
tree | 775127187ee98af60a0c308c7ec00161c07143f0 | |
parent | a87e2f85ee838245f0d5e702561faa3502b14800 (diff) |
VideoStreamGDNative: Fix playing video files without audio stream
-rw-r--r-- | modules/gdnative/videodecoder/video_stream_gdnative.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.cpp b/modules/gdnative/videodecoder/video_stream_gdnative.cpp index 14b7f9a2ef..ab14f01858 100644 --- a/modules/gdnative/videodecoder/video_stream_gdnative.cpp +++ b/modules/gdnative/videodecoder/video_stream_gdnative.cpp @@ -123,9 +123,12 @@ bool VideoStreamPlaybackGDNative::open_file(const String &p_file) { godot_vector2 vec = interface->get_texture_size(data_struct); texture_size = *(Vector2 *)&vec; + // Only do memset if num_channels > 0 otherwise it will crash. + if (num_channels > 0) { + pcm = (float *)memalloc(num_channels * AUX_BUFFER_SIZE * sizeof(float)); + memset(pcm, 0, num_channels * AUX_BUFFER_SIZE * sizeof(float)); + } - pcm = (float *)memalloc(num_channels * AUX_BUFFER_SIZE * sizeof(float)); - memset(pcm, 0, num_channels * AUX_BUFFER_SIZE * sizeof(float)); pcm_write_idx = -1; samples_decoded = 0; @@ -146,7 +149,8 @@ void VideoStreamPlaybackGDNative::update(float p_delta) { ERR_FAIL_COND(interface == NULL); interface->update(data_struct, p_delta); - if (mix_callback) { + // Don't mix if there's no audio (num_channels == 0). + if (mix_callback && num_channels > 0) { if (pcm_write_idx >= 0) { // Previous remains int mixed = mix_callback(mix_udata, pcm + pcm_write_idx * num_channels, samples_decoded); |