From 22cc0544af343e7a873b2288df28ac8eac01fb97 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sun, 22 Jul 2012 04:30:07 +0000 Subject: [PATCH] - Fixed: FStateDefinitions::FinishStates() must ResolveGotoLabels before resolving labelled gotos. Otherwise, something like this fails: Goto State1 State1: Goto State2 State2: because when "Goto State1" is processed, State1 is still pointing at the string "State2" rather than State2's state, so the goto will end up pointing at a string (which will soon be freed from memory) instead of at an actual state. SVN r3784 (trunk) --- src/p_states.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/p_states.cpp b/src/p_states.cpp index 739249189..aeff2f5b6 100644 --- a/src/p_states.cpp +++ b/src/p_states.cpp @@ -884,7 +884,6 @@ int FStateDefinitions::FinishStates (FActorInfo *actor, AActor *defaults) { FState *realstates = new FState[count]; int i; - int currange; memcpy(realstates, &StateArray[0], count*sizeof(FState)); actor->OwnedStates = realstates; @@ -892,12 +891,15 @@ int FStateDefinitions::FinishStates (FActorInfo *actor, AActor *defaults) // adjust the state pointers // In the case new states are added these must be adjusted, too! - FixStatePointers (actor, StateLabels); + FixStatePointers(actor, StateLabels); - for(i = currange = 0; i < count; i++) + // Fix state pointers that are gotos + ResolveGotoLabels(actor, defaults, StateLabels); + + for (i = 0; i < count; i++) { // resolve labels and jumps - switch(realstates[i].DefineFlags) + switch (realstates[i].DefineFlags) { case SDF_STOP: // stop realstates[i].NextState = NULL; @@ -916,14 +918,16 @@ int FStateDefinitions::FinishStates (FActorInfo *actor, AActor *defaults) break; case SDF_LABEL: - realstates[i].NextState = ResolveGotoLabel (defaults, actor->Class, (char *)realstates[i].NextState); + realstates[i].NextState = ResolveGotoLabel(defaults, actor->Class, (char *)realstates[i].NextState); break; } } } - - // Fix state pointers that are gotos - ResolveGotoLabels (actor, defaults, StateLabels); + else + { + // Fix state pointers that are gotos + ResolveGotoLabels(actor, defaults, StateLabels); + } return count; }