Retrieving custom properties from objects
Posted: Fri Feb 01, 2013 10:24 am
Keys used to map custom properties are memory addresses of objects (b2Body,b2Fixture...etc).
And Box2D uses his own allocation method to be efficient (reuse allocated memory).
If the above is true, then what happens when an objectA (memory 0x01), which has a custom property, gets deleted and, objectB (memory 0x01), which does not have one, is created with the same memory as objectA.
It looks like it is going to give the wrong output if its called.
Possible solutions:
- hash the key
- implementing removeCustomPropertiesForItem(void *item)
- set to default value after use
Maybe the best would be to reset values to default, avoiding multiple creation and deletion of custom property objects. As stated above, Box2D is going to reuse memory anyway.
And Box2D uses his own allocation method to be efficient (reuse allocated memory).
If the above is true, then what happens when an objectA (memory 0x01), which has a custom property, gets deleted and, objectB (memory 0x01), which does not have one, is created with the same memory as objectA.
It looks like it is going to give the wrong output if its called.
Possible solutions:
- hash the key
- implementing removeCustomPropertiesForItem(void *item)
- set to default value after use
Maybe the best would be to reset values to default, avoiding multiple creation and deletion of custom property objects. As stated above, Box2D is going to reuse memory anyway.