bufgfix for [#13584] SIGSEV in fluid bake with large amount of small fluid objects
authorCampbell Barton <ideasman42@gmail.com>
Sat, 31 May 2008 19:01:14 +0000 (19:01 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 31 May 2008 19:01:14 +0000 (19:01 +0000)
the maximum number of objects (255) wasnt being checked, added a check before baking.
also changed bakeing to use G.scene->base rather then G.main->objects since these can be in other scenes, from linked
groups, or used only by python so they should not be used for baking. it also meant having a domain in 2 scenes would fail with an error.

Nils, could be good to have a dynamic number of bakeable objects.

source/blender/src/fluidsim.c

index a7361a9ffca35b76c07b5902de74063a30413f21..8b9c89656fb9b7c8bbcaa430313a512ff212d8bf 100644 (file)
@@ -481,6 +481,7 @@ void fluidsimBake(struct Object *ob)
        struct Object *fsDomain = NULL;
        FluidsimSettings *domainSettings;
        struct Object *obit = NULL; /* object iterator */
+       Base *base;
        int origFrame = G.scene->r.cfra;
        char debugStrBuffer[256];
        int dirExist = 0;
@@ -522,7 +523,7 @@ void fluidsimBake(struct Object *ob)
        float *channelObjMove[256][3]; // object movments , 0=trans, 1=rot, 2=scale
        float *channelObjInivel[256];    // initial velocities
        float *channelObjActive[256];    // obj active channel
-
+       
        if(getenv(strEnvName)) {
                int dlevel = atoi(getenv(strEnvName));
                elbeemSetDebugLevel(dlevel);
@@ -545,7 +546,6 @@ void fluidsimBake(struct Object *ob)
 
        /* no object pointer, find in selected ones.. */
        if(!ob) {
-               Base *base;
                for(base=G.scene->base.first; base; base= base->next) {
                        if ( ((base)->flag & SELECT) 
                                        // ignore layer setting for now? && ((base)->lay & G.vd->lay) 
@@ -561,8 +561,26 @@ void fluidsimBake(struct Object *ob)
                if(!ob) return;
        }
 
+       channelObjCount = 0;
+       for(base=G.scene->base.first; base; base= base->next) {
+               obit = base->object;
+               //{ snprintf(debugStrBuffer,256,"DEBUG object name=%s, type=%d ...\n", obit->id.name, obit->type); elbeemDebugOut(debugStrBuffer); } // DEBUG
+               if( (obit->fluidsimFlag & OB_FLUIDSIM_ENABLE) && 
+                               (obit->type==OB_MESH) &&
+                               (obit->fluidsimSettings->type != OB_FLUIDSIM_DOMAIN) &&  // if has to match 3 places! // CHECKMATCH
+                               (obit->fluidsimSettings->type != OB_FLUIDSIM_PARTICLE) ) {
+                       channelObjCount++;
+               }
+       }
+       
+       if (channelObjCount>=255) {
+               pupmenu("Fluidsim Bake Error%t|Cannot bake with more then 256 objects");
+               return;
+       }
+
        /* check if there's another domain... */
-       for(obit= G.main->object.first; obit; obit= obit->id.next) {
+       for(base=G.scene->base.first; base; base= base->next) {
+               obit = base->object;
                if((obit->fluidsimFlag & OB_FLUIDSIM_ENABLE)&&(obit->type==OB_MESH)) {
                        if(obit->fluidsimSettings->type == OB_FLUIDSIM_DOMAIN) {
                                if(obit != ob) {
@@ -605,7 +623,8 @@ void fluidsimBake(struct Object *ob)
        
        // check if theres any fluid
        // abort baking if not...
-       for(obit= G.main->object.first; obit; obit= obit->id.next) {
+       for(base=G.scene->base.first; base; base= base->next) {
+               obit = base->object;
                if( (obit->fluidsimFlag & OB_FLUIDSIM_ENABLE) && 
                                (obit->type==OB_MESH) && (
                          (obit->fluidsimSettings->type == OB_FLUIDSIM_FLUID) ||
@@ -749,7 +768,8 @@ void fluidsimBake(struct Object *ob)
        
        // init obj movement channels
        channelObjCount=0;
-       for(obit= G.main->object.first; obit; obit= obit->id.next) {
+       for(base=G.scene->base.first; base; base= base->next) {
+               obit = base->object;
                //{ snprintf(debugStrBuffer,256,"DEBUG object name=%s, type=%d ...\n", obit->id.name, obit->type); elbeemDebugOut(debugStrBuffer); } // DEBUG
                if( (obit->fluidsimFlag & OB_FLUIDSIM_ENABLE) && 
                                (obit->type==OB_MESH) &&
@@ -952,7 +972,8 @@ void fluidsimBake(struct Object *ob)
                
                // init objects
                channelObjCount = 0;
-               for(obit= G.main->object.first; obit; obit= obit->id.next) {
+               for(base=G.scene->base.first; base; base= base->next) {
+                       obit = base->object;
                        //{ snprintf(debugStrBuffer,256,"DEBUG object name=%s, type=%d ...\n", obit->id.name, obit->type); elbeemDebugOut(debugStrBuffer); } // DEBUG
                        if( (obit->fluidsimFlag & OB_FLUIDSIM_ENABLE) &&  // if has to match 3 places! // CHECKMATCH
                                        (obit->type==OB_MESH) &&