Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak skeleton limbs to use OTR path strings for loading DList and improve Alt toggling #3479

Merged

Conversation

Archez
Copy link
Contributor

@Archez Archez commented Dec 1, 2023

Our skeleton limb resources were loading the raw resource for the specified DList and assigning a pointer to the Gfx instructions when parsing the limb resource. This lead to the issue where the underlying DList resource could be unloaded, but the skeleton limb is not, causing either garbage data to render for the DList or straight up crash.

This situation could happen with the following example:

  1. The user has a mod that has an Alt replacement for a DList that is used by a skeleton limb
  2. The system has Alt toggled on
  3. Upon loading the skeleton, there is no Alt replacement for the skeleton, so the non-alt version is loaded.
  4. Then the limbs load (same thing happens, no Alt replacement)
  5. Then the DList for the limb is loaded, this ends up loading as the Alt version, and the raw pointer assigned to the non-alt skeleton
  6. Upon rendering in game, the first time the skeleton is rendered after loading everything seems fine
  7. After transitioning scenes, all Alt resources are unloaded. This means the DList raw data assigned to the limb resource is now a dangling pointer
  8. Depending on memory, the next time you enter the scene with the skeleton, the pointer could now be garbage data, leading to a crash
  9. Alternatively, toggling off Alt assets will unload the DList too, but the skeleton is not unloaded/reloaded since its a non-Alt asset, leading to a similar issue

The proposed changes/fixes here is to instead use the string reference of the DList path, and assign its pointer to the limb's DList. Later on when the limb is rendered, gSPDisplayList will recognize the OTR signature and dynamically load the DList resource for either Alt or non-Alt as necessary. This pattern matches roughly with how scene MeshLists are registered, and textures in DLists themselves.


To support these changes, I also needed to defer actually toggling the gAltAssets CVar to the end of the game frame, similar to how we defer skeleton patching updates. This is necessary as we don't want a skeleton to try to load a DList for the wrong assets mode due to race conditions. Pressing Tab or clicking the checkbox in the menu for it will appropriately handle toggling the actual CVar at the right time.

Currently though, it is not advised to set gAltAssets via the debug console, as that will set the CVar immediately and potentially cause crashes depending on the used mods. A CVar refactor could mitigate this in the future.

Build Artifacts

@Archez
Copy link
Contributor Author

Archez commented Dec 1, 2023

This resolves issues with the flag poles seen in the 3ds custom pack like so:

image

@garrettjoecox garrettjoecox merged commit fbc397a into HarbourMasters:develop-macready Dec 4, 2023
8 checks passed
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.

None yet

3 participants