Fix T55414: waveforms are reprocessed when undoing
authorBastien Montagne <montagne29@wanadoo.fr>
Fri, 20 Jul 2018 10:01:38 +0000 (12:01 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Fri, 20 Jul 2018 10:01:38 +0000 (12:01 +0200)
Add new tag to bSound (runtime flags), and make read code to set a 'no
reload waveform' new tag, since it uses a mapping to get existing
waveform in undo case...

source/blender/blenkernel/intern/sound.c
source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_sound_types.h

index 6aa44cde0e0fa8d63f710e594f906a1f17bda266..709a00227674ece585e0b9a05b0cb1306098e691 100644 (file)
@@ -757,15 +757,19 @@ int BKE_sound_scene_playing(struct Scene *scene)
 
 void BKE_sound_free_waveform(bSound *sound)
 {
-       SoundWaveform *waveform = sound->waveform;
-       if (waveform) {
-               if (waveform->data) {
-                       MEM_freeN(waveform->data);
+       if ((sound->tags & SOUND_TAGS_WAVEFORM_NO_RELOAD) == 0) {
+               SoundWaveform *waveform = sound->waveform;
+               if (waveform) {
+                       if (waveform->data) {
+                               MEM_freeN(waveform->data);
+                       }
+                       MEM_freeN(waveform);
                }
-               MEM_freeN(waveform);
-       }
 
-       sound->waveform = NULL;
+               sound->waveform = NULL;
+       }
+       /* This tag is only valid once. */
+       sound->tags &= ~SOUND_TAGS_WAVEFORM_NO_RELOAD;
 }
 
 void BKE_sound_read_waveform(bSound *sound, short *stop)
index 1def462b1ca7cf3b13583d84065e49dde3509c89..1d772a15efdb398e92728bb144459d101fa71757 100644 (file)
@@ -7542,6 +7542,7 @@ static void direct_link_speaker(FileData *fd, Speaker *spk)
 
 static void direct_link_sound(FileData *fd, bSound *sound)
 {
+       sound->tags = 0;
        sound->handle = NULL;
        sound->playback_handle = NULL;
 
@@ -7553,6 +7554,7 @@ static void direct_link_sound(FileData *fd, bSound *sound)
 
        if (fd->soundmap) {
                sound->waveform = newsoundadr(fd, sound->waveform);
+               sound->tags |= SOUND_TAGS_WAVEFORM_NO_RELOAD;
        }
        else {
                sound->waveform = NULL;
index aefe1a7d5a3f4d090740fff30788e357b95eec23..7778582b82d76e956d0b911cbfcfa139b902daa2 100644 (file)
@@ -65,13 +65,15 @@ typedef struct bSound {
         */
        struct PackedFile *newpackedfile;
        struct Ipo *ipo;
+
        float volume;
        float attenuation;
        float pitch;
        float min_gain;
        float max_gain;
        float distance;
-       int flags;
+       short flags;
+       short tags;  /* Runtime only, always reset in readfile. */
        int pad;
 
        /* unused currently
@@ -116,6 +118,7 @@ enum {
        SND_CFRA_NUM    = 2,
 };
 
+/* bSound->flags */
 enum {
 #ifdef DNA_DEPRECATED
        SOUND_FLAGS_3D                   = (1 << 3),  /* deprecated! used for sound actuator loading */
@@ -125,6 +128,11 @@ enum {
        SOUND_FLAGS_WAVEFORM_LOADING     = (1 << 6),
 };
 
+/* bSound->tags */
+enum {
+       SOUND_TAGS_WAVEFORM_NO_RELOAD    = 1 << 0,  /* Do not free/reset waveform on sound load, only used by undo code. */
+};
+
 /* to DNA_sound_types.h*/
 
 #endif