diff --git a/src/playsim/p_acs.cpp b/src/playsim/p_acs.cpp index 89aee643d..652dd6141 100644 --- a/src/playsim/p_acs.cpp +++ b/src/playsim/p_acs.cpp @@ -10337,6 +10337,11 @@ scriptwait: } } + // There are several or more p-codes that can trigger a division or modulus of zero. + // Reset the active behavior back to the original if this happens. + if (state == SCRIPT_DivideBy0 || state == SCRIPT_ModulusBy0) + activeBehavior = savedActiveBehavior; + if (runaway != 0 && InModuleScriptNumber >= 0) { auto scriptptr = activeBehavior->GetScriptPtr(InModuleScriptNumber);