GetVirtualObjects+GetClone+Pointers



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

    On 22/08/2004 at 11:27, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   8.206 
    Platform:      
    Language(s) :     C++  ;

    ---------
    Hi,

    Ive coded up a quite complex ObjectData plugin and after adding a feature it crashes. I know exactly where the crash occurs, but I don't know how to stop it.

    Some background on what is happening with my plugin.

    I create a few clones of a child object of the ObjectData object inside GetVirtualObjects.

      
    BaseObject *oBase = op->GetDown();  
    if(!oBase) return NULL;  
    // The following happens a few times in a loop  
    BaseObject *oClone = (BaseObject* )oBase->GetClone();  
    if(!oClone) return NULL;  
    

    I have a struct that I use to create a Link List. The struct is something like

      
    struct mystruct  
    {  
    LONG ID;  
    BaseObject *oReferenceObject;  
    mystruct *NextNode;  
    }  
    

    The oReferenceObject is pointing to the a clone object that I created earlier by doing this

      
    // If there is already a reference, don't reference it again  
    if(!mystructlist->oReferenceObject)  
    mystructlist->oReferenceObject=oClone;  
    

    Now all this works fine like it should. My problem is what comes next

    in my ObjectData::Draw(...) method, I want to check on some propeties of the clones that I referenced in my LinkList. in Psuedoish Code

      
    ObjectData::Draw(...)  
    {  
    mystruct *node=HeadPointer;  
      
    LOOPTHROUGHLINKLIST  
    {  
        if(node->oRefrenceObject)  
        {  
          // THIS IS *ALWAYS* VALID  
          GePrint(node->oReferenceObject->GetName());  
        }      
      
    }   
    }  
    

    The result of this operation is that the objects name is printed to the console once, then C4D will crash the next time it attempts to print the name. Even though the oReferenceObject is not NULL.

    As you can see, its a quite complicated piece of code, but im guessing it crashes because oReferenceObject is pointing to a invalid pointer due to GetVirtualObjects.

    I'm just a confirmation thats the case



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

    On 22/08/2004 at 12:06, xxxxxxxx wrote:

    You need to create the simplest example of the plugin you can that you can still build and it crashes. Post that project. That is much easier. The small bits of code are very difficult to find fault with.

    darf



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

    On 23/08/2004 at 02:41, xxxxxxxx wrote:

    I guessed small snippets of code would be hard to debug, I was just hoping for the best.

    But I think I know the problem.

    What exactly happens in ObjectData::GetVirtualObjects()?

    Looking at this code

      
    BaseObject *CCrashTest::GetVirtualObjects(PluginObject *op, HierarchyHelp *hh)  
    {  
      
    BaseObject *oBase = op->GetDown();  
    if(!oBase) return NULL;  
      
    BaseObject *oClone = (BaseObject* )oBase->GetClone(NULL,NULL);  
    if(!oBase) return NULL;  
      
    BaseObject *null = BaseObject::Alloc(Onull);  
    if(!null) return NULL;  
      
    // Un-Comment this to avoid crash  
    // m_oReference = NULL;  
      
    // I only want to keep reference the very first clone  
    if(!m_oReference) m_oReference = oClone;  
      
    // Add the referenced object to the null object, crashes here on second iteration of GetVirtualObjects  
    if(m_oReference) m_oReference->InsertUnder(null);  
      
      
    return null;  
    

    What I basically want to do is keep a copy of the first oClone (well it will be several) object to be used throughout my plugin.
    When GetVirtualObjects is called once, it references my member variable to the clone. Thats ok. So now I have a member variable that points to a cloned object.
    But when GetVirtualObjects is called again, a *new* oClone is made by GetClone(). I don't want to use this new one but I do want to use the cloned object that was created before on the first call of GetVirtualObjects. So I simply insert the reference object under the null object. Thats where it crashes.

    As I said, its probably due to oReference pointing to a new address.



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

    On 23/08/2004 at 09:15, xxxxxxxx wrote:

    Does this mean that you solved the problem?



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

    On 23/08/2004 at 14:44, xxxxxxxx wrote:

    Sorry, my problem is not solved



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

    On 29/08/2004 at 08:56, xxxxxxxx wrote:

    Quote: Originally posted by Geespot on 23 August 2004
    >
    > * * *
    >
    > // Add the referenced object to the null object, crashes here on second iteration of GetVirtualObjects
    > if(m_oReference) m_oReference- >InsertUnder(null);
    >
    >
    > * * *

    Looks like you are inserting the same object into multiple hierarchies. My SDK-Versions says in GeListNode::InsertUnder(...) :

    "It is also necessary to use Remove() first if the object is already inserted into another list."

    Does that help?

    Michael


Log in to reply