[Released] Panic Button - stop infinite loops in 1 second

Hi everyone!
I’m happy to present my editor extension which I think will be useful to you:

Panic Button
http://u3d.as/hpe

Basically, it solves what you encounter when you accidentally enter an infinite loop during development.
When it happens, the Unity editor is frozen and you cannot do anything - the Stop/Pause buttons are unresponsive as well as the option to save your project or close Unity properly.

When the Panic Button is installed, fortunately all you have to do is to press it (Shift+Escape by default), and the faulty script is aborted, the game is paused, and Unity is immediately responsive again.

It also prints a stack trace in the console, allowing you to locate the infinite loop easily.

So now, when you encounter this problem, all you have to do is to simply press the panic button - that’s all, problem solved instantly.

Watch the video below to see it in action!

This functionality was requested here on the feature requests forum : http://feedback.unity3d.com/suggestions/editor-panic-button-for-infinit

There had to be a better way to handle this issue, so that’s why I created this tool to help you save time while you are coding and debugging.
And I’ve implemented the ideas discussed in the link above, such as:

  • Pausing the game and printing a stack trace

  • Support for game scripts and editor scripts

  • Optional watchdog timer to abort the game after a few seconds of freezing

You can get Panic Button on the Asset Store here.
Price : $10

I hope that you will enjoy it, and I’d be happy to know what you think about it!
Comments, questions, bug reports, or feature requests are welcome - I’m here to help.

Thanks!

1 Like

This has been very handy. Thanks :slight_smile:

You’re welcome. I’m happy to have been helpful.
Please consider leaving a review on the Asset Store if you liked it. :slight_smile:

Update 1.0.2 has been published
It fixes a bug that would sometimes report incorrect line numbers in stack traces.

1 Like

Purchased, but not working. Cleared my game objects properties (fixed by following uninstall instructions). When installed I can’t execute game. Would love for it to work.

PanicButton: Cannot protect file. => E:_Unity\Blockoland\Unity Project\Library\ScriptAssemblies\Assembly-CSharp.dll
Internal exception thrown: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: ‘UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’
at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters parameters) [0x00000] in :0
at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00000] in :0
at Mono.Cecil.DefaultAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00000] in :0
at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00000] in :0
at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00000] in :0
at Mono.Cecil.TypeReference.Resolve () [0x00000] in :0
at Mono.Cecil.Mixin.CheckedResolve (Mono.Cecil.TypeReference self) [0x00000] in :0
at Mono.Cecil.MetadataBuilder.GetConstantType (Mono.Cecil.TypeReference constant_type, System.Object constant) [0x00000] in :0
at Mono.Cecil.MetadataBuilder.AddConstant (IConstantProvider owner, Mono.Cecil.TypeReference type) [0x00000] in :0
at Mono.Cecil.MetadataBuilder.AddField (Mono.Cecil.FieldDefinition field) [0x00000] in :0
at Mono.Cecil.MetadataBuilder.AddFields (Mono.Cecil.TypeDefinition type) [0x00000] in :0
at Mono.Cecil.MetadataBuilder.AddType (Mono.Cecil.TypeDefinition type) [0x00000] in :0
at Mono.Cecil.MetadataBuilder.AddTypeDefs () [0x00000] in :0
at Mono.Cecil.MetadataBuilder.BuildTypes () [0x00000] in :0
at Mono.Cecil.MetadataBuilder.BuildModule () [0x00000] in :0
at Mono.Cecil.MetadataBuilder.BuildMetadata () [0x00000] in :0
at Mono.Cecil.ModuleWriter.b__0 (Mono.Cecil.MetadataBuilder builder, Mono.Cecil.MetadataReader _) [0x00000] in :0
at Mono.Cecil.ModuleDefinition.Read[MetadataBuilder,MetadataBuilder] (Mono.Cecil.MetadataBuilder item, System.Func`3 read) [0x00000] in :0
at Mono.Cecil.ModuleWriter.BuildMetadata (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MetadataBuilder metadata) [0x00000] in :0
at Mono.Cecil.ModuleWriter.WriteModuleTo (Mono.Cecil.ModuleDefinition module, System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) [0x00000] in :0
at Mono.Cecil.ModuleDefinition.Write (System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) [0x00000] in :0
at Dezgo.Panic.Refactory.ProcessAssembly_Procedure (System.String inputFilename, System.Boolean& wasProcessed) [0x00100] in I:\PRO\Dezgo\PRODUCTS\WatchDog\trunk\source\PanicButton_source\Refactoring\Refactory.cs:812
at Dezgo.Panic.Refactory.ProcessAssembly (System.String filename, System.Boolean& wasProcessed) [0x00016] in I:\PRO\Dezgo\PRODUCTS\WatchDog\trunk\source\PanicButton_source\Refactoring\Refactory.cs:664

===
Panic Button version: 1.2.3
0x0000000140E4704D (Unity) StackWalker::GetCurrentCallstack
0x0000000140E48D71 (Unity) StackWalker::ShowCallstack
0x0000000140602A93 (Unity) GetStacktrace
0x00000001405FFE5E (Unity) DebugStringToFile
0x00000001406002BC (Unity) DebugStringToFile
0x0000000140E86EAC (Unity) DebugLogHandler_CUSTOM_Internal_Log
0x000000001D9E05BB (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,string,UnityEngine.Object)
0x000000001D9E04A5 (Mono JIT Code) [DebugLogHandler.cs:10] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[ ])
0x000000001D9E0018 (Mono JIT Code) [Logger.cs:42] UnityEngine.Logger:Log (UnityEngine.LogType,object)
0x000000003BC8E619 (Mono JIT Code) [UnityEngineDebugBindings.gen.cs:121] UnityEngine.Debug:LogError (object)
0x000000003BC8E55D (Mono JIT Code) [Utils.cs:98] Dezgo.Panic.Utils:LogErrorFormat (string,object[ ])
0x000000003BC8E49E (Mono JIT Code) [Utils.cs:120] Dezgo.Panic.Utils:LogError (Dezgo.Panic.Logging,string,object[ ])
0x0000000029E072FC (Mono JIT Code) [Refactory.cs:686] Dezgo.Panic.Refactory:ProcessAssembly (string,bool&)
0x0000000029DEDD8F (Mono JIT Code) [Refactory.cs:244] Dezgo.Panic.Refactory:Refactor (string,PanicSettings)
0x0000000029DEAA4A (Mono JIT Code) [EditorSystem.cs:299] Dezgo.Panic.EditorExt.EditorSystem:LaunchRefactoring (string,bool)
0x000000001DAA2F3A (Mono JIT Code) [EditorSystem.cs:176] Dezgo.Panic.EditorExt.EditorSystem:OnEditorUpdate ()
0x000000001DAA2CC4 (Mono JIT Code) (wrapper delegate-invoke) UnityEditor.EditorApplication/CallbackFunction:invoke_void__this__ ()
0x000000001DAA2C0C (Mono JIT Code) (wrapper delegate-invoke) UnityEditor.EditorApplication/CallbackFunction:invoke_void__this__ ()
0x000000001DAA29FB (Mono JIT Code) [EditorApplicationBindings.gen.cs:222] UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
0x0000000000870A7E (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)
0x00007FF85C2B4FFB (mono) [mini.c:4937] mono_jit_runtime_invoke
0x00007FF85C208341 (mono) [object.c:2623] mono_runtime_invoke
0x000000014033EB25 (Unity) mono_runtime_invoke_profiled
0x00000001404CA1E1 (Unity) CallStaticMonoMethod
0x00000001404CA487 (Unity) CallStaticMonoMethod
0x0000000140BE0700 (Unity) Application::TickTimer
0x0000000140E4179E (Unity) FindMonoBinaryToUse
0x0000000140E42DD1 (Unity) WinMain
0x00000001415C3540 (Unity) strnlen
0x00007FF8BC288364 (KERNEL32) BaseThreadInitThunk

PanicButton: Cannot protect this DLL because the image format is bad, maybe it’s not a .NET assembly?
=> E:_Unity\Blockoland\Unity Project\Library\ScriptAssemblies\Assembly-CSharp-Editor.dll

Internal exception thrown: System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
at Mono.Cecil.PE.ImageReader.ReadImage () [0x00000] in :0
at Mono.Cecil.PE.ImageReader.ReadImageFrom (System.IO.Stream stream) [0x00000] in :0
at Mono.Cecil.ModuleDefinition.ReadModule (System.IO.Stream stream, Mono.Cecil.ReaderParameters parameters) [0x00000] in :0
at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName, Mono.Cecil.ReaderParameters parameters) [0x00000] in :0
at Mono.Cecil.BaseAssemblyResolver.GetAssembly (System.String file, Mono.Cecil.ReaderParameters parameters) [0x00000] in :0
at Mono.Cecil.BaseAssemblyResolver.SearchDirectory (Mono.Cecil.AssemblyNameReference name, IEnumerable1 directories, Mono.Cecil.ReaderParameters parameters) [0x00000] in <filename unknown>:0 at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters parameters) [0x00000] in <filename unknown>:0 at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00000] in <filename unknown>:0 at Mono.Cecil.DefaultAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00000] in <filename unknown>:0 at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00000] in <filename unknown>:0 at Mono.Cecil.TypeReference.Resolve () [0x00000] in <filename unknown>:0 at Mono.Cecil.Mixin.CheckedResolve (Mono.Cecil.TypeReference self) [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.GetConstantType (Mono.Cecil.TypeReference constant_type, System.Object constant) [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.AddConstant (IConstantProvider owner, Mono.Cecil.TypeReference type) [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.AddParameter (UInt16 sequence, Mono.Cecil.ParameterDefinition parameter, Mono.Cecil.ParamTable table) [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.AddParameters (Mono.Cecil.MethodDefinition method) [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.AddMethod (Mono.Cecil.MethodDefinition method) [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.AddMethods (Mono.Cecil.TypeDefinition type) [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.AddType (Mono.Cecil.TypeDefinition type) [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.AddTypeDefs () [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.BuildTypes () [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.BuildModule () [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.BuildMetadata () [0x00000] in <filename unknown>:0 at Mono.Cecil.ModuleWriter.<BuildMetadata>b__0 (Mono.Cecil.MetadataBuilder builder, Mono.Cecil.MetadataReader _) [0x00000] in <filename unknown>:0 at Mono.Cecil.ModuleDefinition.Read[MetadataBuilder,MetadataBuilder] (Mono.Cecil.MetadataBuilder item, System.Func3 read) [0x00000] in :0
at Mono.Cecil.ModuleWriter.BuildMetadata (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MetadataBuilder metadata) [0x00000] in :0
at Mono.Cecil.ModuleWriter.WriteModuleTo (Mono.Cecil.ModuleDefinition module, System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) [0x00000] in :0
at Mono.Cecil.ModuleDefinition.Write (System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) [0x00000] in :0
at Dezgo.Panic.Refactory.ProcessAssembly_Procedure (System.String inputFilename, System.Boolean& wasProcessed) [0x00100] in I:\PRO\Dezgo\PRODUCTS\WatchDog\trunk\source\PanicButton_source\Refactoring\Refactory.cs:812
at Dezgo.Panic.Refactory.ProcessAssembly (System.String filename, System.Boolean& wasProcessed) [0x00016] in I:\PRO\Dezgo\PRODUCTS\WatchDog\trunk\source\PanicButton_source\Refactoring\Refactory.cs:664

===
Panic Button version: 1.2.3
0x0000000140E4704D (Unity) StackWalker::GetCurrentCallstack
0x0000000140E48D71 (Unity) StackWalker::ShowCallstack
0x0000000140602A93 (Unity) GetStacktrace
0x00000001405FFE5E (Unity) DebugStringToFile
0x00000001406002BC (Unity) DebugStringToFile
0x0000000140E86EAC (Unity) DebugLogHandler_CUSTOM_Internal_Log
0x000000001D9E05BB (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,string,UnityEngine.Object)
0x000000001D9E04A5 (Mono JIT Code) [DebugLogHandler.cs:10] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[ ])
0x000000001D9E0018 (Mono JIT Code) [Logger.cs:42] UnityEngine.Logger:Log (UnityEngine.LogType,object)
0x000000003DBE47EC (Mono JIT Code) [UnityEngineDebugBindings.gen.cs:165] UnityEngine.Debug:LogWarning (object)
0x000000003DBE472D (Mono JIT Code) [Utils.cs:93] Dezgo.Panic.Utils:LogWarningFormat (string,object[ ])
0x000000003DBE466E (Mono JIT Code) [Utils.cs:114] Dezgo.Panic.Utils:LogWarning (Dezgo.Panic.Logging,string,object[ ])
0x0000000029E06FC3 (Mono JIT Code) [Refactory.cs:671] Dezgo.Panic.Refactory:ProcessAssembly (string,bool&)
0x0000000029DEDD8F (Mono JIT Code) [Refactory.cs:244] Dezgo.Panic.Refactory:Refactor (string,PanicSettings)
0x0000000029DEAA4A (Mono JIT Code) [EditorSystem.cs:299] Dezgo.Panic.EditorExt.EditorSystem:LaunchRefactoring (string,bool)
0x000000001DAA2F3A (Mono JIT Code) [EditorSystem.cs:176] Dezgo.Panic.EditorExt.EditorSystem:OnEditorUpdate ()
0x000000001DAA2CC4 (Mono JIT Code) (wrapper delegate-invoke) UnityEditor.EditorApplication/CallbackFunction:invoke_void__this__ ()
0x000000001DAA2C0C (Mono JIT Code) (wrapper delegate-invoke) UnityEditor.EditorApplication/CallbackFunction:invoke_void__this__ ()
0x000000001DAA29FB (Mono JIT Code) [EditorApplicationBindings.gen.cs:222] UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
0x0000000000870A7E (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)
0x00007FF85C2B4FFB (mono) [mini.c:4937] mono_jit_runtime_invoke
0x00007FF85C208341 (mono) [object.c:2623] mono_runtime_invoke
0x000000014033EB25 (Unity) mono_runtime_invoke_profiled
0x00000001404CA1E1 (Unity) CallStaticMonoMethod
0x00000001404CA487 (Unity) CallStaticMonoMethod
0x0000000140BE0700 (Unity) Application::TickTimer
0x0000000140E4179E (Unity) FindMonoBinaryToUse
0x0000000140E42DD1 (Unity) WinMain
0x00000001415C3540 (Unity) strnlen
0x00007FF8BC288364 (KERNEL32) BaseThreadInitThunk

error CS0009: file Library/ScriptAssemblies/Assembly-CSharp.dll' has invalid assembly’ metadata

Compilation failed: 1 error(s), 0 warnings
0x0000000140E4704D (Unity) StackWalker::GetCurrentCallstack
0x0000000140E48D71 (Unity) StackWalker::ShowCallstack
0x0000000140602A93 (Unity) GetStacktrace
0x00000001405FFE5E (Unity) DebugStringToFile
0x00000001406002BC (Unity) DebugStringToFile
0x000000014075BEE8 (Unity) std::_Tree<std::_Tset_traits<std::basic_string<char,std::char_traits,stl_allocator<char,66,16> >,std::less<std::basic_string<char,std::char_traits,stl_allocator<char,66,16> > >,std::allocator<std::basic_string<char,std::char_traits,stl_allocator<char,66,16> > >,0> >::_Copy
0x000000014075C04D (Unity) std::_Tree<std::_Tset_traits<std::basic_string<char,std::char_traits,stl_allocator<char,66,16> >,std::less<std::basic_string<char,std::char_traits,stl_allocator<char,66,16> > >,std::allocator<std::basic_string<char,std::char_traits,stl_allocator<char,66,16> > >,0> >::_Copy
0x000000014076759F (Unity) GetAllManagedMonoIslands
0x0000000140796F37 (Unity) UpdateMonoCompileTasks
0x0000000140756B8B (Unity) UpdateMonoCompileTasks
0x0000000140BE03A5 (Unity) Application::TickTimer
0x0000000140E4179E (Unity) FindMonoBinaryToUse
0x0000000140E42DD1 (Unity) WinMain
0x00000001415C3540 (Unity) strnlen
0x00007FF8BC288364 (KERNEL32) BaseThreadInitThunk

Hi!
Thanks for reporting the problem.

Does it work with an empty project? Or is it failing just for your project?

I have the same error. Did not repro on an empty project.

Thanks a lot for notifying me about this problem!
I’m aware of a few edge cases causing issues with the plugin and I’m currently working on an update to fix those.

It was this some script in this asset package that caused it for me: Unity Asset Store - The Best Assets for Game Making

Hello.

Hello. I bought this asset not long ago. It seems to have problems with an other free asset that I have, called Isolationist.
This asset has no Dlls, but it registers itself on some of Unity’s callbacks, like PlayModeStateChange.
Any ideas on how to fix it?

What is correct procedure to uninstall PanicButton? I have removed the folder but somehow references are lingering?

Hi there! Do you have any plans to make it compatible with unity 2019?

1 Like

This will not get updated anymore, so I made my own. Its called Emergency Exit and I have a unity forum post and its on the assetstore.