Skip to content

Rework ActorViewer to use hooks#5474

Merged
Malkierian merged 3 commits intoHarbourMasters:developfrom
Rozelette:actor-view-fix
May 24, 2025
Merged

Rework ActorViewer to use hooks#5474
Malkierian merged 3 commits intoHarbourMasters:developfrom
Rozelette:actor-view-fix

Conversation

@Rozelette
Copy link
Contributor

@Rozelette Rozelette commented May 9, 2025

The current Actor Viewer currently has several situations that can lead or crashes or reading freed memory, such as when you are viewing an actor that dies, or when you reload a scene. The Actor Viewer tries to know when to reload or invalidate its data, but there is no good way to catch all circumstances where this happens. Luckily, hooks are the perfect solution to this.

This PR reworks the Actor Viewer to listen to hooks and update its state that way. This needed several new hooks, but I think they capture important events that were overdue for hooks anyways. I also took the time to rework the internal state to simplify it, now that the state was moving from a bunch of static function variables to class variables.

Build Artifacts

},
"bgCheckFlags");

if (Button("Refresh", ButtonOptions().Color(THEME_COLOR))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling this out since the whitespace changes hide this, but I removed this button. It didn't do anything useful than refresh the actor list, which is done a different way now. This also removes the need of the retrieval method.

Actor* newHead;
ActorDBEntry* dbEntry;

GameInteractor_ExecuteOnActorDelete(actor);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unsure where to put this in the function, but I chose right at the start because, since this function destroys and eventually frees the actor, it make sense for hooks to respond to it with as much information about it as possible.

ImGui::SameLine();
DrawGroupWithBorder(
[&]() {
if (display != nullptr) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now hiding the actor information until one is actually selected. I always disliked the "dummy" actor solution, because it threw me off that it wasn't an actual actor in the world, and that it was somehow "Link" in the "Switch" category...

void ActorViewerWindow::InitElement() {
ResetData();

GameInteractor::Instance->RegisterGameHook<GameInteractor::OnActorInit>([](void* refActor) {
Copy link
Contributor

@serprex serprex May 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to keep track of hook ids returned here & unregister them in ResetData

(assuming InitElement can be invoked multiple times, otherwise no need to call ResetData)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, no window InitElement is ever called more than once, so that's not an issue, I would tend to agree that ResetData doesn't need to be called here, unless those aren't the default states of those variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and removed it. It was kinda leftover from when there was more state that had to be reset. We can just rely on default initialization.

As for the hook ids, I do agree we are leaking them, but this is a singleton whose lifetime is the lifetime of the entire application, so I didn't worry about it (and the existing hook was already being leaked). Although, it does make me want to make a RAII hook manager...

@Malkierian Malkierian merged commit 8b4cad1 into HarbourMasters:develop May 24, 2025
6 checks passed
krazyjakee pushed a commit to krazyjakee/OOT that referenced this pull request Sep 6, 2025
* Rework ActorViewer to use hooks

* Rework ActorViewer to use hooks

* Remove ResetData
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.

3 participants