|
Boost Users : |
From: Phill Djonov (phill_at_[hidden])
Date: 2007-04-26 14:35:20
Assuming your issue is related to the OpenMaya API and isn't a general
programming error...
Maya's really good at managing its object lifetimes...you just have to let
it do its job. Some quick rules (a few of which I've learned the hard way
:D):
- Don't store MObject instances across invocations of any of your
plugin's methods - Maya can invalidate these from time to time and using an
invalid MObject is pretty much the same as using a dangling pointer. Check
the OpenMaya docs for more info on when Maya can decide to invalidate an
MObject (I forget what all the cases are).
- When a creator function returns a pointer to an MPx* object to Maya,
that object belongs to Maya. Don't delete it.
- Don't ever store an MPx* pointer you've given to Maya. If one custom
node needs to reference another, create an attribute (like the "message"
attribute Maya uses for light linking) and link them that way:
- If Maya doesn't know that node A references node B it can
delete node B at a whim (or allow the user or some custom script
to delete
it), leaving node A with a dangling pointer. If the connection
were made via
an attribute then node A would find the missing connection next time it
tries to use B and could respond appropriately.
- Also, if node A decides to delete it's pointer to B, then Maya
is left with a dangling pointer which will blow things up nicely
next time
Maya touches that part of the DG.
- Types like MPoint, MVector (etc) are close enough to being POD that
you can do with these pretty much whatever you want. Just be consistent.
Maya will never give you a pointer to one of its internal data arrays so
you're pretty safe when it comes to messing anything up that way.
- M*Array is pretty much equivalent to std::vector. The same rules
apply.
- If you have a bunch of data that you want to pass from one object to
another use a datablock and let Maya pass the data around the DG.
Nodes should never look directly at each other's data (except in
special cases like light/object linking where a "message" type connection
exists to ensure that object is in a valid state before it gets queried),
let Maya pass that info around the DG for you.
My guess is that you're either trying to use an MObject after Maya has
invalidated it (in which case you need to make sure you don't keep MObject
instances around too long - get a new node reference from a representation
that doesn't expire each time you need the object), or you're keeping a
pointer to an MPx* type node and either you or Maya is deleting it
prematurely (in which case you need to replace that pointer with a proper
Maya attribute and connection).
Not really boost/smart pointer issues, but you might want to check to see if
you've got a smart pointer to a smart pointer to something you shouldn't be
managing (or something like that), or if a long-lived container has MObjects
somewhere in its data elements.
Phill
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net