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

make crash report if crashed on construct thread #243

Merged
merged 2 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/main/java/com/anatawa12/fixRtm/FixRtm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -108,6 +113,23 @@ object FixRtm {
}
}

private val thrownMarker = CrashReport("", Throwable())
private val crashReportHolder = AtomicReference<CrashReport?>(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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 @@
}
}

Expand Down