MergeDocument() crash C4D
-
Hi,
c4d.documents.MergeDocument(doc, path_str,c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS,None)this code,c4d always crashed
-
Hi, @chuanzhen
This code runs fine on my end (Cinema 4D 2026.3.4). Analyzing the cause of the failure may require more detailed information, such as the Cinema 4D version number and the real path (path resolution may occur), and corruption of the path_str file is also one possibility.
Cheers,
Anlv -
@Anlv Hi
Here is a video demonstrating how C4D crashes. For a saved document (or a loaded document), using MergeDocument() is fine, but for a new document that hasn't been saved, using MergeDocument() will definitely crash
2026.3.3 win11
-
Hi, @chuanzhen
I tested the same code as you in both saved projects and unsaved new documents, but no crash occurred. This might be a bug, possibly related to the ObjectData plugin in your project. I can't be certain that's the cause. You could try ruling out the plugin's influence first. But this is beyond my capability, so let's wait for more professional personnel to help.
Cheers,
Anlv -
@Anlv Thanks for your reply.can't reproduce this issue on your side, it seems I need to test it on other computers. It's a puzzling problem
-
Hey @chuanzhen,
we will need both the scene you are merging and merging into to make here any sensible statement. We will also need more than this one sole line of code.
And while a crash always indicates that we could do something better, my hunch would be that that fault lies mostly with some plugin. Because Cinema itself uses heavily
MergeDocumentand if there would be a principal bug with the very common flagsc4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS, we would have found and fixed it before.The first thing that comes to mind with your line of code is that you are off-main thread and then run into problems because you try to let the code run on the MT by passing
Noneforthread. But off-main-thread, merging documents would be a bit unusual (and also illegal if one of the participating documents is a loaded document). You can usec4d.threading.GeGetCurrentThread()to get the current thread and pass it forthread.Another cause could be some
NodeDataplugin which holds data outside of its data container and which does not correctly serialize that extra data (does not implementNodeData::Read,::Write, and::CopyTo) which can then lead to crashes when Cinema tries to run the merged scene with only partially copied node data (assuming the plugin in questions also fails to do sanity/existence checks on its internal extra data).Cheers,
Ferdinand -
@ferdinand Thanks for reply.
I tested a simple C4D file (such as one with only a cube, where the merge command works well).
But I still have a question. If it's a plugin issue ( CopyTo Read Write function is not implemented), then why can the Merge command in C4D merge files normally?(As an aside, I found this issue in one of my plugins (which uses MergeDocument). This plugin was developed in C4D 2024, and the same code worked in older versions but crashes in 2026. Even with the same script code and merge same file, it works normally in 2024 but crashes in 2026)
c4d.documents.MergeDocument(doc, path_str,c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS,c4d.threading.GeGetCurrentThread()) -
@chuanzhen said in MergeDocument() crash C4D:
But I still have a question. If it's a plugin issue ( CopyTo Read Write function is not implemented), then why can the Merge command in C4D merge files normally?
What I meant was this: Imagine you have an
ObjectDatapluginFoowhich has a class instance attribute called_data. Many ofFoo's methods rely on_data, as for exampleGetVirtualObjects,GetDDescription, etc. When you now copy an instance ofFoo, Cinema will copy its data container but not_datawhen you have not implementedCopyTo. On the copied instance ofFoo, the_dataattribute will either not exist at all or be in uninitialized state. Cinema can then for example crash or freeze when you raise anAttributeError(because you try to access a non-existing_data; or any other error) in aGetDDescriptioncall in some corner cases._databeing misaligned with the data container of a node could also lead to all sorts of bugs when your code assumes that they are somehow aligned.In short, Cinema can always read, write, and copy nodes, no matter what you do. But with
CopyToyou can make sure that data outside of the data container of the node (BaseList2D.GetDataInstance) is also correctly copied. The lesson here is that when you have fields such asself._my_dataon a node, and that field cannot be reestablished on the fly, you must implementRead,Write, andCopyTo, so that_my_datacan be written, read, and copied from/to/between scene files. You therefore also usually implement all three of these methods and not just one of them when you need them.Cheers,
Ferdinand -
@ferdinand Thanks for your detailed explanation.
-
(As an aside, I found this issue in one of my plugins (which uses MergeDocument). This plugin was developed in C4D 2024, and the same code worked in older versions but crashes in 2026. Even with the same script code and merge same file, it works normally in 2024 but crashes in 2026)
things can change in the backend of Cinema, without concrete code (the plugin) and example files, I cannot help you much. It could very well be that we added some corner case bug.