mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-21 03:10:54 -04:00
Make screen API crash easier to debug (#2338)
* Make screen API crash easier to debug * Update fabric-screen-api-v1/src/client/java/net/fabricmc/fabric/mixin/screen/ScreenMixin.java
This commit is contained in:
parent
a6d2f785a8
commit
f05effaf73
2 changed files with 18 additions and 1 deletions
fabric-screen-api-v1/src/client/java/net/fabricmc/fabric/mixin/screen
|
@ -17,6 +17,8 @@
|
|||
package net.fabricmc.fabric.mixin.screen;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
@ -28,15 +30,30 @@ import net.minecraft.client.MinecraftClient;
|
|||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
@Mixin(MinecraftClient.class)
|
||||
abstract class MinecraftClientMixin {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger("fabric-screen-api-v1");
|
||||
private static final boolean DEBUG_SCREEN = FabricLoader.getInstance().isDevelopmentEnvironment() || Boolean.getBoolean("fabric.debugScreen");
|
||||
|
||||
@Shadow
|
||||
public Screen currentScreen;
|
||||
|
||||
@Shadow
|
||||
private Thread thread;
|
||||
@Unique
|
||||
private Screen tickingScreen;
|
||||
|
||||
@Inject(method = "setScreen", at = @At("HEAD"))
|
||||
private void checkThreadOnDev(@Nullable Screen screen, CallbackInfo ci) {
|
||||
Thread currentThread = Thread.currentThread();
|
||||
|
||||
if (DEBUG_SCREEN && currentThread != this.thread) {
|
||||
LOGGER.error("Attempted to set screen to \"{}\" outside the render thread (\"{}\"). This will likely follow a crash! Make sure to call setScreen on the render thread.", screen, currentThread.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "setScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;removed()V", shift = At.Shift.AFTER))
|
||||
private void onScreenRemove(@Nullable Screen screen, CallbackInfo ci) {
|
||||
ScreenEvents.remove(this.currentScreen).invoker().onRemove(this.currentScreen);
|
||||
|
|
|
@ -150,7 +150,7 @@ abstract class ScreenMixin implements ScreenExtensions {
|
|||
@Unique
|
||||
private <T> Event<T> ensureEventsAreInitialised(Event<T> event) {
|
||||
if (event == null) {
|
||||
throw new IllegalStateException(String.format("[fabric-screen-api-v1] The current screen (%s) has not been correctly initialised, please send this crash log to the mod author. This is usually caused by the screen not calling super.init(Lnet/minecraft/client/MinecraftClient;II)V", this.getClass().getSuperclass().getName()));
|
||||
throw new IllegalStateException(String.format("[fabric-screen-api-v1] The current screen (%s) has not been correctly initialised, please send this crash log to the mod author. This is usually caused by calling setScreen on the wrong thread.", this.getClass().getName()));
|
||||
}
|
||||
|
||||
return event;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue