ACF7: Fix possible Lua error spam in intro sequence
authorWuzzy <Wuzzy2@mail.ru>
Fri, 27 Oct 2017 05:03:58 +0200
changeset 12787 389453e1e09e
parent 12786 9892d596693e
child 12788 7849398ec0fa
ACF7: Fix possible Lua error spam in intro sequence This was caused by a race of onGearDelete vs AnimationSetup. If AnimationSetup came first, it uses old values from the natives table. The solution is to force the code to guarantee that AnimationSetup always coms after deleting gears in the natives table.
ChangeLog.txt
share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/queen.lua
--- a/ChangeLog.txt	Fri Oct 27 02:17:39 2017 +0200
+++ b/ChangeLog.txt	Fri Oct 27 05:03:58 2017 +0200
@@ -247,6 +247,7 @@
  * Mission 5: Fix final animation being stuck if cyborg's way to the left is blocked
  * Mission 6: Block off left cave entrance to stop player to just rope all the way around
  * Mission 6: Fix mines not being able to get triggered in first turn
+ * Mission 7: Fix possible Lua error message spam in intro sequence
  * Mission 8: Fix Lua error message at the beginning
  * Mission 10: Fix mission becoming unplayable when all hogs except the traitor died
  * All missions: Add missing texts for translation
--- a/share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/queen.lua	Fri Oct 27 02:17:39 2017 +0200
+++ b/share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/queen.lua	Fri Oct 27 05:03:58 2017 +0200
@@ -100,6 +100,8 @@
 fleeAnim = {}
 finalAnim = {}
 leaderDeadAnim = {}
+
+nativeAwaitingDeletion = nil
 -----------------------------Animations--------------------------------
 function EmitDenseClouds(dir)
   local dif
@@ -648,7 +650,10 @@
     if GetHogName(natives[i]) == GetHogName(enemy) then
       AnimSetGearPosition(enemy, GetGearPosition(natives[i]))
       DeleteGear(natives[i])
+      -- triggers AfterSetupPlace when the gear is *actually* deleted
+      nativeAwaitingDeletion = natives[i]
       DeleteGear(cyborgs[cyborgsLeft])
+      break
     end
   end
 
@@ -762,6 +767,10 @@
 function onGameStart()
   SetupAmmo()
   SetupPlace()
+  -- Animation is setup in AfterSetupPlace
+end
+
+function AfterSetupPlace()
   AnimationSetup()
   SetupEvents()
   AddAnim(startAnim)
@@ -791,6 +800,10 @@
       end
       table.remove(natives, toRemove)
       nativesLeft = nativesLeft - 1
+      if nativeAwaitingDeletion and gear == nativeAwaitingDeletion then
+        AfterSetupPlace()
+        nativeAwaitingDeletion = nil
+      end
     end
   end
 end