[V8i C++] Copying an Edit ElemHandle

I've got two EditElemHandle's (elHandle1 and elHandle2) and each is valid with a complex element. I have just added the contents of elHandle1 to my model, and now I need to "copy" the contents of elHandle2 into elHandle1 (this allows me to NOT regenerate the graphic elements for the next iteration). How is that done? do I:

 

elHandle1.Invalidate();
elHandle1.ReplaceElemDescr( elHandle2.GetElemDescrP() );

 

What happens when I now call elHandle2.Invalidate(); ? Will it corrupt elHandle1 when elHandle2's ElementDescr is freed?

 

Thanks,

 

Bruce

Parents
  • Unknown said:

    elHandle1.Invalidate();
    elHandle1.ReplaceElemDescr( elHandle2.GetElemDescrP() );

    This is incorrect because:

    - ReplaceElemDescr requires that elHandle1 has an existing MSElementDescr to replace (which it won't after the call to Invalidate).
    - ReplaceElemDescr expects that elHandle1 is to take ownership of the MSElementDescr (which it can't because elHandle2 may still own it).

    If elHandle2 doesn't need to remain valid you can do the following:

    MSElementDescrP edP = elHandle2.ExtractElemDescr (); // take ownership of edP from elHandle2
    elHandle1.SetElemDescr (edP, true, false); // pass ownership of edP to elHandle1

    If elHandle2 is to remain valid, you need to copy the descriptor:

    MSElementDescrP edP;
    mdlElmdscr_duplicateSingle (&edP, elHandle2.GetElemDescrCP ()); // make copy of edP from elHandle2
    elHandle1.SetElemDescr (edP, true, false); // pass ownership of edP to elHandle1

    NOTE: There's is a Duplicate method in the next version of the api that will duplicate the MSElementDescr if needed, You can use the assignment operator only for ElemHandle because unlike EditElemHandle these are const so there's no issue with 2 ElemHandle's referring to the same MSElementDescr.

    HTH

    -B

    * I feel like we'd had this discussion before...



Reply
  • Unknown said:

    elHandle1.Invalidate();
    elHandle1.ReplaceElemDescr( elHandle2.GetElemDescrP() );

    This is incorrect because:

    - ReplaceElemDescr requires that elHandle1 has an existing MSElementDescr to replace (which it won't after the call to Invalidate).
    - ReplaceElemDescr expects that elHandle1 is to take ownership of the MSElementDescr (which it can't because elHandle2 may still own it).

    If elHandle2 doesn't need to remain valid you can do the following:

    MSElementDescrP edP = elHandle2.ExtractElemDescr (); // take ownership of edP from elHandle2
    elHandle1.SetElemDescr (edP, true, false); // pass ownership of edP to elHandle1

    If elHandle2 is to remain valid, you need to copy the descriptor:

    MSElementDescrP edP;
    mdlElmdscr_duplicateSingle (&edP, elHandle2.GetElemDescrCP ()); // make copy of edP from elHandle2
    elHandle1.SetElemDescr (edP, true, false); // pass ownership of edP to elHandle1

    NOTE: There's is a Duplicate method in the next version of the api that will duplicate the MSElementDescr if needed, You can use the assignment operator only for ElemHandle because unlike EditElemHandle these are const so there's no issue with 2 ElemHandle's referring to the same MSElementDescr.

    HTH

    -B

    * I feel like we'd had this discussion before...



Children
No Data