c4d crashes when plugin is open

On 04/02/2014 at 11:33, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R15 
Platform:   Windows  ;   
Language(s) :     C++  ;

I have created a command plugin which creates a dialog and some objects.
When I close cinema when the plugin is open, cinema crashes.
It is ok when I close the plugin before closing cinema 4d.

Could it be, because I allocate objects, but never "free" thems?
If so, where and what to free?

Or is main.cpp important? I almost commented out everything.
Note: The plugin works fine.

					BaseObject* sphere = BaseObject::Alloc(Osphere);
					sphere->SetName("Alloc test");
					doc->InsertObject(sphere, nullptr, nullptr);

On 04/02/2014 at 15:22, xxxxxxxx wrote:

In such a case, I comment out everything, then successively add function by function, line by line, until it chrashes again.

On 05/02/2014 at 01:49, xxxxxxxx wrote:

Wouldn't it be easier to step through with the debugger and see exactly where it crashes?


On 05/02/2014 at 03:12, xxxxxxxx wrote:

I do not think I can step through with the debugger, because when closing down cinema 4d, I get a crash message.
Strange enough I do not get it anymore.
I'll try to find out, what changed and took away the crash.

On 05/02/2014 at 03:22, xxxxxxxx wrote:

Once you insert the sphere into a document, it becomes the property of the document.  You do not need to free it yourself (unless you Remove() it from the document and take ownership).

I agree with ingvarai.  Comment all code and uncomment section by section until you hone in on the culprit.  The crash may be caused by something you never considered.

On 05/02/2014 at 04:18, xxxxxxxx wrote:

It only crashes when the plugin is open and the timeline is on/running (Play Forward).
And indeed in the plugin I use frames to animated.
Thanks for all the input.

On 05/02/2014 at 04:29, xxxxxxxx wrote:

Perhaps some more information.
I have a command plugin and in MainDialog::Message I check current frame.
If not equal to previous, I animate some object positions.
I guess this is where it goes wrong.

Int32 MainDialog::Message(const BaseContainer& msg, BaseContainer& result)
	Bool animate, addSphere;
	if (animate)
		Int32 frame, fps;
		BaseDocument* doc = GetActiveDocument();
		fps = doc->GetFps();                               
		frame = doc->GetTime().GetFrame(fps); 
		//GePrint ("Message frame: " + String::IntToString(curframe));
		if (frame != currentFrame)
			currentFrame = frame;

On 05/02/2014 at 04:39, xxxxxxxx wrote:

After GetActiveDocument(), check:

if (!doc) return 0;

As C4D is closing, there may be no active document anymore.

On 05/02/2014 at 06:56, xxxxxxxx wrote:

Originally posted by xxxxxxxx

After GetActiveDocument(), check:

if (!doc) return 0;

As C4D is closing, there may be no active document anymore.

In fact, there is no document anymore, according to my experiences.
In any case, it is a criminal not to check an objects existence, before making it do something. I think we have the cause nailed down!

On 06/02/2014 at 00:37, xxxxxxxx wrote:

Ok, clear and thanks.
Again a lesson learned.

And indeed, that was the issue!