Skip to content

Commit

Permalink
Quick work arround for recursive state setting
Browse files Browse the repository at this point in the history
  • Loading branch information
jval1972 committed May 5, 2022
1 parent 458fd21 commit ffb73ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions Doom/p_mobj.pas
Expand Up @@ -287,6 +287,10 @@ implementation
const
MOBJ_CYCLE_LIMIT = 1000000;

var
prev_states: TDNumberList;
recursion_level: integer = 0;

//==============================================================================
// P_DoSetMobjState
//
Expand All @@ -300,7 +304,15 @@ function P_DoSetMobjState(mobj: Pmobj_t; state: statenum_t; const runthinker: bo
cycle_counter: integer;
begin
cycle_counter := 0;
result := true;
if recursion_level = 0 then
prev_states := TDNumberList.Create;
Inc(recursion_level);
repeat
if prev_states.IndexOf(Ord(state)) > 0 then
Break;
prev_states.Add(Ord(state));

if state = S_NULL then
begin
if mobj.flags_ex and MF_EX_DONOTREMOVE = 0 then // JVAL Do not remove missile
Expand All @@ -309,7 +321,7 @@ function P_DoSetMobjState(mobj: Pmobj_t; state: statenum_t; const runthinker: bo
P_RemoveMobj(mobj);
end;
result := false;
exit;
break;
end;

if mobj.validcount <> validcount then
Expand All @@ -329,6 +341,7 @@ function P_DoSetMobjState(mobj: Pmobj_t; state: statenum_t; const runthinker: bo
// Call action functions when the state is set
if Assigned(st.action.acp1) and runthinker then
begin

if st.params <> nil then
st.params.Actor := mobj;
st.action.acp2(mobj, nil);
Expand All @@ -340,8 +353,9 @@ function P_DoSetMobjState(mobj: Pmobj_t; state: statenum_t; const runthinker: bo
if cycle_counter > MOBJ_CYCLE_LIMIT then
I_Error('P_SetMobjState(): Infinite state cycle detected in object "%s"!', [Info_GetMobjName(mobj.info)]);
until mobj.tics <> 0;

result := true;
Dec(recursion_level);
if recursion_level = 0 then
prev_states.Free;
end;

//==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion Doom32.dof
Expand Up @@ -100,7 +100,7 @@ Conditionals=DOOM;OPTIMIZE_FOR_SPEED;
DebugSourceDirs=.\Base\;F:\DelphiDoom_Release\DelphiDoom_Src\Src\Doom\
UsePackages=0
[Parameters]
RunParams=-iwad doomu.wad
RunParams=-iwad doom2.wad NineCircles_1.0.wad
HostApplication=
Launcher=
UseLauncher=0
Expand Down

0 comments on commit ffb73ee

Please sign in to comment.