Skip to content

Commit 785cdf6

Browse files
committed
[JK2] Fix crash/hang when loading saved games on 64-bit builds
Add missing watchTarget pointer field to savefields_gNPC table. The watchTarget field (gentity_t*) in gNPC_t was being serialized as int32_t in sg_export() but was not included in the savefields_gNPC conversion table. This caused: - On save: 64-bit pointer truncated to 32-bit - On load: Truncated value used as invalid pointer - On use: Crash (Windows x64) or infinite loop (macOS ARM64) when NPC_BSCinematic() calls CalcEntitySpot(NPCInfo->watchTarget, ...) The Jedi Academy codebase (code/game/g_savegame.cpp) correctly includes watchTarget in its savefields_gNPC table, but the JK2 codebase was missing this entry. Fixes #1278
1 parent e76263d commit 785cdf6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

codeJK2/game/g_savegame.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ static const field_t savefields_gNPC[] =
106106
{strNPCOFS(defendEnt), F_GENTITY},
107107
{strNPCOFS(greetEnt), F_GENTITY},
108108
{strNPCOFS(group), F_GROUP},
109+
{strNPCOFS(watchTarget), F_GENTITY},
109110

110111
{NULL, 0, F_IGNORE}
111112
};
@@ -233,7 +234,7 @@ intptr_t GetGEntityNum(gentity_t* ent)
233234

234235
gentity_t *GetGEntityPtr(intptr_t iEntNum)
235236
{
236-
if (iEntNum == -1)
237+
if (iEntNum < 0 || iEntNum >= MAX_GENTITIES)
237238
{
238239
return NULL;
239240
}

0 commit comments

Comments
 (0)