adrian.licuriceanu Posted August 9, 2022 Posted August 9, 2022 Hello, Had this code (that was leaking memory): Unigine::PropertyPtr property; ... Unigine::PropertyParameterPtr paramRoot = property->getParameterPtr(); const int propertyParamsNo = paramRoot->getNumChildren(); for(int I=0; I<propertyParamsNo; ++I) { auto param = paramRoot->getChild(I); ... } At the above, param, which is PropertyParameterPtr is not an owned pointer even if allocated at each getChild call. Why is that? Basically I have to call param->setOwner(true) at each getChild call, so when it goes out of scope its underlying raw pointer is deleted. This is a very unsafe way to work with smart pointers. Maybe I misunderstood some details, but I thought that non owned pointers are the ones that have data always maintained by the engine internally. Regards, Adrian
alexander Posted August 9, 2022 Posted August 9, 2022 Hi adrian.licuriceanu, Why is that? Yeah, this is a bug. We already fixed it in SDK 2.15 (or 2.15.1, I don't remember, sorry). Best regards, Alexander 1
adrian.licuriceanu Posted August 10, 2022 Author Posted August 10, 2022 Hello, so for now, as an workaround since we are still on Unigine 2.13.0.1, I have setOwner(true) called after each get. But I was wondering if it is better to just cache the pointers too (not just call get each time i need them in the loops)? I know you are using some pooling, but still allocate / deallocate in each block seems expensive. What is your suggestion? Regards, Adrian
alexander Posted August 10, 2022 Posted August 10, 2022 But I was wondering if it is better to just cache the pointers too (not just call get each time i need them in the loops)? Yes, sure. If you can cache pointers, cache them. But don't forget to set setOwner(true) for each new pointer. 1
Recommended Posts