Created
January 31, 2025 20:37
-
-
Save kurtdekker/d652416a515dafd2327ab72b7d4a8dc0 to your computer and use it in GitHub Desktop.
Emergency infinite loop breakout code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
// @kurtdekker - dead-simple infinite loop finder | |
// TODO: call BREAKOUT.Check(); from within every suspect loop. | |
// TODO: optionally supply a custom max callcount | |
public class BREAKOUT : MonoBehaviour | |
{ | |
static BREAKOUT _instance; | |
const int MaxCallCount = 100000; | |
static int callCount; | |
public static void Check( int customMaxCallCount = 0) | |
{ | |
if (!_instance) | |
{ | |
_instance = new GameObject("BREAKOUT").AddComponent<BREAKOUT>(); | |
} | |
if (customMaxCallCount == 0) | |
{ | |
customMaxCallCount = MaxCallCount; | |
} | |
callCount++; | |
// we're still good, continue | |
if (callCount < customMaxCallCount) | |
{ | |
return; | |
} | |
// whoops... we're spinning... | |
Debug.Log("Look at the stack, or put a breakpoint here."); | |
throw new System.Exception("Blew a loop check!"); | |
} | |
private void LateUpdate() | |
{ | |
callCount = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment