Skip to content

Commit 2a5ecaf

Browse files
committed
Last-minute fix to issues with async pathing and landing zone causing issues in activities with multiple AI teams
Also hopeful improvement to other pathing issues that've been seen
1 parent 88aab52 commit 2a5ecaf

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Data/Base.rte/Activities/Utility/LandingZoneMap.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ function LandingZoneMap.SearchForLZ(self, team, Destination, digStrenght)
496496
Vector(LZ.X, LZ.Y), Destination, false, digStrenght, team);
497497
end
498498

499-
while pathRequestsCompleted ~= #GoodLZs do
499+
while pathRequestsCompleted < #GoodLZs do
500500
coroutine.yield(); -- wait until all paths are complete
501501
end
502502

Source/Lua/LuaAdapters.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,16 @@ void LuaAdaptersScene::CalculatePathAsync2(Scene* luaSelfObject, const luabind::
295295
// So, luabind::object is a weak reference, holding just a stack and a position in the stack
296296
// This means it's unsafe to store on the C++ side if we do basically anything with the lua state before using it
297297
// As such, we need to store this function somewhere safely within our Lua state for us to access later when we need it
298-
// Note that also, the callbackParam's interpreter is actually different from our Lua state.
299298
// It looks like Luabind constructs temporary interpreters and really doesn't like if you destroy these luabind objects
300299
// In any case, it's extremely unsafe to use! For example capturing the callback by value into the lambdas causes random crashes
301300
// Even if we did literally nothing with it except capture it into a no-op lambda
302-
LuaStateWrapper* luaState = g_LuaMan.GetThreadCurrentLuaState();
301+
// TODO: validate this is still actually the case. Changes to lua may have fixed this
302+
lua_State* luaState = callbackParam.interpreter();
303303
static int currentCallbackId = 0;
304304
int thisCallbackId = currentCallbackId++;
305305
if (luabind::type(callbackParam) == LUA_TFUNCTION && callbackParam.is_valid()) {
306-
luabind::call_function<void>(luaState->GetLuaState(), "_AddAsyncPathCallback", thisCallbackId, callbackParam);
306+
g_ConsoleMan.PrintString(std::to_string(reinterpret_cast<unsigned long long>(luaState)));
307+
luabind::call_function<void>(luaState, "_AddAsyncPathCallback", thisCallbackId, callbackParam);
307308
}
308309

309310
auto callLuaCallback = [luaState, thisCallbackId, movePathToGround](std::shared_ptr<volatile PathRequest> pathRequestVol) {
@@ -316,7 +317,7 @@ void LuaAdaptersScene::CalculatePathAsync2(Scene* luaSelfObject, const luabind::
316317
}
317318
}
318319

319-
luabind::call_function<void>(luaState->GetLuaState(), "_TriggerAsyncPathCallback", thisCallbackId, pathRequest);
320+
luabind::call_function<void>(luaState, "_TriggerAsyncPathCallback", thisCallbackId, pathRequest);
320321
});
321322
};
322323

0 commit comments

Comments
 (0)