diff options
author | Nicholas Bishop <nicholasbishop@gmail.com> | 2015-01-15 14:51:53 +0300 |
---|---|---|
committer | Nicholas Bishop <nicholasbishop@gmail.com> | 2015-01-15 16:01:04 +0300 |
commit | 4b0007cf821caa0f51b16275ec011949de318c89 (patch) | |
tree | a6c4f235fbe50001239fc49999b1237944b50c46 /source/blender/blenkernel/intern | |
parent | b41ce0d1b95973c64bb4300a20c1b89506fe32d0 (diff) |
Prevent waveform drawing from continually retrying bad files
If sound_read_waveform() cannot read the file (i.e. info.length is
zero), set the sound's waveform to a valid waveform of zero
length. This indicates that reading the waveform is done so that it
doesn't get tried over and over again.
Reviewed By: sergey
Differential Revision: https://developer.blender.org/D988
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/sound.c | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 5c5b2cc02c5..88720d5fcb7 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -673,9 +673,12 @@ int sound_scene_playing(struct Scene *scene) void sound_free_waveform(bSound *sound) { - if (sound->waveform) { - MEM_freeN(((SoundWaveform *)sound->waveform)->data); - MEM_freeN(sound->waveform); + SoundWaveform *waveform = sound->waveform; + if (waveform) { + if (waveform->data) { + MEM_freeN(waveform->data); + } + MEM_freeN(waveform); } sound->waveform = NULL; @@ -683,29 +686,37 @@ void sound_free_waveform(bSound *sound) void sound_read_waveform(bSound *sound, short *stop) { - AUD_SoundInfo info; - SoundWaveform *waveform = NULL; - - info = AUD_getInfo(sound->playback_handle); - + AUD_SoundInfo info = AUD_getInfo(sound->playback_handle); + SoundWaveform *waveform = MEM_mallocN(sizeof(SoundWaveform), + "SoundWaveform"); + if (info.length > 0) { int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND; - waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform"); waveform->data = MEM_mallocN(length * sizeof(float) * 3, "SoundWaveform.samples"); waveform->length = AUD_readSound(sound->playback_handle, waveform->data, length, SOUND_WAVE_SAMPLES_PER_SECOND, stop); - - if (*stop) { + } + else { + /* Create an empty waveform here if the sound couldn't be + * read. This indicates that reading the waveform is "done", + * whereas just setting sound->waveform to NULL causes other + * code to think the waveform still needs to be created. */ + waveform->data = NULL; + waveform->length = 0; + } + + if (*stop) { + if (waveform->data) { MEM_freeN(waveform->data); - MEM_freeN(waveform); - BLI_mutex_lock(sound->mutex); - sound->flags &= ~SOUND_FLAGS_WAVEFORM_LOADING; - BLI_mutex_unlock(sound->mutex); - return; } - - sound_free_waveform(sound); + MEM_freeN(waveform); + BLI_mutex_lock(sound->mutex); + sound->flags &= ~SOUND_FLAGS_WAVEFORM_LOADING; + BLI_mutex_unlock(sound->mutex); + return; } + + sound_free_waveform(sound); BLI_mutex_lock(sound->mutex); sound->waveform = waveform; |