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

Mixins: Do not crash when a mixin has no associated handler #103

Merged
merged 5 commits into from
Jan 17, 2024

Conversation

mattco98
Copy link
Member

@mattco98 mattco98 commented Jan 7, 2024

Initially it made sense to crash, but after some experience this is not
a viable solution. There is usually a bit of time between when the mixin
is created and when .attach() is called. If the mixin attempts to run
in between this period, it would lead to a crash, however this is not
user error.

To fix this, all generated mixins now check with JSLoader to see if
they have an attached method before attempting to invoke it. If there is
no attached method yet, the mixin will act as if it did not exist (e.g.
do nothing for inject mixins, call the original method for redirect
mixins, etc).

With this change, CT users can now inject into places that are invoked
early in the startup process, such as MinecraftClient.setScreen (which
is invoked in the MinecraftClient constructor).

Initially it made sense to crash, but after some experience this is not
a viable solution. There is usually a bit of time between when the mixin
is created and when `.attach()` is called. If the mixin attempts to run
in between this period, it would lead to a crash, however this is not
user error.

To fix this, all generated mixins now check with `JSLoader` to see if
they have an attached method before attempting to invoke it. If there is
no attached method yet, the mixin will act as if it did not exist (e.g.
do nothing for inject mixins, call the original method for redirect
mixins, etc).

With this change, CT users can now inject into places that are invoked
early in the startup process, such as MinecraftClient.setScreen (which
is invoked in the MinecraftClient constructor).
@mattco98 mattco98 merged commit de81472 into ChatTriggers:main Jan 17, 2024
1 check failed
@mattco98 mattco98 deleted the mixin-without-attach branch January 17, 2024 00:02
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.

1 participant