HISE Logo Forum
    • Categories
    • Register
    • Login

    Inline functions sharing iterators

    Scheduled Pinned Locked Moved Scripting
    9 Posts 5 Posters 443 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.
    • d.healeyD
      d.healey
      last edited by d.healey

      If you want to make HISE freeze put this code in your on init callback.

      one();
      
      inline function one()
      {
          for (i = 0; i < 20; i++)
          {
              two();
          }
      }
      
      inline function two()
      {
          for (i = 0; i < 10; i++)
          {
              Console.print(i);
          }
      }
      

      @Christoph-Hart Are iterators supposed to be shared between inline functions? I assume it's some kind of scope issue when one function is called inside the loop of another. Took me a while track this down as the cause of a weird execution time-out I was getting.

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

      ulrikU LindonL ustkU 3 Replies Last reply Reply Quote 2
      • ulrikU
        ulrik @d.healey
        last edited by

        @d-healey are you saying that (i) is leaking between the 2 functions?

        Hise Develop branch
        MacOs 15.3.1, Xcode 16.2
        http://musikboden.se

        1 Reply Last reply Reply Quote 1
        • LindonL
          Lindon @d.healey
          last edited by

          @d-healey yep cant say I've tried this but I have noted ta similar situation -two iterators running at the same time (one inside a timer callback) give "unpredictable" results.

          HISE Development for hire.
          www.channelrobot.com

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

            @d-healey Strange, as Ulrik said it seems to leak... Problem is gone as soon as you replace i in one of the functions...

            Can't help pressing F5 in the forum...

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

              @Lindon There's no timer here.

              The leak is caused by one inline function being called inside the other. Inline functions are syntactic sugar, it basically copies the contents of the function to where the function is invoked.

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

              ustkU ulrikU LindonL 3 Replies Last reply Reply Quote 2
              • ustkU
                ustk @d.healey
                last edited by

                @d-healey This makes sense now ;)

                Can't help pressing F5 in the forum...

                1 Reply Last reply Reply Quote 0
                • ulrikU
                  ulrik @d.healey
                  last edited by

                  @d-healey ahh, ok I see

                  Hise Develop branch
                  MacOs 15.3.1, Xcode 16.2
                  http://musikboden.se

                  1 Reply Last reply Reply Quote 0
                  • LindonL
                    Lindon @d.healey
                    last edited by

                    @d-healey yes I know there is no timer in there... all I'm saying is that if yu use the same index variable in an iterator in a timer and one outside a timer this also "breaks" HISE.

                    HISE Development for hire.
                    www.channelrobot.com

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

                      This is because the i variable is in fact a global variable, because inline functions do not have a scope for default variables.

                      In order to fix it, just create a local variable before using the loop:

                      inline function one()
                      {
                          local i = 0;
                          for (i = 0; i < 20; i++)
                          {
                              two();
                          }
                      }
                      
                      inline function two()
                      {
                          local i = 0;
                          for (i = 0; i < 10; i++)
                          {
                              Console.print(i);
                          }
                      }
                      
                      1 Reply Last reply Reply Quote 5
                      • First post
                        Last post

                      38

                      Online

                      1.8k

                      Users

                      12.1k

                      Topics

                      105.0k

                      Posts