Revision: 15570
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15570
Author:   campbellbarton
Date:     2008-07-14 19:19:24 +0200 (Mon, 14 Jul 2008)

Log Message:
-----------
bugfix
* samples that wernt loaded could crash blender - divide by zero errors from 
having 0 channels or bits.
* could also corrupt memory when selecting samples with long names. from the 
sample selector menu.

Modified Paths:
--------------
    trunk/blender/source/blender/src/buttons_scene.c

Modified: trunk/blender/source/blender/src/buttons_scene.c
===================================================================
--- trunk/blender/source/blender/src/buttons_scene.c    2008-07-14 17:09:47 UTC 
(rev 15569)
+++ trunk/blender/source/blender/src/buttons_scene.c    2008-07-14 17:19:24 UTC 
(rev 15570)
@@ -137,36 +137,42 @@
        bSample *sample, *newsample;
 
        sound = G.buts->lockpoin;
+       
+       /* No Sound or Selected the same sample as we alredy have, just ignore 
*/
+       if (sound==NULL || str==sound->name)
+               return;
+               
+       if (sizeof(sound->sample->name) < strlen(str)) {
+               error("Path too long: %s", str);
+               return;
+       }
+               
+       // save values
+       sample = sound->sample;
+       strcpy(name, sound->sample->name);      
+       strcpy(sound->name, str);
+       sound_set_sample(sound, NULL);
+       sound_initialize_sample(sound);
 
-       if (sound) {
-               // save values
-               sample = sound->sample;
-               strcpy(name, sound->sample->name);
+       if (sound->sample->type == SAMPLE_INVALID) {
+               error("Not a valid sample: %s", str);
 
-               strcpy(sound->name, str);
-               sound_set_sample(sound, NULL);
-               sound_initialize_sample(sound);
+               newsample = sound->sample;
 
-               if (sound->sample->type == SAMPLE_INVALID) {
-                       error("Not a valid sample: %s", str);
+               // restore values
+               strcpy(sound->name, name);
+               sound_set_sample(sound, sample);
 
-                       newsample = sound->sample;
+               // remove invalid sample
 
-                       // restore values
-                       strcpy(sound->name, name);
-                       sound_set_sample(sound, sample);
-
-                       // remove invalid sample
-
-                       sound_free_sample(newsample);
-                       BLI_remlink(samples, newsample);
-                       MEM_freeN(newsample);
-               }
+               sound_free_sample(newsample);
+               BLI_remlink(samples, newsample);
+               MEM_freeN(newsample);
+               return;
        }
-
+       
        BIF_undo_push("Load new audio file");
        allqueue(REDRAWBUTSSCENE, 0);
-
 }
 
 
@@ -403,7 +409,7 @@
                sample = sound->sample;
 
                /* info string */
-               if (sound->sample && sound->sample->len) {
+               if (sound->sample && sound->sample->len && 
sound->sample->channels && sound->sample->bits) {
                        char *tmp;
                        if (sound->sample->channels == 1) tmp= "Mono";
                        else if (sound->sample->channels == 2) tmp= "Stereo";


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to