Skip to content

fix(camera): handle camera object replacement - #14

Merged
TrackAndTruckDevs merged 1 commit into
TrackAndTruckDevs:mainfrom
aefly:main
Sep 30, 2026
Merged

TrackAndTruckDevs merged 1 commit into
TrackAndTruckDevs:mainfrom
aefly:main

Conversation

@aefly

@aefly aefly commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Problem

SPF keeps the address of the game's camera object and only re-reads it when the camera type changes. When the game replaces the object without changing the type (e.g. switching trucks in the interior view), SPF kept writing to the old, freed object:

  • Camera writes from plugins (seat position, rotation, FOV, roll) were silently lost.
  • The roll SPF re-applies every frame could land in reused memory and crash the game (ACCESS_VIOLATION in spf-framework.dll).
  • "Reset" in the Camera window restored the first truck's defaults, since defaults were stored once per session.

Changes

  • GameCameraManager::Update() asks the game for the active camera's live object every frame. If it changed, the camera is re-activated on the new object (one Info log line).
  • Activation goes through a single ActivateCamera(), which also refreshes the verified-camera cache so cameras reading it (Free camera) get the same object.
  • Default state is tracked per game object: a camera activated on another object (another truck) stores its defaults again, whether the object was replaced live or through a switch to another camera type. New IGameCamera::ForgetDefaults().
  • Eight cameras redeclared their own m_defaultsSaved, hiding the one in IGameCamera: HasSavedDefaults() always returned false and StoreDefaultState() ran every frame. The duplicates are removed.

Every camera's OnDeactivate() only clears its pointer, so deactivating a camera whose object is already freed is safe.

Testing

  • Switching trucks in the interior view: the camera is re-activated on the new object, plugin writes apply, no crash.
  • "Reset to Defaults" in the Camera window restores the current truck's defaults.

The game can swap the active camera's underlying object without changing
its type (e.g. switching trucks in the interior view). Track the live
object in `GameCameraManager` and re-activate the camera when it changes
so writes target the new object. Store default state per
object and forget it when the object is replaced.
@TrackAndTruckDevs
TrackAndTruckDevs merged commit 81fec55 into TrackAndTruckDevs:main Sep 30, 2026
1 check passed
@TrackAndTruckDevs

Copy link
Copy Markdown
Owner

Thanks for finding this, merging!

@aefly aefly mentioned this pull request Oct 3, 2026
12 tasks done
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