node id. Again
Created by: ly29
For keeping of things track that can't be stored in bpy.props
we use a number of schemes to be able to use as a key for python dicts.
The one we recommended in #116 (closed) was
n_id=hash(node)
Which works well until we undo. Which often will change the value of hash(node)
.
Easiest is to test with view drawer where it leads to abandoned callbacks that aren't disabled. For a node like script node it only leads to a memory leak because it regenerates the script from a bpy.prop if it can't find the key in node_dict
To test create a string prop and test for change.
old_nid = StringProperty(default='',options={'SKIP_SAVE'})
def update(self):
n_id = str(hash(self))
if n_id != self.old_nid:
print(self.name,"node id changed")
self.old_nid=n_id
I think we have to accept that there isn't a stable unique value for a node. Name, label, hash can all change and that we have to keep track of the change for cached data to avoid memory leaks or abandoned callbacks.
Any suggestions for how to do this in a good way?