On 03/02/2015 at 03:45, xxxxxxxx wrote:
Cinema 4D Version: 13+
Platform: Windows ; Mac ; Mac OSX ;
Language(s) : C++ ;
the docs about GetDescEntry say that the assigned BaseContainer is owned by the caller. This makes me think that I must free the bc memory myself. However, trying to do so will eventually crash C4D.
Am I misunderstanding the docs? How should the retrieved bc be handled?
Thanks in advance
On 03/02/2015 at 09:31, xxxxxxxx wrote:
I investigated the code in question to see what's up with the constant pointer to a pointer of a BaseContainer, which I do find unusual in C4D's SDK. Despite what the docs vaguely imply, you shouldn't do anything but retrieve the pointer and use it to make the appropriate method calls, and let it go out of scope once it's done, meaning you shouldn't delete it. It likely crashes when internal code that expects it to still exist after you've deleted it gets called, and so never reaches the code that actually should delete it.
Long story short, a pointer to a pointer in this case, especially being const, is meant to ensure that if the BaseContainer it points to is changed to another, it can change the first pointer to it while allowing code that uses a pointer to that pointer to still correctly retrieve the new BaseContainer's address. Other than not having to delete it, I'm not sure if it provides any major benefit to you, as re-retrieving the pointer to a pointer each time is probably a good defensive programming habit.
I hope that helps!
SDK Support Engineer
On 03/02/2015 at 10:02, xxxxxxxx wrote:
thanks that clears it up. But the docs should really be fixed concerning ownership. It's really misleading.
On 03/02/2015 at 10:09, xxxxxxxx wrote:
Thanks for confirming your question is answered, I'll close the topic as solved. I already plan on fixing the documents to clear up the misleading wording, thanks for mentioning it anyway.
On 03/02/2015 at 10:45, xxxxxxxx wrote: