Announcement

Collapse
No announcement yet.

How to avoid reaching the max loop iteration count?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to avoid reaching the max loop iteration count?

    I'm currently working on a tile based game and the grid of tiles can be 10x10, 20x20 or 30x30. When the user clicks on a tile, I have implemented a flood fill algorithm that will search adjacent tiles for matching criteria and add them to a list. For the 10x10 and the 20x20 grid this works fine without any issues. But when I do 30x30 it crashes with an infinite loop error. I have tried increasing the max loop iteration in Project Settings->Engine->General Settings->Max Loop Iteration Count. It was defaulted at 1,000,000 so I tried 2,000,000, 10,000,000 and 1,000,000,000 but I still keep getting this error on the 30x30 grid.

    I added two images one of where the function is called from and one of the function itself. Does anyone have any suggestions on how to avoid this? Is there another why I can implement this algorithm without running into infinite loop error?
    HunterGaming
    Facebook
    Twitter

    #2
    Maybe could work if you split your loops into several loops for example calculate the loops from 0 to 1000 then add some little delay lets day 0.2 seconds than start the other loop from 1001 to 2000 as an example another thing you can try is to implement a custom for each loop with delay coding in blueprint by yourself

    Comment


      #3
      The loop inside the algorithm at most will loop over 8 tiles at a time. So however many times the PrepareGameTilesToUncover is called recursively, at most GetAdjacentTiles will return 8 tiles to loop over each time. I call PrepareGameTilesToUncover which searches adjacent tiles that match the criteria and add them to GameTilesToUncover. When the algorithm is finished I loop over the GameTilesToUncover and uncover each tile.
      HunterGaming
      Facebook
      Twitter

      Comment


        #4
        I am a little surprised that this is actually breaking the loop limit. I figured it might reach thousands of iterations being there is a loop over a small number of items in a recursive function but millions? What is considered an "iteration"?
        HunterGaming
        Facebook
        Twitter

        Comment


          #5
          Well I figured out the issue. Where I was creating the tiles I have an event dispatcher that is called when the tiles are done loading. I was not calling that when the 30x30 grid was done. Once I added that this err went away. I'm not sure why that missing dispatcher call cause the infinite loop but it did.
          HunterGaming
          Facebook
          Twitter

          Comment

          Working...
          X