Skip to content

Fix getElementBoundingBox/radius for engineRequestModel custom models (#4925)#5003

Open
QueryOfficial wants to merge 1 commit into
multitheftauto:masterfrom
QueryOfficial:fix/custom-model-element-bounds
Open

Fix getElementBoundingBox/radius for engineRequestModel custom models (#4925)#5003
QueryOfficial wants to merge 1 commit into
multitheftauto:masterfrom
QueryOfficial:fix/custom-model-element-bounds

Conversation

@QueryOfficial

Copy link
Copy Markdown

Summary

Fix getElementRadius and getElementBoundingBox for custom models created with engineRequestModel.

Custom model slots no longer share the parent model’s pColModel bounds data. After a successful DFF replace, bounds are recalculated from RenderWare atomic geometry. Visual bounds recalculation is skipped when a custom COL is applied via engineReplaceCOL.

Changes are in:

  • Client/game_sa/CModelInfoSA.h
  • Client/game_sa/CModelInfoSA.cpp

Motivation

Fixes #4925.

Custom models created with engineRequestModel always returned the parent model’s radius and bounding box. For object models with the default parent 1337 (trash can), scripts consistently saw the same radius and bounding box values regardless of the replaced DFF.

Root cause:

  • Make*Model shallow-copied the parent CBaseModelInfoSAInterface, so the custom slot shared the parent’s pColModel
  • engineReplaceModel only replaced visual geometry and did not update bounds
  • getElementRadius / getElementBoundingBox read stale/shared collision bounds via CModelInfo::GetBoundingBox()

Test plan

  1. Request a custom object model with engineRequestModel("object"), replace the DFF, create an object, and verify getElementRadius / getElementBoundingBox differ from parent 1337 values.
  2. Repeat with an explicit parent ID (e.g. engineRequestModel("object", 1225)) and confirm returned bounds match the custom DFF, not the parent.
  3. Test with custom vehicle and ped models.
  4. Apply engineReplaceCOL, verify bounds come from the COL, and confirm a later DFF replace does not overwrite them.
  5. Verify parent model 1337 bounds are unchanged after a custom model replace.
  6. Confirm engineFreeModel does not crash or leak.
  7. Replace the DFF before the model is streamed in, then verify bounds are updated after load via MakeCustomModel.

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

- Introduced functions to create and destroy owned collision model copies, ensuring collision geometry is not shared.
- Implemented bounds accumulation from RenderWare objects to update collision model bounds accurately.
- Enhanced model creation methods to clone parent collision models, ensuring proper collision data handling.
- Added necessary member variables and updated existing methods to integrate new functionality.

This change improves collision handling and model integrity during runtime, addressing potential issues with shared collision data.
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.

getElementRadius / getElementBoundingBox always returns the parent's model's results for objects created with requested / custom model ids

1 participant