Illegal operation in audio thread: Dynamic object access using []. Try object.member instead
-
I have a global object which I use to store persistent data and have it be accessible globally. The data itself is saved into a panel, and "saving persistent data" works by saving data into an object property first, then writing the object itself as value for the panel.
inline function set(stringID, value) { Persistent[stringID] = value; memoryShard.setValue(Persistent); }
I just wanna do this on a keyswitch. I want to store the current keyswitch data so that it's there next time the plugin loads.
However, since that's done in noteOn, I get
Illegal operation in audio thread: Dynamic object access using []. Try object.member instead
.Since I'm doing this with a function provided above, how would I do this with a function?
Using the following
inline function set(stringID, value) { Persistent.stringID = value; memoryShard.setValue(Persistent); }
doesn't work, i.e. I get
Illegal operation in audio thread: Resizing of object.
I assume it tries to add a property literally called stringID because that's not the syntax for dynamic access.I can manually store everything into properties and then call a function to update the memory shard, but I was wondering if I'm missing something obvious here in regards to realtime-safe setting of an object property with a function.
-
@aaronventure Is this in your UI script or a secondary script?
-
Does the
Persistent
object already have a property calledstringID
? If not, just create one in onInit, then you should be fine (otherwise it's a false positive from the AudioThreadGuard. -
@d-healey Secondary, I'm not using the Interface script for realtime
@Christoph-Hart it does, I have
if (Persistent.currentKeyswitch == undefined) GlobalPersistence.set("currentKeyswitch", Config.ksSus);
in on init.Yeah, that's what I had to do for a bunch of other stuff that I was dynamically expanding in rt callbacks after my first encounter with the Audio Thread Guard.
Is there a way to flag a function or something as an exception?
Btw. the simplest solution for my issue here is by far updating the properties directly using object.property and calling updateMemoryShard() at the end of the callback, which just writes the global object into the panel.
-
if (Persistent.currentKeyswitch == undefined) GlobalPersistence.set("currentKeyswitch", Config.ksSus);
so
GlobalPersistence
is a namespace and itsset()
inline function writes the property into thePersistent
global value?small side quest: you can use the builtin
isDefined(Persistent.currentKeyswitch()
instead of the==
operator, I wouldn't trust that it will return true when comparing againstfalse
or zero - the beauty of JS :)Is there a way to flag a function or something as an exception?
I'm doing that with the Console.print() calls (you can have a big party with string allocation and object resizing in there), but I have to specify this on the C++ level.
-
@Christoph-Hart aaah, now I understand and yes this is in fact a legit complaint of the AudioThreadGuard.
// this is a dynamic object property setter, it allocates the string "currentKeyswitch" // (well in this case it doesn't as this string is constructed during script parsing, but the // audio thread guard doesn't know that and has to assume the worst GlobalPersistence.set("currentKeyswitch", Config.ksSus); // This is completely fine as the audio thread guard knows that the property ID is defined // at compile time. Persistent.currentKeyswitch = Config.ksSus;
-
@Christoph-Hart said in Illegal operation in audio thread: Dynamic object access using []. Try object.member instead:
I'm doing that with the Console.print() calls (you can have a big party with string allocation and object resizing in there), but I have to specify this on the C++ level.
Right, I can't just ignore the ATG callout, it won't execute my functions and my instrument won't work (in HISE)
You're correct in the assumptions and yes, I'm familiar with isDefined, I found out about it some time ago and seem to have missed these particular few checks (I just copy pasted my code before doing the changes, didn't think it would trip anyone up but thanks for caring!).