Fix improved hostages AI freezing after map change when bots are disabled#1162
Open
belomaxorka wants to merge 1 commit into
Open
Fix improved hostages AI freezing after map change when bots are disabled#1162belomaxorka wants to merge 1 commit into
belomaxorka wants to merge 1 commit into
Conversation
…bled When hostage_ai_enable is set in CS 1.6 but bots are not allowed (dedicated server without bot_enable), CCSBotManager::LoadNavigationMap returns early and never frees the navigation mesh of the previous map. LoadNavigationMap() then sees a non-empty TheNavAreaList and keeps the stale nav data, so on the next hostage map CHostageImprov is created against the wrong navigation mesh: hostages freeze and stop responding to +use. Destroy the stale navigation data in CHostageManager::ServerActivate before loading, but only when bots are not allowed - otherwise CCSBotManager has already reloaded the nav mesh earlier in the same ServerActivate and holds pointers into it. Fixes rehlds#1161 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
e35fd6c to
2fddd8c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #1161
Bug
With
hostage_ai_enable 1on a CS 1.6 server, the improved (CZ) hostages work fine on the first loaded map, but after any map change they completely freeze and stop responding to+use.Root cause
LoadNavigationMap()(game_shared/bot/nav_file.cpp) returns early ifTheNavAreaListis not empty, relying on the assumption that "the navigation map is destroyed on map change":However, the only place that actually destroys it on map change is
CCSBotManager::LoadNavigationMap(), and it returns early when bots are not allowed (e.g. a dedicated CS 1.6 server withoutbot_enable 1):So with bots disabled the sequence is:
cs_office):TheNavAreaListis empty, the nav mesh loads correctly, CZ hostage AI works.map cs_italy: nobody destroys the old nav data.CHostageManager::ServerActivate()callsLoadNavigationMap(), which sees a non-empty list and silently keeps the mesh of the previous map.CHostage::IdleThink()still createsCHostageImprov(the list is not empty), but the improv cannot find any valid nav area beneath the hostage on the new map. The hostage freezes;+useis actually received, but the follow behavior cannot move without navigation.This never reproduces in Condition Zero, because bots are always allowed there and the bot manager destroys and reloads the mesh on every map — which is exactly why only CS 1.6 with
hostage_ai_enableis affected.Fix
Destroy the stale navigation data in
CHostageManager::ServerActivate()right before loading, but only when bots are not allowed. When bots are allowed,CCSBotManager::ServerActivate()has already destroyed and reloaded the mesh earlier in the same engineServerActivate()call (see the order inclient.cpp) and holds pointers into the fresh mesh (scenario zones), so it must not be destroyed again.Both code paths are gated by the same
AreBotsAllowed()flag (g_bAllowedCSBot, snapshotted once inRegamedll_Game_Init()aftergame_init.cfgis executed), so exactly one subsystem owns nav destruction for the entire server lifetime — no double-destroy and no ownerless state in any configuration.Safety notes
ServerActivatebefore the first game frame: no bots exist (they are disallowed on this path), hostage improvs are not created yet (m_improvis only created inIdleThink), andCHostageManageris recreated per map withm_hostageCountalready reset.DestroyNavigationMap()also resetsTheNavAreaGridand the nav-edit statics (EditNavAreasReset()clearsmarkedArea/lastSelectedArea); the A* open-list static is cleared byClearSearchLists()at the start of every path search, so no stale pointer is ever dereferenced.LoadNavigationMap()call already does this internally).REGAMEDLL_ADDbuilds and servers with bots enabled are bit-for-bit unaffected..navfile,TheNavAreaListnow correctly stays empty and hostages fall back to the classic CS 1.6 AI instead of freezing on the previous map's mesh.Verified on a live server
Reproduced and verified on a dedicated ReHLDS server (Windows), CS 1.6,
hostage_ai_enable "1", bots disabled, scenariocs_office→map cs_italy:+use, but never move — the follow behavior cannot path on the stale mesh. Enabling bots (bot_enable 1) makes the same build work across map changes, confirming that the bot manager's nav reload is exactly what masks the bug.+useand follow normally after any number of map changes. A debug-instrumented build confirmed the expected internals on the second map: nav statusNAV_OKwith the correct area count after reload, hostages standing on valid nav areas, and successful path construction (noNavAreaBuildPathfailures).Notes for testers
.navfiles must be generated for the CS 1.6 map geometry (e.g. the zBot nav files). Nav files taken from CZ for maps that were remade in CZ (such ascs_assault) do not match the 1.6 geometry — hostages then cannot path on any map load, regardless of this fix.models/hostageA.mdl...hostageD.mdl) must be present on the server, otherwisehostage_ai_enablesilently resets to0at hostage precache and the classic (non-CZ) hostages are used.How to test
hostage_ai_enable "1"ingame_init.cfg, bots disabled (nobot_enable 1).cs_office— CZ hostages work (animations, pathfinding,+use).map cs_italy— before the fix the hostages freeze and ignore+use; with the fix they respond and follow normally. Repeated map changes (including back tocs_office) keep working.