MessageData::CoreMessage vs SceneHook::Message

On 27/01/2017 at 02:49, xxxxxxxx wrote:

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

In order not to derail the question I had asked in another thread, I have created this separate topic.

I have a MessageData plugin which detects changes in a document in its CoreMessage method.
As a result of changes I then perform some calculation. However, it was brought to my attention that intensive operations should not be performed in CoreMessage.
An alternative would then be for the change detection in CoreMessage to send a message to a SceneHook plugin, which would then instead perform the intensive operation in its Message method.

So, is that simply moving the problem to another plugin, or is SceneHook::Message allowed to spend more time on operations?
Or would it be better to let MessageData call a custom SceneHook method instead?


On 30/01/2017 at 02:21, xxxxxxxx wrote:


there's no easy answer on this.

CoreMessage() is always called from the main thread.So, if you do a longer lasting calculation in there, you'll block the main thread (and with it almost completely C4D, at least from the user's point of view).

Message() is called synchronously, so it's running in the thread context of the caller. This could be the thread running the execution pipeline (when Message() is called from e.g. Execute()), or again the main thread. You can already guess, where this is heading, when calling SceneHookData::Message() from MessageData::CoreMessage(), you won't gain anything as you are still in the same (main) thread.

The solution highly depends on your needs and the situation you are in. One idea is to spawn a thread in CoreMessage() let this thread do the calculation and then send another CoreMessage, signalling the end and the result of the calculation. This of course does not work (at least not without further ado), if you want to do this from the GetVirtualObjects() or alike).

So, if you need more information, you'd probably need to provide us with some more details on your use-case.

The Threading Overview/Manuals might also be an interesting read on this topic, as well as the Core Messages Manual and the NodeData::Message() Manual.

On 31/01/2017 at 12:17, xxxxxxxx wrote:

OK, thanks Andreas.
I must confess that I originally assumed that Message() was called asynchronously. I mean by this that I assumed that calling Message() would post a message on a queue which would be handled when time permits. I guess this is how CoreMessage() works, not?

I had provided details in the "How to detect undo?" thread ( but it soon became cluttered with too many questions, failing getting to the point I guess.

So, I'll read your proposed manuals once more.
Spawning a thread would probably be the better solution then.

Thanks again.