Undo question

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

On 04/01/2010 at 15:09, xxxxxxxx wrote:

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

---------
I had previously set up my plugin to remove all connected materials when the object is deleted by using the Free() member function.  THe code that I have in the Free() is ...

  
void Planet::Free(GeListNode* node)  
{  
  
  GePrint("FREE");  
      BaseObject* op = static_cast<BaseTag*>(node)->GetObject();  
      if (!op) goto BYPASS;  
      BaseObject* prnt = op->GetDocument()->GetActiveObject();  
      if (!prnt) goto BYPASS;  
      BaseDocument* doc = op->GetDocument();  
      if (!doc) goto BYPASS;  
        
            
      doc->StartUndo();  
  
  
      //Remove Materials when Object is deleted  
      if (prnt)  
      {  
            
          TextureTag* surfaceTag = (TextureTag* )(prnt->GetDown()->GetFirstTag());  
          if (!surfaceTag) goto BYPASS;  
          TextureTag* lightTag = (TextureTag* )(prnt->GetDown()->GetFirstTag()->GetNext());  
          if (!lightTag) goto BYPASS;  
          TextureTag* cloudTag = (TextureTag* )(prnt->GetDown()->GetNext()->GetFirstTag());  
          if (!cloudTag) goto BYPASS;  
          TextureTag* atmTag = (TextureTag* )(prnt->GetDown()->GetNext()->GetNext()->GetFirstTag());  
          if (!atmTag) goto BYPASS;  
        
          if (prnt->GetDown()->GetNext()->GetNext()->GetNext()->GetNext()->GetDown())  
          {  
              TextureTag* ringTag = (TextureTag* )(prnt->GetDown()->GetNext()->GetNext()->GetNext()->GetNext()->GetDown()->GetFirstTag());  
            
              BaseMaterial* rMat = ringTag->GetMaterial();  
              if (!rMat) goto BYPASS;  
              rMat->Remove();  
              BaseMaterial::Free(rMat);  
          }  
  
          BaseMaterial* sMat = surfaceTag->GetMaterial();  
          if (!sMat) goto BYPASS;  
          sMat->Remove();  
          BaseMaterial::Free(sMat);  
  
          BaseMaterial* lMat = lightTag->GetMaterial();  
          if (!lMat) goto BYPASS;  
          lMat->Remove();  
          BaseMaterial::Free(lMat);  
  
          BaseMaterial* cMat = cloudTag->GetMaterial();  
          if (!cMat) goto BYPASS;  
          cMat->Remove();  
          BaseMaterial::Free(cMat);  
  
          BaseMaterial* aMat = atmTag->GetMaterial();  
          if (!aMat) goto BYPASS;  
          aMat->Remove();  
          BaseMaterial::Free(aMat);  
        
      }  
  
      doc->EndUndo();  
BYPASS:;  
  
}  

However, I have run in to a snag.  This code works great for removing the materials when the object is deleted, however, when the user does an undo, it also calls the Free() and removes all of the materials when it is not suypposed to.  Is there a way to avoid this from happening?  Does anyone have any ideas how I can test to see if the reason the plugin is entering in to the Free() is because of an UNDO .  and if so,  skip over the r emove code?

Thanks in advance.

~Shawn

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

On 05/01/2010 at 01:47, xxxxxxxx wrote:

Free() is called after undoing what?

cheers,
Matthias

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

On 05/01/2010 at 03:11, xxxxxxxx wrote:

anything.  It is called after I undo a rotation .   It's called after I undo anything.

~Shawn

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

On 05/01/2010 at 06:33, xxxxxxxx wrote:

It is not allowed to remove materials from within object generators. This will lead to crashes because of extensive use of threading in Cinema. One thread may still use the material while another is trying to delete it.

In general materials have to be created during the object creation when MSG_MENUPREPARE is called. Material deletion is unfortunatly left to the user ("Remove Unused Materials" command for instance).

cheers,
Matthias

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

On 05/01/2010 at 06:56, xxxxxxxx wrote:

okay.. maybe I'll just remove that option then and solve the problem.  :)

Thanks,

~Shawn