Skip to content

fix(core): relocate heliRenderEvent hook from CEntity to CHeli and guard vehicle types - #309

Merged
user-grinch merged 1 commit into
user-grinch:mainfrom
CanerKaraca23:fix/core-heli-render-hook-and-entity-guard
Sep 9, 2026
Merged

fix(core): relocate heliRenderEvent hook from CEntity to CHeli and guard vehicle types#309
user-grinch merged 1 commit into
user-grinch:mainfrom
CanerKaraca23:fix/core-heli-render-hook-and-entity-guard

Conversation

@CanerKaraca23

Copy link
Copy Markdown
Collaborator

Summary

Fixes an Access Violation crash (0xC0000005 at 0x004C5B10 in CModelInfo::IsHeliModel) that occurs in total conversion mods or expanded limit configurations (such as SAxVCxLC) when rendering map objects/buildings with model IDs above 32,767.

Root Cause

  1. In src/utils/meevents.h, heliRenderEvent was hooked at 0x5343B2 (call CEntity::RenderEffects inside CEntity::Render).
  2. CEntity::Render() is the base render routine for all non-vehicle world entities (buildings, objects, roads, and dummies) across the entire map. As a result, every rendered map entity was triggering heliRenderEvent and being passed to the lambda as a CVehicle*.
  3. In src/utils/modelinfomgr.cpp, the callback queried CModelInfo::IsHeliModel(pVeh->m_nModelIndex).
  4. Because CEntity::m_nModelIndex is defined as a signed 16-bit short, any model ID > 32,767 (e.g. 34,569 = 0x8709) sign-extends to a negative integer (-30,967 / 0xFFFF8709).
  5. CModelInfo::IsHeliModel indexed ms_modelInfoPtrs with that negative index, causing an immediate crash.

Changes

  1. Hook Relocation (src/utils/meevents.h):
    • Moved heliRenderEvent from 0x5343B2 to 0x6C4523 (call CEntity::Render at the tail of CHeli::Render).
    • 0x6C4523 is exclusively called for helicopters, eliminating tens of thousands of redundant event firings per frame on map objects and significantly improving rendering performance.
  2. Defensive Entity Guards (src/utils/modelinfomgr.cpp):
    • Added pVeh->m_nType == ENTITY_TYPE_VEHICLE checks to both vehRenderEvent and heliRenderEvent.
    • Cast m_nModelIndex to unsigned uint16_t before calling CModelInfo::IsHeliModel().
    • Added standard 10-frame dummy registration (ModelInfoMgr::FindDummies) for helicopters.

@user-grinch
user-grinch merged commit 08958e0 into user-grinch:main Sep 9, 2026
1 check passed
@CanerKaraca23
CanerKaraca23 deleted the fix/core-heli-render-hook-and-entity-guard branch September 9, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants