cut frames *after* writing instances, only cut non-define tags
[swftools.git] / src / swfc.c
index c470fbc..ee86802 100644 (file)
@@ -816,7 +816,8 @@ TAG* removeFromTo(TAG*from, TAG*to)
     TAG*save = from->prev;
     while(from!=to) {
        TAG*next = from->next;
-       swf_DeleteTag(from);
+       if(swf_isAllowedSpriteTag(from))
+           swf_DeleteTag(from);
        from = next;
     }
     save->next = 0;
@@ -953,9 +954,6 @@ static void s_endSprite()
 {
     SRECT r = currentrect;
 
-    if(stack[stackpos].cut)
-       tag = removeFromTo(stack[stackpos].cut, tag);
-
     stackpos--;
     instance_t *i;
     stringarray_t* index =dictionary_index(&instances);
@@ -969,6 +967,12 @@ static void s_endSprite()
             writeInstance(i);
        }
     }
+
+    if(stack[stackpos].cut)
+       tag = removeFromTo(stack[stackpos].cut, tag);
+
+    // the writeInstance loop above may have inserted tags after what used yo be the current tag,
+    // so let's make sure 'tag' point to the current tag again.
     while (tag->next)
        tag = tag->next;
 
@@ -1028,6 +1032,11 @@ static void s_endSWF()
     swf = stack[stackpos].swf;
     filename = stack[stackpos].filename;
 
+    // the writeInstance loop above may have inserted tags after what used yo be the current tag,
+    // so let's make sure 'tag' point to the current tag again.
+    while (tag->next)
+       tag = tag->next;
+
     //if(tag->prev && tag->prev->id != ST_SHOWFRAME)
     //    tag = swf_InsertTag(tag, ST_SHOWFRAME);
     tag = swf_InsertTag(tag, ST_SHOWFRAME);