Undo problem

On 24/06/2014 at 18:00, xxxxxxxx wrote:

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

Let me see if I can explain the situation...

I have a DescriptionToolData plugin that includes a BUTTON in the Attribute Manager.
I check for the user clicking it in the Message method, with:

Bool cPolyPaintTool::Message(BaseDocument* doc, BaseContainer& data, LONG type, void* t_data)   
     BaseObject* obj=doc->GetActiveObject();   
     if (!obj) return TRUE;   
     if (type==MSG_DESCRIPTION_COMMAND)   
          DescriptionCommand *dc = static_cast<DescriptionCommand*>(t_data);             
          LONG button = dc->id[0].id;   
          if (button == MDATA_APPLY_BUTTON)   
               doc->AddUndo(UNDOTYPE_CHANGE, obj);   
     return TRUE;   

Inside the process_object routine I adjust a few parameters inside the BaseContainer of the object. Actually, I just mess up with a BaseContainer that I created inside the object BaseContainer.

If I click the BUTTON it all goes fine. It works perfectly all the time.
But, as soon as I choose Undo, as soon as I click the BUTTON again, it hangs.
If I remove the:

doc->AddUndo(UNDOTYPE_CHANGE, obj);   

It all works perfectly but, of course, I can't go back to the states before the changes made to the object.
Why could it be that a simple Undo can make it all go wrong?

On 24/06/2014 at 19:12, xxxxxxxx wrote:

Putting the button inside an Undo stack seems like a bad idea to me.
Try putting the Undo code inside of your process_object(); method.
That way the button just calls and runs that method. And the button itself won't be recorded in any Undo operation.


On 25/06/2014 at 02:30, xxxxxxxx wrote:

I tried it, Scott, and I still get the same problem.
Anyway, I don't believe the button is being recorded in the Undo operation.
The button is inside the Tool container and the Undo is only recording the state of the object (with its updated container).
I have another DescriptionToolData tool that also updates the same object container through the use of a button. It has Undo working perfectly.
I just don't understand why this one is behaving like this.

On 25/06/2014 at 03:57, xxxxxxxx wrote:

I solved it. It had something to do with the Container. I was storing a reference to the object Container as a private variable and that works fine for the rest of the code of the plugin.
But for this particular task, I have to access a fresh instance of the Container.