Fixes VideostreamGDNative crash on audio_channel=0.

Added an if case to check if the mix_callback exists before running any
of the audio code.

Fixes: #28644
(cherry picked from commit f0757f31a4)
This commit is contained in:
Anish 2019-05-04 00:34:58 +05:30 committed by Rémi Verschelde
parent cd1bb5d3db
commit c70a3671b0
1 changed files with 18 additions and 16 deletions

View File

@ -146,23 +146,25 @@ void VideoStreamPlaybackGDNative::update(float p_delta) {
ERR_FAIL_COND(interface == NULL); ERR_FAIL_COND(interface == NULL);
interface->update(data_struct, p_delta); interface->update(data_struct, p_delta);
if (pcm_write_idx >= 0) { if (mix_callback) {
// Previous remains if (pcm_write_idx >= 0) {
int mixed = mix_callback(mix_udata, pcm, samples_decoded); // Previous remains
if (mixed == samples_decoded) { int mixed = mix_callback(mix_udata, pcm, samples_decoded);
pcm_write_idx = -1; if (mixed == samples_decoded) {
} else { pcm_write_idx = -1;
samples_decoded -= mixed; } else {
pcm_write_idx += mixed; samples_decoded -= mixed;
pcm_write_idx += mixed;
}
} }
} if (pcm_write_idx < 0) {
if (pcm_write_idx < 0) { samples_decoded = interface->get_audioframe(data_struct, pcm, AUX_BUFFER_SIZE);
samples_decoded = interface->get_audioframe(data_struct, pcm, AUX_BUFFER_SIZE); pcm_write_idx = mix_callback(mix_udata, pcm, samples_decoded);
pcm_write_idx = mix_callback(mix_udata, pcm, samples_decoded); if (pcm_write_idx == samples_decoded) {
if (pcm_write_idx == samples_decoded) { pcm_write_idx = -1;
pcm_write_idx = -1; } else {
} else { samples_decoded -= pcm_write_idx;
samples_decoded -= pcm_write_idx; }
} }
} }