Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Function causes a crash

    Bug Reporting (FUZE 4 Nintendo Switch)
    crash bug function
    8
    48
    3321
    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.
    • Hector1945
      Hector1945 F last edited by Hector1945

      Hello !
      So recently I have been working on a recreation of Tennis For Two:

      And I used this function to display the trail of the ball:

      2020080516552600-86FC867622BE2C2315A009D470F52DAE.jpg
      and traillength = 50

      But as soon as I added it to the code, Fuze started crashing. Approximately 20 seconds in the game, Fuze closes and I get the "The software was closed because an error occured" error. This is probably a bug, since Fuze crashing is never a feature. But I have absolutely no idea what causes the bug. It is probably a bit of an error of mine, too. What could I do to get rid of it ?
      Thanks.

      1 Reply Last reply Reply Quote 0
      • D
        DaddyJDM last edited by

        Since that is called in a loop, creating a shape each iteration will eat memory. You can try deleting the shape after it is drawn to clean up.
        Alternatively, you can just draw the line, I think with the ' line ' function?

        Hector1945 1 Reply Last reply Reply Quote 0
        • Hector1945
          Hector1945 F @DaddyJDM last edited by

          @DaddyJDM Well actually, I tested it with the "drawing" part commented, like in the picture, and it didn't change anything...

          1 Reply Last reply Reply Quote 0
          • Jongjungbu
            Jongjungbu F last edited by

            What about that CreateLine() also

            Hector1945 1 Reply Last reply Reply Quote 0
            • Gothon
              Gothon F last edited by

              The negative step loop might be the culprit here. Fuze doesn't do these loops the way you would expect it to.
              Replace:
              for i = len(trail)-1 to -1 step -1 loop
              with
              for i = len(trail)-1 to 0 loop
              and see if that works. I suspect Fuze may have been crashing on reading trail[-1] because the loop doesn't stop at 0 like the positive step loops do. Also the sign of the step is unneeded because Fuze determines the direction from the start and stop values.

              Hector1945 1 Reply Last reply Reply Quote 3
              • D
                DaddyJDM last edited by

                It can be worth trying to replace
                Trail[0]=[{ball.x,ball.y},moving]
                With
                Trail[0][0]={ball.x,ball.y}
                Trail[0][1]=moving

                That might avoid unnecessary creation of arrays through each loop?

                Hector1945 1 Reply Last reply Reply Quote 2
                • Hector1945
                  Hector1945 F @Jongjungbu last edited by

                  @Jongjungbu Fuze still crashes when I don't use it, so pretty sure it only comes from the first part of the function.

                  spikey 1 Reply Last reply Reply Quote 0
                  • Hector1945
                    Hector1945 F @Gothon last edited by

                    @Gothon There is no crash anymore, but if I uncomment the second part of the function, the trail doesn't display anymore, while it used to...

                    Gothon 1 Reply Last reply Reply Quote 0
                    • Hector1945
                      Hector1945 F @DaddyJDM last edited by

                      @DaddyJDM I get an error for attempting to index non array type

                      1 Reply Last reply Reply Quote 0
                      • spikey
                        spikey F @Hector1945 last edited by spikey

                        @Hector1945 wow, the response time is quite fast here 😄 @Gothon +1, @DaddyJDM +1 even go with:

                        trail[0]=[] //the first time
                        trail[0][0]={} //the first time
                        trail[0][0].x=ball.x
                        trail[0][0].y=ball.y
                        
                        Hector1945 1 Reply Last reply Reply Quote 2
                        • Hector1945
                          Hector1945 F @spikey last edited by

                          @spikey Why do I get a "unrecognized type: 4" on the line 79 ?

                          spikey 1 Reply Last reply Reply Quote 0
                          • Gothon
                            Gothon F @Hector1945 last edited by Gothon

                            There is actually another caveat. If len(trail) is 1, the loop will become for i = 0 to 0 flipping to positive direction and not iterate. There are a couple ways of avoiding this problem. You can write a while loop or use

                            for j = 0 to len(trail) loop
                                i = len(trail) - 1 - j
                            

                            Though I notice that your loop uses both trail[i] and trail[i+1], so you probably need to write it as:

                            for j = 0 to len(trail)-1 loop
                                i = len(trail) - 2 - j
                                ...
                            repeat
                            

                            so that it loops len(trail)-2 through 0 since anything outside that range will give you an out of bounds array index.

                            1 Reply Last reply Reply Quote 0
                            • Hector1945
                              Hector1945 F last edited by

                              So I tried replacing

                              for i = len(trail)-1 to -1 step -1 loop
                              

                              with

                              for i = len(trail)-1 to 0 loop
                              

                              and starting the game with 2 values already in the array, and the trail works, but I still get the crash...

                              Gothon 1 Reply Last reply Reply Quote 0
                              • Gothon
                                Gothon F @Hector1945 last edited by Gothon

                                @Hector1945 said in Function causes a crash:

                                but I still get the crash...

                                Right the first value of i is len(trail)-1 = 1 and i+1 = 2 which is out of bounds for an array of size 2 (the valid indices are 0, 1). Since you are writing trail[i+1], you need to start the loop with for i = len(trail)-2 ....

                                Hector1945 1 Reply Last reply Reply Quote 0
                                • PickleCatStars
                                  PickleCatStars F last edited by

                                  I had ’unrecognised type’ error before when accessing an array. Martin said to change the iterator Name to something unique (the ’x’ in ’for x = 0 to..’), and that worked. It was a fuze bug, not something I’d done that time...

                                  1 Reply Last reply Reply Quote 0
                                  • Hector1945
                                    Hector1945 F @Gothon last edited by

                                    @Gothon Wouldn't I get an error if it was out of bounds ? Because the crash only occurs like 20 seconds in the game, way after the array gets completely filled with 50 values...

                                    Gothon 1 Reply Last reply Reply Quote 0
                                    • Gothon
                                      Gothon F @Hector1945 last edited by

                                      @Hector1945 I agree that Fuze should give you an out of bounds error, but when Fuze itself is crashing it is difficult to know what to expect. It can be tricky to trace back to the cause of undefined behaviors.

                                      1 Reply Last reply Reply Quote 0
                                      • Hector1945
                                        Hector1945 F last edited by

                                        If I do the len(trail)-2 it does not crash but the trail doesn't display properly

                                        1 Reply Last reply Reply Quote 0
                                        • Hector1945
                                          Hector1945 F last edited by

                                          Oh ok it just didn't execute the command because len(trail)-2 = 0 if trail has 2 values

                                          1 Reply Last reply Reply Quote 2
                                          • spikey
                                            spikey F @Hector1945 last edited by

                                            @Hector1945 Glad you solved it , the unrecognized type 4 error probably went from adding a value to a not properly initialized array (or reading from a such). (Because of wrong dimension, index). Is it technically a 'void' type? What means its just pointing to a place in memory, but its not clear yet, what the bytes mean there: number, string, array. If somebody knows for sure please comment on this. It would be nice to know for sure.

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