diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-03-11 12:46:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-11 12:46:35 +0100 |
commit | 0deb3921e378178f04e9a185aa040a84fc9254e8 (patch) | |
tree | 5b44221376358fad1a34a6723629e9692d8ca0f2 | |
parent | 91d3ea0d1f33af26328c741835a8ff72c58d34d7 (diff) | |
parent | bd22b1cbe6088accf46493c304e17f616042ad68 (diff) |
Merge pull request #26911 from KidRigger/pr-fix
Fixes segfault on opening incompatible files in GDNative videodecoder.
-rw-r--r-- | modules/gdnative/videodecoder/video_stream_gdnative.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.cpp b/modules/gdnative/videodecoder/video_stream_gdnative.cpp index 8d6f167d04..8fcebe7855 100644 --- a/modules/gdnative/videodecoder/video_stream_gdnative.cpp +++ b/modules/gdnative/videodecoder/video_stream_gdnative.cpp @@ -117,18 +117,20 @@ bool VideoStreamPlaybackGDNative::open_file(const String &p_file) { file = FileAccess::open(p_file, FileAccess::READ); bool file_opened = interface->open_file(data_struct, file); - num_channels = interface->get_channels(data_struct); - mix_rate = interface->get_mix_rate(data_struct); + if (file_opened) { + num_channels = interface->get_channels(data_struct); + mix_rate = interface->get_mix_rate(data_struct); - godot_vector2 vec = interface->get_texture_size(data_struct); - texture_size = *(Vector2 *)&vec; + godot_vector2 vec = interface->get_texture_size(data_struct); + texture_size = *(Vector2 *)&vec; - 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; + 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; - texture->create((int)texture_size.width, (int)texture_size.height, Image::FORMAT_RGBA8, Texture::FLAG_FILTER | Texture::FLAG_VIDEO_SURFACE); + texture->create((int)texture_size.width, (int)texture_size.height, Image::FORMAT_RGBA8, Texture::FLAG_FILTER | Texture::FLAG_VIDEO_SURFACE); + } return file_opened; } |