Peter Dimov wrote:
Paul Giaccone wrote:
1. The creator function, required by Maya. Note the absence of a smart pointer. I tried wrapping this in a shared_ptr and returning .get() but this caused a crash, if I remember rightly.
void* MyNode::creator(void) { return new MyNode(); }
This is, I think, exactly as it should be. Maya expects to take ownership of the returned pointer and will delete it when it decides that it's no longer needed. But I'm not an expert on that; you probably need to ask in a Maya SDK forum to be sure.
A bit of research and feedback from HighEnd 3D's Maya API forum suggests that this is the case - you create the node and Maya takes responsibility deleting it when necessary. Apparently, Maya owns the node and deletes it itself when it feels like it, not when the programmer says so. If I've understood correctly, this means that any memory allocated on the heap in MyNode must be done using bare pointers rather than smart pointers, so that Maya can delete it when it wants, not when the smart pointers say the memory can be released. MyNode and any objects that it allocates on the heap still need to have destructors to deallocate their contents, but it is up to Maya when the destructor for MyNode is called. Not an ideal state of affairs (once you've experienced smart pointers, you never want to go back to the inconvenience of having to work out where the all the deletes need to go), but then I've found that Maya is hardly the most programmer-friendly system, IMO.