Fix T64144: Crash when displaying audio waveforms in VSE

This commit is contained in:
Sergey Sharybin 2019-05-04 19:15:15 +02:00
parent 773691310f
commit 9f681bea68
Notes: blender-bot 2023-02-14 12:01:57 +01:00
Referenced by commit 2b9965122e, Sound: Revert all the recent changes to sound
Referenced by commit c68c81a870, Sound: Make sure spin lock is initialized for new sound datablocks
Referenced by issue #64144, crashes when try to display audio waveforms in video sequence editor
4 changed files with 13 additions and 15 deletions

View File

@ -152,6 +152,7 @@ void BKE_sound_free(bSound *sound)
}
BKE_sound_free_audio(sound);
BKE_sound_free_waveform(sound);
if (sound->spinlock) {
BLI_spin_end(sound->spinlock);
@ -173,8 +174,6 @@ void BKE_sound_free_audio(bSound *sound)
AUD_Sound_free(sound->cache);
sound->cache = NULL;
}
BKE_sound_free_waveform(sound);
#else
UNUSED_VARS(sound);
#endif /* WITH_AUDASPACE */
@ -199,8 +198,8 @@ void BKE_sound_copy_data(Main *UNUSED(bmain),
sound_dst->cache = NULL;
sound_dst->waveform = NULL;
sound_dst->playback_handle = NULL;
sound_dst->spinlock =
NULL; /* Think this is OK? Otherwise, easy to create new spinlock here... */
sound_dst->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
BLI_spin_init(sound_dst->spinlock);
/* Just to be sure, should not have any value actually after reading time. */
sound_dst->ipo = NULL;
@ -882,10 +881,11 @@ void BKE_sound_free_waveform(bSound *sound)
sound->tags &= ~SOUND_TAGS_WAVEFORM_NO_RELOAD;
}
/* TODO(sergey): Consider mamakinging this function fully autonomous, as in, not require having
* an existing playback handle. That would make it easy to read waveforms, which doesn't seem to
* be affected by evaluated scene (waveworm comes from file). */
void BKE_sound_read_waveform(bSound *sound, short *stop)
{
sound_verify_evaluated_id(&sound->id);
AUD_SoundInfo info = AUD_getInfo(sound->playback_handle);
SoundWaveform *waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform");

View File

@ -8403,10 +8403,9 @@ static void direct_link_sound(FileData *fd, bSound *sound)
sound->waveform = NULL;
}
if (sound->spinlock) {
sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
BLI_spin_init(sound->spinlock);
}
sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
BLI_spin_init(sound->spinlock);
/* clear waveform loading flag */
sound->tags &= ~SOUND_TAGS_WAVEFORM_LOADING;

View File

@ -259,11 +259,6 @@ static void drawseqwave(View2D *v2d,
return;
}
if (!sound->spinlock) {
sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
BLI_spin_init(sound->spinlock);
}
BLI_spin_lock(sound->spinlock);
if (!sound->waveform) {
if (!(sound->tags & SOUND_TAGS_WAVEFORM_LOADING)) {

View File

@ -50,6 +50,7 @@ typedef struct PreviewJob {
typedef struct PreviewJobAudio {
struct PreviewJobAudio *next, *prev;
struct Main *bmain;
bSound *sound;
int lr; /* sample left or right */
int startframe;
@ -79,7 +80,9 @@ static void preview_startjob(void *data, short *stop, short *do_update, float *p
PreviewJobAudio *preview_next;
bSound *sound = previewjb->sound;
BKE_sound_load_audio(previewjb->bmain, sound);
BKE_sound_read_waveform(sound, stop);
BKE_sound_free_audio(sound);
if (*stop || G.is_break) {
BLI_mutex_lock(pj->mutex);
@ -153,6 +156,7 @@ void sequencer_preview_add_sound(const bContext *C, Sequence *seq)
/* attempt to lock mutex of job here */
audiojob->bmain = CTX_data_main(C);
audiojob->sound = seq->sound;
BLI_mutex_lock(pj->mutex);