@ThomasB said in Thread safety when handling CTrack in TagData.Message() on button click:
I think you misunderstood me. Iām not trying to report a bug here, since the issue isn't with Cinema 4D itself.
No, I did not misunderstood your situation (at least I think so
). We sometimes ask people to report a formal bug report so that we can reproduce an issue. This is not necessarily bound to the bug being in Cinema 4D. Although we often do this when we suspect that the bug is on the Cinema side or at least in a grey area where the plugin does something that is not so great but Cinema also drops the ball in some shape or form.
Your code, at least the one you shared with us, does not do anything wrong. And even though I know you have put a lot of work in your reply here, a lot of text and diagrams do not help in concretely fixing the issue. To answer a few questions anyway:
NodeData::Messageusually runs on the main thread (and you additionally check), so we are fine.- Dialog code also usually runs on the main thread. The only exception can be drawing code (something like
GeUseraArea::DrawMsg), although drawing code usually also runs in a special section of the main thread. Hence my hint to useGeIsMainThreadAndNoDrawThreadinstead ofGeIsMainThreadin my first posting. - Generally there is no guarantee that any code runs on the MT. As an example,
NodeData::Messagecalls are usually on the MT, especially the messageMSG_DESCRIPTION_COMMAND. I.e., when a user clicked a button in your node this should run on the MT as you often want to do GUI things or modify the scene. And Cinema will (should) honor this. But nothing prevents me, Evil Bob the developer, from grabbing your tag, creating a new thread then callingyourTag.Message(MSG_DESCRIPTION_COMMAND, BaseContainer())from this new thread and with that violate the assumption that description commands alwary run on the MT. - Core messages are also usually sent from the MT, both in a dialog and in a
MessageData; soCoreMessagefunctions should usually run on the MT. Core message (i.e., event) evaluation is also decoupled. When you set a (core) event from a non-MT thread (viaSpecialEventAdd), Cinema should properly synchronize and execute the event on the MT. But there could be of course bugs in our code. You should therefore always shield your code withGeIsMainThreadAndNoDrawThreadorGeIsMainThreadif your code could also run in a drawing context.
It is good that you have an eye on the threading safety in Cinema as this is something that often trips developers. But I do not think that threading is here the issue. Threading violations usually lead to crashes, corrupted data, or inexplicable behavior. Slowdowns usually mean that either code runs way more often that you think, e.g. some feedback loop between your tag and dialog, or that there is some resource fighting going on. Playing audio means that hardware resources must be allocated. When they are constantly dropped and reallocated, because something else wants to access them too, this can lead to slowdowns. This is still just a guess into the blue of mine, but it would fit the symptoms you are describing.
Could you please:
- Confirm that the issue also happens for your with the simplified plugin.
- Provide a step by step bug report to reproducing the issue as described here.
- Check that the issue does not happen when you delete your tag (but leave the sound track in the scene). I really want to rule out that Cinema does not have a problem with audio playback on some hardware in general.
When push comes to shove, you can also share your full plugin in private with us via sdk_support(at)maxon(dot)com. When you can reproduce the issue with the simplified plugin, this is of course sufficient for us to investigate the issue. But if you cannot reproduce the issue with the simplified plugin, then we would need to see the full plugin to understand what is going on.
Cheers,
Ferdinand
edit: I now also tried on my Win 11 machine (Intel chipset, a bit beefier GPU). And I cannot detect any slowdowns in normal scene playback or when using the RS render view. However, when I use the Calculate Fps tool (just press SHIFT + C and type 'FPS'), I experience distorted audio and the view port becomes sightly laggy. This happens with and without your tag, an audio track alone seem to be enough.

Cloudflare unfortunately still does interfere with our server cache. You might have to refresh your cache manually to see new data when you read this posting within 24 hours of its release.