beyond-all-reason / spring

A powerful free cross-platform RTS game engine
https://beyond-all-reason.github.io/spring/
Other
178 stars 95 forks source link

Fix #1523, stack issue with warning spam #1546

Closed sprunk closed 2 weeks ago

sprunk commented 2 weeks ago

UnitCallIn already puts the function on the stack. Fixes #1523

badosu commented 2 weeks ago

@sprunk Can you clarify, maybe pointing out how this is set somewhere else?

sprunk commented 2 weeks ago

All other unit-related callins' implementations consist of passing their name to UnitCallIn(), for example: https://github.com/beyond-all-reason/spring/blob/fd7de2625116007a28eab9af9e06bd0066c92617/rts/Lua/LuaHandle.cpp#L1373-L1377 https://github.com/beyond-all-reason/spring/blob/fd7de2625116007a28eab9af9e06bd0066c92617/rts/Lua/LuaHandle.cpp#L1621-L1625

UnitCallIn pushes the relevant Lua function on top of the Lua stack via GetGlobalFunc: https://github.com/beyond-all-reason/spring/blob/fd7de2625116007a28eab9af9e06bd0066c92617/rts/Lua/LuaHandle.cpp#L968-L976

UnitArrivedAtGoal() differs from all other callins implemented via UnitCallIn in that it manually calls GetGlobalFunc first, which puts a second copy of the Lua function on the Lua stack. https://github.com/beyond-all-reason/spring/blob/fd7de2625116007a28eab9af9e06bd0066c92617/rts/Lua/LuaHandle.cpp#L1852-L1861

This extra copy on the stack does not get cleaned up and is what causes the "stack-top = 1" warning.