Crash when switch Basic Properties Enabled
On 06/04/2016 at 02:50, xxxxxxxx wrote:
Cinema 4D Version: R17
Platform: Windows ;
Language(s) : C++ ;
My plugin is a kind of importer but has a interactive connection with the host, but at the end of the day they are poly objects.
All seems to work ok but if I switch Enabled to Off it works fine, but after that turning it into On c4d crashes and there is no info on debug.
Any tip about where the problem could be or a potential fix?
On 06/04/2016 at 07:38, xxxxxxxx wrote:
Did you run the code in the IDE's debugger so you can see where it's crashing?
Crashes usually happen when the code is trying to access data that isn't there, like trying to access an array element that is outside the index limits, or trying to access a member function of a class pointer that's invalid (NULL).
On 06/04/2016 at 07:58, xxxxxxxx wrote:
Do you save pointers to GeListNode Objects (BaseObjects etc.) persistent in variables? The pointers get invalid when C4D performs stuff like undo or redo. Save it as Link in the BaseContainer.
On 06/04/2016 at 23:53, xxxxxxxx wrote:
Unfortunatly debug is not helping here, it doesn't point to the error.
@Klaus Heyne, sorry I'm newbie to c4d development (I come from autodesk ecosystem) could you explain it a little more?
Thank you for your help to both!
On 07/04/2016 at 02:35, xxxxxxxx wrote:
what do you mean debug isn't helping here? If you are running in the debugger, you should at least get the reason, a more or less precise position of a crash and a callstack. This info may be difficult to interpret due to code optimization or threading issues, but the information should be there and should be a good point to start the investigation.
Also I think, you need to provide us with more details. You say, "kind of importer", is it a SceneLoaderData plugin or something else? And in which function does it crash? What are you doing in this function? Without such information everything is just guess work.
On 07/04/2016 at 07:14, xxxxxxxx wrote:
Originally posted by xxxxxxxx
...Unfortunatly debug is not helping here, it doesn't point to the error...
It may not always point to the error in your code, because your code may be overwriting some other portion of memory that doesn't get accessed until later in Cinema 4D's code.
Can you post a screen shot of the debugger window showing the list of function calls leading up to the crash?
P.S. Sometimes it helps to back off on the compiler optimization.
On 12/04/2016 at 01:09, xxxxxxxx wrote:
It is an object that contains a polyobject inside that is modified when time changes (it reads from a third party connection).
Finally I found the crash point, it was on GetVirtualObject and manage to reproduce it on the minimal example:
MESSAGEBOX(Utils::toQString(op->GetName()).toStdString().c_str(), "step 1 works"); if (m_actual_obj == nullptr || m_actual_obj == NULL) MESSAGEBOX(Utils::toQString(op->GetName()).toStdString().c_str(), "this is not shown never"); m_actual_obj->GetTag(Ttexture, 0);//<<\-----crash! MESSAGEBOX(Utils::toQString(op->GetName()).toStdString().c_str(), "step 2 is not shown after disable->enable");
Thank you in advance for your valuable help!
On 12/04/2016 at 02:03, xxxxxxxx wrote:
this is some strange code... I hope you don't mind, it just doesn't look like the typical code, we usually see here in these forums.
Opening message boxes (I assume you are using some Qt equivalent there) within GetVirtualObjects() is unusual to say the least and certainly doesn't help in debugging. Instead I'd rather recommend to use either C4D's GePrint() to the console or even better breakpoints in your IDE.
if (m_actual_obj == nullptr || m_actual_obj == NULL)
This looks a bit redundant. In the end these are two comparisons with zero.
And finally my guess about the crash reason (note, it's just a guess and as there's a third party library involved, I might be all wrong and not the right person to ask) :
It looks like you are storing a pointer to an object in a member variable (m_actual_obj). This is highly dangerous and your nullptr check doesn't (and can not) do anything about it. The pointer might be stale as C4D might have replaced the object instance with another one located in a completely different memory location. Of course your stored pointer doesn't change in such situation (so your nullptr check won't trigger) and it will point to free'd or differently used memory. If you really need to store an object reference in a member variable, then I'd recommend to use a BaseLink instead.
On 13/04/2016 at 02:25, xxxxxxxx wrote:
Andreas your explanation (..stored pointer doesn't change in such situation (so your nullptr check won't trigger..) has sense, I bet that this is the real problem!
Unfortunatly I'm working on a object that contains a PolygonObject* that has been created from that third party.
I've read the BaseLink documentation but I cannot figure how I could manage this case using that class, by the way disabling that property if possible could be ok too since this object contains 2 different PolyObjects just to make lighter updates.