[JK2] Fix crash/hang when loading saved games on 64-bit builds #1309
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1278 - OpenJO x64: Crash when loading saved game
Root Cause
The
watchTargetfield (gentity_t*) ingNPC_twas being serialized asint32_tinsg_export()but was not included in thesavefields_gNPCpointer conversion table. This caused:NPC_BSCinematic()callsCalcEntitySpot(NPCInfo->watchTarget, ...)Investigation
Using the crash dump and save file from issue #1278:
EXCEPTION_ACCESS_VIOLATIONat0x426e6fa8CalcEntitySpot(NPCInfo->watchTarget, SPOT_HEAD_LEAN, viewSpot)with a corrupted pointer at line 252 ofNPC_behavior.cpp.Fix
Add the missing
watchTargetentry tosavefields_gNPCincodeJK2/game/g_savegame.cpp:{strNPCOFS(watchTarget), F_GENTITY},This ensures the pointer is properly converted to an entity index when saving and restored to a valid pointer when loading. Also - improve game save parameter validation to return null for invalid entity IDs to maintain save compatibility.
Notes
code/game/g_savegame.cpp) correctly includeswatchTargetin itssavefields_gNPCtable - this was an oversight specific to the JK2 codebase.