On 12/05/2015 at 05:18, xxxxxxxx wrote:
Cinema 4D Version: R16
Platform: Mac OSX ;
Language(s) : C++ ;
I want to call MCOMMAND_CURRENTSTATETOOBJECT when a button is pressed.
I should do this inside Message()'s MSG_DESCRIPTION_COMMAND, I guess, but if I try it my program crashes.
Is this not possible inside Message?
Here is my code:
if (type == MSG_DESCRIPTION_COMMAND)
DescriptionCommand* dc = (DescriptionCommand* )data;
if (dc->id.id == MY_BUTTON)
BaseDocument* doc = static_cast<BaseDocument*>(data);
BaseObject* myObject = doc->GetFirstObject();
cd.doc = doc;
cd.op = myObject;
Thanks in advance for your help and time!
On 12/05/2015 at 06:03, xxxxxxxx wrote:
It is valid and safe. But you cannot simply cast data (which is a DescriptionCommand) into a basedocument coz it does not hold a basedocument pointer.
You should use node->GetDocument() instead (or GetActiveDocument() which should be valid due to a button click most of the time only being triggered interactively..though this is no guarantee so node->GetDocument() is the better alternative).
Also you might need to do this on a copy of the scene.
On 12/05/2015 at 06:22, xxxxxxxx wrote:
If I change that, I get no error, and my program doesn't quit.
The only problem is, it is not making it editable..
On 12/05/2015 at 06:32, xxxxxxxx wrote:
Ignore my previous post
I forgot to cast it and add it to the scene, feeling stupid now yeeeuy
On 12/05/2015 at 07:50, xxxxxxxx wrote:
Katachi is right with his answer.
I sense some problems with the concept of casting datatypes here. It is certainly one of the more advanced concepts of C and C++ and probably one which is cause for many (if not most) bugs. As casts are needed in several places in the C4D SDK, I'd recommend to have a read on this topic.
For example here or here or here. Especially the parts about casting pointers are crucial.
On 13/05/2015 at 08:17, xxxxxxxx wrote:
Thanks for your answer!
I shall definately look more into casting!