From 3a944a8730c4089a38802f32ca4028433e47800f Mon Sep 17 00:00:00 2001 From: codeimp Date: Sat, 28 Aug 2010 16:48:17 +0000 Subject: [PATCH] Fixed a problem that allowed endless recursion when instructed by DECORATE goto statements. --- Source/Core/ZDoom/StateStructure.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Source/Core/ZDoom/StateStructure.cs b/Source/Core/ZDoom/StateStructure.cs index b710b2e5..a8fab9cc 100644 --- a/Source/Core/ZDoom/StateStructure.cs +++ b/Source/Core/ZDoom/StateStructure.cs @@ -160,28 +160,38 @@ namespace CodeImp.DoomBuilder.ZDoom // This finds the first valid sprite and returns it public string GetSprite(int index) + { + List callstack = new List(); + return GetSprite(index, callstack); + } + + // This version of GetSprite uses a callstack to check if it isn't going into an endless loop + private string GetSprite(int index, List prevstates) { // If we have sprite of our own, see if we can return this index if(index < sprites.Count) { return sprites[index]; } + // Otherwise, continue searching where goto tells us to go - else if(gotostate != null) + if(gotostate != null) { // Find the class ActorStructure a = parser.GetArchivedActorByName(gotostate.ClassName); if(a != null) { StateStructure s = a.GetState(gotostate.StateName); - if(s != null) + if((s != null) && !prevstates.Contains(s)) { - return s.GetSprite(gotostate.SpriteOffset); + prevstates.Add(this); + return s.GetSprite(gotostate.SpriteOffset, prevstates); } } } + // If there is no goto keyword used, just give us one of our sprites if we can - else if(sprites.Count > 0) + if(sprites.Count > 0) { // The following behavior should really depend on the flow control keyword (loop or stop) but who cares. return sprites[0];