This piece of code crash. Can i know why?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 19/06/2006 at 08:33, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   9.1+ 
    Platform:   Windows  ; Mac  ;  Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    Hi all,

    i hope that someone can help me to fix this problem.

    All work like a charm except when i render on viewport on a picture viewer.

    BaseObject *Fast_Fur::GetVirtualObjects(PluginObject *op, HierarchyHelp *hh)
    {
         BaseDocument *doc=op->GetDocument();
         BaseObject *ret = NULL;
         BaseContainer *data=op->GetDataInstance();
         BaseObject *geo=data->GetObjectLink(FAST_FUR_GEOMETRY,doc);
        if     (!geo) return NULL;

    BaseTime tempo          = doc->GetTime();
         Real fps               = doc->GetFps();
         Real frame               = tempo.Get()*fps;

    //PolygonObject* cloned = (PolygonObject* ) (geo->GetClone(NULL,NULL));
         //PolygonObject* cloned = ToPoly(geo->GetClone(COPY_NO_HIERARCHY,NULL));

    PolygonObject* cloned = static_cast<PolygonObject*>( geo->GetClone(COPY_NO_HIERARCHY,NULL) );
         if (!cloned) return NULL;

    Vector* vettore=NULL;
         
         // Get undeformed object
         ModelingCommandData cd;
         cd.doc     = doc;
         cd.op     = cloned;
         if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, cd)) return NULL;
         //PolygonObject* geopoly = static_cast<PolygonObject*>(cd.result->GetIndex(0));
         AutoAlloc<PolygonObject> geopoly(static_cast<PolygonObject*>(cd.result->GetIndex(0)));
         if (!geopoly) return NULL;

    // Getting *Deformed* object at frame - 1
         doc->AnimateObject(geo,BaseTime( (frame-1)/fps ),NULL);
         BaseContainer bc;
         cd.doc = doc;
         cd.op = geo;
         cd.bc=&bc;
         bc.SetBool(MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION,TRUE);
         if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, cd)) return NULL;

    AutoAlloc<PolygonObject> Deformed_Object(static_cast<PolygonObject*>(cd.result->GetIndex(0) ));
         if (!Deformed_Object) return FALSE;
         Matrix Mres=Deformed_Object->GetMg();
         Vector *deformed_padr=Deformed_Object->GetPoint();

    LONG countpoint=Deformed_Object->GetPointCount();
         vettore = (Vector* ) GeAlloc ( sizeof(Vector) * countpoint );

    // store vertex coordinate
         for (LONG i=0; i<countpoint; i++ ) {
              vettore _=deformed_padr _*Mres;
         }

    // Get deformed vertex at current frame
         doc->AnimateObject(geo,BaseTime( frame/fps ),NULL);
         cd.doc = op->GetDocument();
         cd.op = geo;
         cd.bc=&bc;
         bc.SetBool(MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION,TRUE);
         if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, cd)) return NULL;
         
         AutoAlloc<PolygonObject> Deformed_Object2(static_cast<PolygonObject*>(cd.result->GetIndex(0) ));
         if (!Deformed_Object2) return FALSE;
         Matrix Mres2=Deformed_Object2->GetMg();

    Vector *deformed2_padr=Deformed_Object2->GetPoint();

    for (LONG i=0; i<countpoint; i++ ) {
              vettore _=vettore _- deformed2_padr _*Mres2 ;
         }
         
         Real     lod;
         Real     fur_display     = data->GetReal(FAST_FUR_DISPLAY);

    lod=doc->GetLOD() * fur_display;

    if(hh->GetVFlags()==20 ) lod=hh->GetLOD();

    ret = GenerateFast_Fur( op, hh->GetThread(), lod, geopoly, Deformed_Object2, vettore, Mres);
         if (!ret) goto Error;

    ret->SetName(op->GetName());

    PolygonObject::Free(cloned);
         if (vettore) GeFree(vettore);
         return ret;

    Error:
         if (ret) blDelete(ret);
         if (vettore) GeFree(vettore);
         return NULL;
    }



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 19/06/2006 at 08:39, xxxxxxxx wrote:

    I forgot to tell you that i tried to comment:

    ret = GenerateFast_Fur( op, hh->GetThread(), lod, geopoly, Deformed_Object2, vettore, Mres);
         if (!ret) goto Error;
         ret->SetName(op->GetName());

    so c4d crash outside the plugin also without the GenerateFast_Fur call.

    Cheers
    Renato T.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 19/06/2006 at 18:38, xxxxxxxx wrote:

    Sometime when i render it crash here:

    Thanks all :)
    Renato T.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 19/06/2006 at 22:47, xxxxxxxx wrote:

    It is very illegal to call CURRENTSTATETOOBJECT within the cache build (GetVirtualObjects) this will give crashes, if you need to use this you must clone the object (and hierarchy) and put it into its own document, you can not call it in the same document because it affects the cache building. Try removing this first and see if it stops the crashing, this might be your problem and even if it is not it should be removed as it will give crashes.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 20/06/2006 at 00:02, xxxxxxxx wrote:

    Argh!... so where is legal to use CurrentStateToObject?
    This mean that Hair work in this way? I'm just curious :)

    Anyway thanks David, i'll try to make what you suggest.

    Cheers
    Renato T.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 20/06/2006 at 11:20, xxxxxxxx wrote:

    Hello Dear David,

    can you help me to understand how clone an object in a new document?
    I don't find any SDK example about it and some try that i made are not working.

    Thanks in advance
    Renato T.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 20/06/2006 at 11:29, xxxxxxxx wrote:

    David,
    if the 3 object are cloned.. i can call currentstatetoobject without probs and without insert in a new document?

    Cheers
    Renato T.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 21/06/2006 at 09:52, xxxxxxxx wrote:

    CURRENTSTATETOOBJECT is fine when its not used within the cache building (i.e. where GetVirtualObjects is called), calling that function isn't allow there because it uses the caches itself, so can only be used before or afterwards. Hair doesn't work like this and the system I had to use to make it work (without using CURRENTSTATETOOBJECT, see below why) is rather involved.

    As for using that function, it means you must clone your objects into another document and call it on the clones in the new document so that it isn't affecting the currently building cache. This does mean that its slow because not only are you cloning, you are then rebuilding any caches in a new document each time. Unfortunately there is no fast and easy way to handle any of this.

    To clone into a new document just allocate a temporary document (i.e. just for the scope you need it) then clone your objects and insert them into the temp document, then you can safely uses this. You might be able to optimise a little by reusing these if the originals haven't changed, something else that also gets very involved (checking an object and hierarchy match exactly).



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 21/06/2006 at 09:55, xxxxxxxx wrote:

    Thanks david, i was testing this and seem to work with no memory leak and crash :)

    Seem to be a bit slow.. but i'm glad for this :)

    Thanks
    Renato T.

    BaseDocument *copiadoc=doc->Alloc();
         copiadoc->InsertObject(cloned,NULL,NULL,FALSE);

    BaseObject* copiato=copiadoc->GetFirstObject();
         //GePrint(copiato->GetName());

    Vector* vettore=NULL;
         
         // Get undeformed object
         ModelingCommandData cd,cd2,cd3;
         cd.doc     = copiadoc;
         cd.op     = cloned;
         if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, cd)) return NULL;
         //PolygonObject* geopoly = static_cast<PolygonObject*>(cd.result->GetIndex(0));
         AutoAlloc<PolygonObject> geopoly(static_cast<PolygonObject*>(cd.result->GetIndex(0)));
         if (!geopoly) return NULL;

    // Getting *Deformed* object at frame - 1
         doc->AnimateObject(geo,BaseTime( (frame-1)/fps ),NULL);
         PolygonObject* cloned2 = static_cast<PolygonObject*>( geo->GetClone(NULL,NULL) );
         BaseContainer bc;
         cd2.doc = copiadoc;
         cd2.op = cloned2;
         cd2.bc=&bc;
         bc.SetBool(MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION,TRUE);
         if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, cd2)) return NULL;
         //PolygonObject* Deformed_Object = static_cast<PolygonObject*>(cd2.result->GetIndex(0));
         AutoAlloc<PolygonObject> Deformed_Object(static_cast<PolygonObject*>(cd2.result->GetIndex(0) ));
         //GePrint("atom array counter #2 :" + LongToString(cd2.result->GetCount()));

    if (!Deformed_Object) return FALSE;
         Matrix Mres=Deformed_Object->GetMg();
         Vector *deformed_padr=Deformed_Object->GetPoint();

    LONG countpoint=Deformed_Object->GetPointCount();
         vettore = (Vector* ) GeAlloc ( sizeof(Vector) * countpoint );

    // store vertex coordinate
         for (LONG i=0; i<countpoint; i++ ) {
              vettore _=deformed_padr _*Mres;
         }

    // Get deformed vertex at current frame
         doc->AnimateObject(geo,BaseTime( frame/fps ),NULL);
         PolygonObject* cloned3 = static_cast<PolygonObject*>( geo->GetClone(NULL,NULL) );
         cd3.doc = copiadoc;
         cd3.op = cloned3;
         cd3.bc=&bc;
         bc.SetBool(MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION,TRUE);
         if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, cd3)) return NULL;
         //PolygonObject* Deformed_Object2 = static_cast<PolygonObject*>(cd3.result->GetIndex(0));
         AutoAlloc<PolygonObject> Deformed_Object2(static_cast<PolygonObject*>(cd3.result->GetIndex(0) ));

    if (!Deformed_Object2) return FALSE;
         Matrix Mres2=Deformed_Object2->GetMg();

    Vector *deformed2_padr=Deformed_Object2->GetPoint();

    for (LONG i=0; i<countpoint; i++ ) {
              vettore _=vettore _- deformed2_padr _*Mres2 ;
         }
         
         Real     lod;
         Real     fur_display     = data->GetReal(FAST_FUR_DISPLAY);

    lod=doc->GetLOD() * fur_display;

    if(hh->GetVFlags()==20 ) lod=hh->GetLOD();

    ret = GenerateFast_Fur( op, hh->GetThread(), lod, geopoly, Deformed_Object2, vettore, Mres);
         if (!ret) goto Error;

    ret->SetName(op->GetName());

    PolygonObject::Free(cloned);
         PolygonObject::Free(cloned2);
         PolygonObject::Free(cloned3);
    //     PolygonObject::Free(geopoly);
    //     PolygonObject::Free(Deformed_Object);
    //     PolygonObject::Free(Deformed_Object2);



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 23/06/2006 at 13:12, xxxxxxxx wrote:

    Hi David,

    i see that now my plugin is slower than before.. what's about GetCache() and GetDeformCache() on GetVirtualObjects?

    Thanks
    Renato T.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 27/06/2006 at 00:40, xxxxxxxx wrote:

    GetCache() and GetDeformCache() should be fine if they are built I believe. That will however depend on where in the pipeline you are, so you will always need to support the case where the caches are not available.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 27/06/2006 at 01:41, xxxxxxxx wrote:

    Yes, it can easily happen if for exmaple you link a generator that comes after your object in the hierarchy, and was previously turned off. Now it's on, but Cinema hasn't updated it yet, because it goes from top to buttom.

    It can also happen if all viewports show only isoparams, not the real polygon geometry.

    Make sure to check the BIT_CONTROLOBJECT, to find out what objects are hidden because of usage by generators.


Log in to reply