GetDescEntry() [SOLVED]
-
On 03/02/2015 at 03:45, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 13+
Platform: Windows ; Mac ; Mac OSX ;
Language(s) : C++ ;---------
Hi,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:
Hi Katachi,
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!
Joey Gaspe
SDK Support Engineer -
On 03/02/2015 at 10:02, xxxxxxxx wrote:
Hi Joey,
thanks that clears it up. But the docs should really be fixed concerning ownership. It's really misleading.
Thanks!
-
On 03/02/2015 at 10:09, xxxxxxxx wrote:
Hi Katachi,
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.
Joey Gaspe
SDK Support Engineer -
On 03/02/2015 at 10:45, xxxxxxxx wrote: