Freeing CurrentStateToObject



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

    On 29/07/2005 at 18:01, xxxxxxxx wrote:

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

    ---------
    Hi All,

    i would like to understand how is working the result from ModellingCommand CurrentStateToObject. I assumed that the   atomarray contain only 1 object.

    ModelingCommandData cd;
    cd.doc = doc;
    cd.op = obj_link;

    if(SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT,cd)) {
       exist=TRUE;
       obj_linkb=(BaseObject* ) cd.result->GetIndex(0);
    }

    now.. how i do free this.. and what?

    I need to free the AtomArray, the Atom or the baseobject casted?

    Thanks in advance
    Renato T.
    http://www.tarabella.it/c4d



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

    On 30/07/2005 at 00:01, xxxxxxxx wrote:

    You just need to free the resulting object (just use BaseObject::Free) when you are finished with it. If ever in doubt, just check the debug console for leaks at CINEMA exit.



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

    On 30/07/2005 at 04:34, xxxxxxxx wrote:

    Thanks :)

    Renato T.



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

    On 18/08/2005 at 21:28, xxxxxxxx wrote:

    Hello,

    i'm trying to free the result and it's all ok.. except when i try to render in a viewport, C4D crash.
    No memory leak and no crash when i render in a picture viewer.

    Any help?

    BaseObject* resc=NULL;
    if(SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, cd)) {
         exist=TRUE;
         resc=static_cast<BaseObject*> (cd.result->GetIndex(0));//->GetIndex(0);
            obj_linkb=resc;
         }

    /////////////////////////
    meshdeformer things....

    if (exist) {
        BaseObject::Free(resc);
    }



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

    On 18/08/2005 at 23:18, xxxxxxxx wrote:

    The resulting object is automatically added to the BaseDocument. That means that Cinema 4D owns the object - so don't delete it! Cinema 4D will handle its deletion. If you resc->Remove() (which removes it from the BaseDocument object list), then you own the object and must delete it.



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

    On 18/08/2005 at 23:53, xxxxxxxx wrote:

    Thats wrong, the object is certainly not added to the document. MCOMMAND_CURRENTSTATETOOBJECT returns back the result for you to deal with.
    @Renato: where are you calling this from? Have you tried disabling all your other code and just checking what happens with the SendModelingCommand call? Step through it and see where and why it crashes.



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

    On 19/08/2005 at 02:49, xxxxxxxx wrote:

    That's true, but sounds like it is being added to the document, even if explicitly. Sorry, I didn't check my own call on it - was thinking GetVirtualObject() for some odd reason...



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

    On 19/08/2005 at 06:02, xxxxxxxx wrote:

    David: if i don't free the object i got memory leak. If i free it at and i render on a vieport 3d i got this error:

    First-chance exception at 0x007c2838 in CINEMA 4D.exe: 0xC0000005: Access violation writing location 0xfe255cc4.
    Unhandled exception at 0x007c2838 in CINEMA 4D.exe: 0xC0000005: Access violation writing location 0xfe255cc4.

    I call it in ModifyObject and the error is out of my source so i can't understand where is the error.

    Thanks
    Renato T.



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

    On 19/08/2005 at 06:57, xxxxxxxx wrote:

    My first question, since my goof above, is are you adding the object resulting from SendModelingCommand() to the document? Again, no matter about my goof, Cinema 4D owns the object if you insert it into the document. Free()ing it while inserted would be a good cause for the crash.

    I'm not certain of the dynamics of using SendModelingCommand() within ModifyObject(). Personally, although the docs don't seem to forbid it, it sounds like a tricky prospect. David? :)



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

    On 19/08/2005 at 07:21, xxxxxxxx wrote:

    Robert,
    i don't need to add the object but only i get the current state to work with it.

    I use currentstate to get the real poly from a nurbs generator and it's deformed state.

    Cheers
    Renato T.



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

    On 19/08/2005 at 12:13, xxxxxxxx wrote:

    Two thing you could try.
    First, simplify your code down to just calling the modeling command and see if it still crashes. If it doesn't then start putting back your code until it does. If it does not crash then try inserting the currentstate call into one of the sdk examples (say spherify as that uses modifyobject, replace its code with the modeling command call). This will help locate what is wrong and give more info about the problem.



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

    On 20/08/2005 at 18:00, xxxxxxxx wrote:

    David:

    all is working, CurrentStateToObject is working good.
    When i free the resc i got no memory leak.
    The only prolem is if i render in a 3D viewport.... crash.

    thanks for now
    Renato T.



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

    On 20/08/2005 at 23:46, xxxxxxxx wrote:

    I had a quick mo so I wrote a test and can confirm it causes a crash rendering into the viewport if you have the "Use Render LOD" enabled for the editor. Do you also have this option enabled? does it work if you do not have that enabled? Next chance I get I'll do some investigating.



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

    On 21/08/2005 at 05:48, xxxxxxxx wrote:

    David:

    i don't have "use render lod" enabled and it crash.
    When i enable it the deformer seem to not work but C4D is not crashing...

    Cheers :)
    Renato T.



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

    On 21/08/2005 at 09:17, xxxxxxxx wrote:

    Bad news I'm afraid. Calling the CurrentStateToObject is illegal, this function causes the internal caches to become invalid and since this is happening during the cache build it leads to unpredictable results (i.e. it can crash for any number of reasons).
    The suggested solution is to clone the object+hierarchy that you want a polygon version of and insert it into a dummy document, calling CurrentStateToObject for this. This is not great as it has overheads from the cloning plus will not work with a complex setup (think of dependencies etc.).
    You might (this is just an idea, not tested) be able to use Execute just before the cache is built (GENERATORS-1), if you then call CurrentStateToObject here it is allowed (as you are not within the cache building), you could then store this result (when you need it, maybe you will need your own dirty check to speed it up so you don't call this for every Execute) for use in ModifyObject. This way (if it works) you will not have the hierarchy problem or add much overhead (just your own dirty check).



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

    On 23/08/2005 at 19:40, xxxxxxxx wrote:

    Hi David,

    i'll try.. but i've fear about this :)

    Thanks for now
    Renato T.



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

    On 29/08/2005 at 01:45, xxxxxxxx wrote:

    Hi David,

    this explains why my former experiments also failed.

    But tell me, how does Maxon implement the Instance object. ( perhaps the document trick ?! ) I think it would be very educational for the general public as well.

    It is exactly the same problem as we have to solve. We just don't need to clone the referenced object(s), but instead we use them for a mapping from uv space to the object.

    Meanwhile i've tried to access the caches of the linked objects directly. But this doesn't work because the BIT_CONTROLOBJECT flag is not avaiable if the generator is executed before the referenced objects. So i can't determine what objects i should use.



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

    On 29/08/2005 at 02:20, xxxxxxxx wrote:

    The instance object is not requesting a polygon/deformed version, it just clones the linked object. The only places MAXON have done something similar afaik is in Sky, and that uses the mentioned clone+makeeditable.
    As you mentioned, you can't grab the cache as you are within the building so some may not be available, plus some may be invalid too!



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

    On 29/08/2005 at 06:43, xxxxxxxx wrote:

    Aww.. i see.
    Thanks anyway for your help :) Untill i read your post, i didn't even know about the problem with CurrentstateToObject.

    best regards
    Michael


Log in to reply