spelunky-fyi / overlunky

An overlay for Spelunky 2 to help you with modding, exploring the depths of the game and practicing with tools like spawning arbitrary items, warping to levels and teleporting.
MIT License
86 stars 32 forks source link

Infinite loop detection false positives while paused #347

Closed Cosine256 closed 1 year ago

Cosine256 commented 1 year ago

The Lua infinite loop detection depends on state.time_startup incrementing, but that field is not incremented in certain circumstances. Notably, it doesn't increment when state.pause is PAUSE.FADE, which is one of the better options for OL frame advance, and the user may spend a long time on a single frame in that pause state. This will periodically trigger infinite loop detection false positives depending on how much ON.GUIFRAME activity is occurring on every frame, interrupting and potentially breaking whatever code was running at the time.

In some scripts I use with a lot of window code, a false positive gets triggered every couple minutes. The excessive script below can be put in the console and will trigger it every couple seconds.

set_callback(function()
  for _ = 1, 10000000 do end
end, ON.GUIFRAME)
Hit Infinite Loop Detection of 1bln instructions

It's also configured for 500,000,000 instructions, even though the message says "1bln". Last checked on OL build 16f752a.

Dregu commented 1 year ago

Oh right that detection was probably made out of laziness when the default, only pause type was on a different flag that didn't stop the global frame counters. Keeping the same kind of logic but moving the counter to the render loop will probably fix this, unless the cause is simply doing a ton of stuff that will freeze the rendering for multiple seconds, and I can add a function to disable the check manually if you really know what you're doing and need all that compute time.