diff --git a/src/main/java/com/anatawa12/fixRtm/FixRtm.kt b/src/main/java/com/anatawa12/fixRtm/FixRtm.kt index 7f4dd7a3..765f1a9a 100644 --- a/src/main/java/com/anatawa12/fixRtm/FixRtm.kt +++ b/src/main/java/com/anatawa12/fixRtm/FixRtm.kt @@ -15,9 +15,11 @@ import jp.ngt.rtm.RTMCore import net.minecraft.block.Block import net.minecraft.client.Minecraft import net.minecraft.client.resources.IReloadableResourceManager +import net.minecraft.crash.CrashReport import net.minecraft.entity.player.EntityPlayerMP import net.minecraft.item.Item import net.minecraft.launchwrapper.Launch +import net.minecraft.util.ReportedException import net.minecraft.util.ResourceLocation import net.minecraft.util.text.Style import net.minecraft.util.text.TextComponentString @@ -34,10 +36,13 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent import net.minecraftforge.fml.common.event.FMLPreInitializationEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.PlayerEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import net.minecraftforge.fml.common.network.NetworkCheckHandler import net.minecraftforge.fml.relauncher.Side import paulscode.sound.SoundSystemConfig import java.awt.Color import java.awt.image.BufferedImage +import java.util.concurrent.atomic.AtomicReference import javax.imageio.ImageIO import kotlin.math.max @@ -108,6 +113,23 @@ object FixRtm { } } + private val thrownMarker = CrashReport("", Throwable()) + private val crashReportHolder = AtomicReference(null) + + internal fun reportCrash(report: CrashReport) { + // fail if after crashing other thread + crashReportHolder.compareAndSet(null, report) + } + + @SubscribeEvent + fun onServerTick(e: TickEvent.ServerTickEvent) { + val report = crashReportHolder.get() + if (report === null) return + if (report === thrownMarker) return + crashReportHolder.set(thrownMarker) + throw ReportedException(report) + } + @Mod.EventHandler @Suppress("UNUSED_PARAMETER") fun init(e: FMLInitializationEvent) { diff --git a/src/main/java/com/anatawa12/fixRtm/rtm/modelpack/init/ExModelPackConstructThread.kt b/src/main/java/com/anatawa12/fixRtm/rtm/modelpack/init/ExModelPackConstructThread.kt index 05657c87..60a651cc 100644 --- a/src/main/java/com/anatawa12/fixRtm/rtm/modelpack/init/ExModelPackConstructThread.kt +++ b/src/main/java/com/anatawa12/fixRtm/rtm/modelpack/init/ExModelPackConstructThread.kt @@ -1,5 +1,6 @@ package com.anatawa12.fixRtm.rtm.modelpack.init +import com.anatawa12.fixRtm.FixRtm import com.anatawa12.fixRtm.asm.Preprocessor import com.anatawa12.fixRtm.asm.config.MainConfig import com.anatawa12.fixRtm.asm.config.MainConfig.ModelPackLoadSpeed.* @@ -34,13 +35,13 @@ class ExModelPackConstructThread(val threadSide: Side, val parent: ModelPackLoad try { block() } catch (throwable: Throwable) { + var crashReport: CrashReport = CrashReport.makeCrashReport(throwable, "Constructing RTM ModelPack") + crashReport.makeCategory("Initialization") if (threadSide == Side.CLIENT) { - var crashReport: CrashReport = CrashReport.makeCrashReport(throwable, "Constructing RTM ModelPack") - crashReport.makeCategory("Initialization") crashReport = NGTUtilClient.getMinecraft().addGraphicsAndWorldToCrashReport(crashReport) NGTUtilClient.getMinecraft().displayCrashReport(crashReport) } else { - throw throwable + FixRtm.reportCrash(crashReport) } } } diff --git a/src/main/rtm-patches/jp/ngt/rtm/modelpack/init/ModelPackLoadThread.java.pm.patch b/src/main/rtm-patches/jp/ngt/rtm/modelpack/init/ModelPackLoadThread.java.pm.patch index aaee5512..3d9bc633 100644 --- a/src/main/rtm-patches/jp/ngt/rtm/modelpack/init/ModelPackLoadThread.java.pm.patch +++ b/src/main/rtm-patches/jp/ngt/rtm/modelpack/init/ModelPackLoadThread.java.pm.patch @@ -1,6 +1,29 @@ --- a/jp/ngt/rtm/modelpack/init/ModelPackLoadThread.java +++ b/jp/ngt/rtm/modelpack/init/ModelPackLoadThread.java -@@ -131,19 +131,20 @@ +@@ -97,17 +97,19 @@ + }; + thread.start(); + this.runThread(); + } catch (Throwable throwable) { + this.finish(); ++ CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Loading RTM ModelPack"); ++ crashreport.makeCategory("Initialization"); + if (this.threadSide == Side.CLIENT) { +- CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Loading RTM ModelPack"); +- crashreport.makeCategory("Initialization"); + crashreport = NGTUtilClient.getMinecraft().addGraphicsAndWorldToCrashReport(crashreport); + NGTUtilClient.getMinecraft().displayCrashReport(crashreport); + } else { +- throwable.printStackTrace(); ++ // Kotlin intellij plugin issue: reportCrash$fixRtm looks not found ++ // in ide but should be found in gradle build ++ com.anatawa12.fixRtm.FixRtm.INSTANCE.reportCrash$fixRtm(crashreport); + } + } finally { + if (this.displayWindow && !this.debug) { + this.mainFrame.dispose(); + } +@@ -131,19 +133,20 @@ } }