HISE Logo Forum
    • Categories
    • Register
    • Login

    Breaking Change: Calling an API method with undefined throws an error

    Scheduled Pinned Locked Moved Scripting
    1 Posts 1 Posters 553 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.
    • Christoph HartC
      Christoph Hart
      last edited by

      Hi everybody,

      after tracking down some weird bugs which were caused by an implicit cast from undefined to 0 because a ParameterId wasn't spelled correctly (or the object was created after the call silently returning undefined), I decided to not allow passing undefined into any API calls anymore, so from now on you will get an error like this:

      API call with undefined parameter 0
      

      This should not break any existing code, because I don't know any scenario where you would want to pass undefined into an API call, but it prevents you from nasty follow up errors.
      In my case, I was using a reference to a synth before it was actually created so Group.UnisonoVoiceAmount returned undefined which set the gain of the module (= Parameter index 0) to zero effectively muting the output of this module.

      I also added a new function called isDefined(value), which returns false if the value is not defined (or void which is a non-existent key value from an object but practically the same thing). So whenever you hit that error, from now on you can replace the API call with this construct:

      if(isDefined(value)
      {
          Api.someCall(value);
      }
      else
      {
          // handle the undefined value gracefully instead of silently converting it to zero and causing weird stuff.
      }
      
      1 Reply Last reply Reply Quote 1
      • First post
        Last post

      48

      Online

      1.7k

      Users

      11.7k

      Topics

      101.9k

      Posts