Skip to content

Commit

Permalink
UObjectHook: Fix persistent attached object bug with still-existing obj
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Dec 18, 2023
1 parent 0140ce9 commit 9d980ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/mods/UObjectHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,13 @@ void UObjectHook::update_persistent_states() {
continue;
}

// Destroy the existing mc state if it exists
// This can cause issues if the previous object still exists
// so we need to detach the old one
if (state->last_object != nullptr && state->last_object != obj) {
remove_motion_controller_state(state->last_object);
}

auto mc_state = get_or_add_motion_controller_state((sdk::USceneComponent*)obj);

if (mc_state == nullptr) {
Expand All @@ -1229,6 +1236,8 @@ void UObjectHook::update_persistent_states() {
} else {
*mc_state = state->state;
}

state->last_object = (sdk::USceneComponent*)obj;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/mods/UObjectHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ class UObjectHook : public Mod {
return {};
}

void remove_motion_controller_state(sdk::USceneComponent* component) {
std::unique_lock _{m_mutex};
m_motion_controller_attached_components.erase(component);
}

auto get_spawned_spheres() const {
std::shared_lock _{m_mutex};
return m_spawned_spheres;
Expand Down Expand Up @@ -332,6 +337,7 @@ class UObjectHook : public Mod {
struct PersistentState : JsonAssociation {
StatePath path{};
MotionControllerStateBase state{};
sdk::USceneComponent* last_object{nullptr};
};

struct PersistentCameraState : JsonAssociation {
Expand Down

0 comments on commit 9d980ac

Please sign in to comment.