Skip to content

Commit

Permalink
Add crash report window on a separate process
Browse files Browse the repository at this point in the history
  • Loading branch information
serivesmejia committed Dec 6, 2024
1 parent 7f84006 commit 47fbfb2
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.github.serivesmejia.eocvsim.gui.dialog.source.CreateVideoSource;
import com.github.serivesmejia.eocvsim.input.SourceType;
import com.github.serivesmejia.eocvsim.util.event.EventHandler;
import com.github.serivesmejia.eocvsim.util.exception.handling.CrashReport;
import io.github.deltacv.eocvsim.plugin.loader.PluginManager;

import javax.swing.*;
Expand Down Expand Up @@ -175,6 +176,10 @@ public static void createWorkspace(Visualizer visualizer) {
invokeLater(() -> new CreateWorkspace(visualizer.frame, visualizer));
}

public static void createCrashReport(Visualizer visualizer, String crash) {
invokeLater(() -> new CrashReportOutput(visualizer == null ? null : visualizer.frame, crash));
}

public static FileAlreadyExists.UserChoice createFileAlreadyExistsDialog(EOCVSim eocvSim) {
return new FileAlreadyExists(eocvSim.visualizer.frame, eocvSim).run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ public void init(Theme theme) {
EOCVSimIconLibrary.INSTANCE.getIcoEOCVSim16().getImage()
));

if(true) {
throw new RuntimeException("This code is not supposed to be executed");
}

frame.setLocationRelativeTo(null);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.github.serivesmejia.eocvsim.gui.dialog

import com.formdev.flatlaf.intellijthemes.FlatArcDarkIJTheme
import com.github.serivesmejia.eocvsim.gui.EOCVSimIconLibrary
import com.github.serivesmejia.eocvsim.gui.dialog.component.BottomButtonsPanel
import com.github.serivesmejia.eocvsim.gui.dialog.component.OutputPanel
import com.github.serivesmejia.eocvsim.gui.dialog.component.OutputPanel.DefaultBottomButtonsPanel
import java.awt.Dimension
import java.awt.FlowLayout
import java.awt.Font
import javax.swing.Box
import javax.swing.BoxLayout
import javax.swing.JDialog
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.SwingUtilities
import javax.swing.WindowConstants
import kotlin.system.exitProcess

class CrashReportOutput(
parent: JFrame?,
crashReport: String
){
val output by lazy {
JDialog(parent)
}

private val reportPanel by lazy {
OutputPanel(DefaultBottomButtonsPanel { exitProcess(0) })
}

init {
FlatArcDarkIJTheme.setup()

output.isModal = true
output.title = "Crash Report"
output.layout = BoxLayout(output.contentPane, BoxLayout.Y_AXIS)
output.isAlwaysOnTop = true

reportPanel.outputArea.text = crashReport
SwingUtilities.invokeLater {
reportPanel.resetScroll()
}

output.add(JLabel("An unexpected fatal error occurred, please report this to the developers.").apply {
font = font.deriveFont(Font.BOLD, 18f)
alignmentX = JLabel.CENTER_ALIGNMENT
})
output.add(reportPanel)

output.defaultCloseOperation = WindowConstants.DISPOSE_ON_CLOSE

output.size = Dimension(800, 400)

output.iconImages = listOf(
EOCVSimIconLibrary.icoEOCVSim128.image,
EOCVSimIconLibrary.icoEOCVSim64.image,
EOCVSimIconLibrary.icoEOCVSim32.image,
EOCVSimIconLibrary.icoEOCVSim16.image
)

output.setLocationRelativeTo(null)
output.isVisible = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class OutputPanel(
) : JPanel(GridBagLayout()) {

val outputArea = JTextArea("")
val outputScroll = JScrollPane(outputArea)

companion object {
val monoFont: Font by lazy {
Expand Down Expand Up @@ -73,7 +74,6 @@ class OutputPanel(
)
}

val outputScroll = JScrollPane(outputArea)
outputScroll.verticalScrollBarPolicy = JScrollPane.VERTICAL_SCROLLBAR_ALWAYS
outputScroll.horizontalScrollBarPolicy = JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED

Expand All @@ -95,6 +95,10 @@ class OutputPanel(
})
}

fun resetScroll() {
outputScroll.verticalScrollBar.value = 0
}

open class DefaultBottomButtonsPanel(
override val closeCallback: () -> Unit
) : BottomButtonsPanel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,26 @@ class CrashReport(causedByException: Throwable, isDummy: Boolean = false) {
/**
* Save the crash report to a file located in the working directory
*/
fun saveCrashReport() {
fun saveCrashReport(): File {
val workingDir = File(System.getProperty("user.dir"))

val crashLogFile = workingDir + defaultCrashFileName

saveCrashReport(crashLogFile)

return crashLogFile
}

/**
* Save the crash report to a file located in the working directory
* @param filename the name of the file to save the crash report to
*/
fun saveCrashReport(filename: String) {
fun saveCrashReport(filename: String): File {
val workingDir = File(System.getProperty("user.dir"))
val crashLogFile = workingDir + File.separator + "$filename.log"

saveCrashReport(crashLogFile)
return crashLogFile
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.serivesmejia.eocvsim.util.exception.handling

import com.formdev.flatlaf.intellijthemes.FlatArcDarkIJTheme
import com.github.serivesmejia.eocvsim.Build
import com.github.serivesmejia.eocvsim.gui.DialogFactory
import com.github.serivesmejia.eocvsim.util.SysUtil
import kotlinx.coroutines.Runnable
import picocli.CommandLine
import java.io.File

object CrashReportOutputMain {
@CommandLine.Command(name = "report", mixinStandardHelpOptions = true, version = [Build.versionString])
private class CrashReportOutputCommandInterface : Runnable {
@CommandLine.Option(names = ["-p", "--path"], description = ["Specifies the path where the crash report was saved"])
@JvmField var crashReportPath: String? = null

override fun run() {
DialogFactory.createCrashReport(null, SysUtil.loadFileStr(File(crashReportPath ?: "")))
}
}

@JvmStatic
fun main(args: Array<String>) {
CommandLine(CrashReportOutputCommandInterface()).execute(*args)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.github.serivesmejia.eocvsim.util.exception.handling

import com.github.serivesmejia.eocvsim.currentMainThread
import com.github.serivesmejia.eocvsim.util.JavaProcess
import com.github.serivesmejia.eocvsim.util.SysUtil
import com.github.serivesmejia.eocvsim.util.loggerForThis
import java.lang.Thread.sleep
import javax.swing.SwingUtilities
import kotlin.system.exitProcess

Expand Down Expand Up @@ -35,14 +38,21 @@ class EOCVSimUncaughtExceptionHandler private constructor() : Thread.UncaughtExc
//since we would be basically in a deadlock state if that happened
//or if we have a lotta uncaught exceptions.
if(t == currentMainThread || SwingUtilities.isEventDispatchThread() || e !is Exception || uncaughtExceptionsCount > MAX_UNCAUGHT_EXCEPTIONS_BEFORE_CRASH) {
CrashReport(e).saveCrashReport()
val file = CrashReport(e).saveCrashReport()

logger.warn("If this error persists, open an issue on EOCV-Sim's GitHub attaching the crash report file.")
logger.warn("The application will exit now (exit code 1)")

Thread {
JavaProcess.killSubprocessesOnExit = false
JavaProcess.exec(CrashReportOutputMain::class.java, listOf(), listOf("-p=${file.absolutePath}"))
}.start()

sleep(3000) // wait enough for the subprocess to start

exitProcess(1)
} else {
CrashReport(e).saveCrashReport("lasterror-")
CrashReport(e).saveCrashReport("lasterror-eocvsim")

//if not, eocv sim might still be working (i.e a crash from a MatPoster thread)
//so we might not need to exit in this point, but we'll need to send a warning
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ Join the [deltacv discord server](https://discord.gg/A3RMYzf6DA) !
- Improved several dialogs, adds a better "create workspace" dialog & a welcome dialog that is shown when the sim is opened for the first time
- New modernized application icon
- @qwertychouskie made their first contribution: "macOS: Add application name, use system light/dark mode in titlebar" and "macOS: Use standard Settings & About entries in menu". Thank you !

## [v3.8.4 - Maven Central Migration](https://github.com/deltacv/EOCV-Sim/releases/tag/v3.8.4)
- This is the 29th release for EOCV-Sim
- Migrates all of EOCV-Sim's artifacts to the maven central repository (bye bye JitPack)
- Bugfixes:
- Adds error checking at multiple points of the sim to handle simple edge cases that shouldn't cause an app crash

## [v3.8.3 - Plugin Classloader major optimization](https://github.com/deltacv/EOCV-Sim/releases/tag/v3.8.3)
- This is the 28th release for EOCV-Sim
- Improves plugin classloader classpath loading by caching and resource reusage, this brings an extremely noticeable performance boost for plugins that load a lot of class files from different Maven dependencies in a short amount of time (I'm looking at you Javalin)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ plugins {

allprojects {
group 'org.deltacv.EOCV-Sim'
version '4.0.0'
version '4.0.1'

apply plugin: 'java'

Expand Down

0 comments on commit 47fbfb2

Please sign in to comment.