HISE Logo Forum
    • Categories
    • Register
    • Login

    Illegal operation in audio thread: Dynamic object access using []. Try object.member instead

    Scheduled Pinned Locked Moved Scripting
    7 Posts 3 Posters 250 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      aaronventure
      last edited by

      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.

      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @aaronventure
        last edited by

        @aaronventure Is this in your UI script or a secondary script?

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        Christoph HartC A 2 Replies Last reply Reply Quote 0
        • Christoph HartC
          Christoph Hart @d.healey
          last edited by

          Does the Persistent object already have a property called stringID? If not, just create one in onInit, then you should be fine (otherwise it's a false positive from the AudioThreadGuard.

          1 Reply Last reply Reply Quote 0
          • A
            aaronventure @d.healey
            last edited by

            @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.

            Christoph HartC 1 Reply Last reply Reply Quote 0
            • Christoph HartC
              Christoph Hart @aaronventure
              last edited by

              if (Persistent.currentKeyswitch == undefined) 
                  GlobalPersistence.set("currentKeyswitch", Config.ksSus);
              

              so GlobalPersistence is a namespace and its set() inline function writes the property into the Persistent 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 against false 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 HartC A 2 Replies Last reply Reply Quote 0
              • Christoph HartC
                Christoph Hart @Christoph Hart
                last edited by

                @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;
                1 Reply Last reply Reply Quote 1
                • A
                  aaronventure @Christoph Hart
                  last edited by

                  @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!).

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post

                  12

                  Online

                  1.8k

                  Users

                  12.0k

                  Topics

                  104.4k

                  Posts