Best way to track down an infinite loop?

0 favourites
  • 5 posts
From the Asset Store
For Adventure, Action, Heroes, Sci-fi and Action-RPG games.
  • I've come across a very hard to reproduce crashbug bug which I've been able to identify as an infinte loop. However my project has a lot of loops, and setting up loopindexes checks for every single one is a huge hassle. Is there any debug command or built in feature that can paste information about which loop is repeating itself excessively? Kind of like what happens when there's stack overflow.

    Thanks

  • There isn’t any debugging feature for that, at least not in construct. The browser’s debugger can let you look at the JavaScript where it’s looping, but that is very abstracted away from events so it probably isn’t very useful. I mean if we wanted to deal with JavaScript and debugging it we’d be using something other than construct.

    Anyways,

    You don’t have to check every loop you have though.

    If you use “while”, then I’d pay attention to that. It’s the only way to create an infinite loop other than with function recursion.

    Just make sure it can exit the loop. If not then as a band aid you could replace the while with a repeat. That way it will just stop instead of looping indefinitely.

    The second thing to look out for isn’t an Infinite loop, but a loop that takes long enough that the browser asks to stop it. It happens with infinite loops too, but I digress.

    Are you looping over big arrays that are increasing in size?

    Do you have a loop that changes the number if iterations based on an expression that sometimes gives a very big number?

    Anyways that’s where I’d look.

    Ideas to mitigate that is to not loop over an entire giant array in one tick but do it in smaller chunks. Like half one frame and the other half the next. Big is the key word here.

  • I'm close to my wits end. I ended up doing loopindex checks and cur x checks for every event in the entire game, and a crash still couldn't produce a debug alert. It clearly shows signs of an infinite loop where the CPU is constantly peaking with nothing happening, yet it doesn't seem to be related to any of my code that can trigger it. Really frustrating. I also know 100 % it's not a stack overflow issue since I don't get the alert.

    At this point I would take any abstract solution as long as it can help me track this down.

  • So it doesn’t seem to be caused by the loops you added to your events. Maybe it’s an infinite loop inside a plugin?

    Rather than shooting in the dark, maybe try to utilize the browsers debugger. I’m really rusty with it but it should be able to show you where it’s looping infinitely.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I struggle figuring it out. If there's a tool that just pastes all javascript running in succession I would love using it. Is that hidden in the debugger somewhere?

    Edit: I feel this is the only way I can track this down. Even when playing the exact same scenario over and over again it can't be reproduced consistently. Some times it takes 90 minutes of play, other times 2. Nothing in the code can theoretically lead to a crash of this nature , and it's happening with game features that I haven't touched for months with no issues. I'm finding more and more reason to suspect this isn't my code's fault, but a problem with Construct. The problem happens with Chrome, NWjs and FireFox, so it's not just an isolated browser issue either.

    Edit 2: Just solved the bug. Took the whole weekend, and the best part is that the solution doesn't even make sense. It definately wasn't related to any loops. I've never been more certain there's a bug in Construct 2.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)