Skip to content

Commit

Permalink
Merge pull request #131 from deltacv/dev
Browse files Browse the repository at this point in the history
v4.0.1
  • Loading branch information
serivesmejia authored Dec 8, 2024
2 parents 6bef9ea + 6c0e3a7 commit 2057240
Show file tree
Hide file tree
Showing 14 changed files with 334 additions and 21 deletions.
10 changes: 10 additions & 0 deletions EOCV-Sim/src/main/java/com/github/serivesmejia/eocvsim/EOCVSim.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

package com.github.serivesmejia.eocvsim

import com.formdev.flatlaf.intellijthemes.FlatArcDarkIJTheme
import com.formdev.flatlaf.intellijthemes.FlatArcDarkIJTheme.setup
import com.github.serivesmejia.eocvsim.EOCVSim.Parameters
import com.github.serivesmejia.eocvsim.config.Config
import com.github.serivesmejia.eocvsim.config.ConfigManager
Expand Down Expand Up @@ -59,6 +61,7 @@ import org.openftc.easyopencv.TimestampedPipelineHandler
import java.awt.Dimension
import java.io.File
import java.lang.Thread.sleep
import javax.swing.JOptionPane
import javax.swing.SwingUtilities
import javax.swing.filechooser.FileFilter
import javax.swing.filechooser.FileNameExtensionFilter
Expand Down Expand Up @@ -262,6 +265,13 @@ class EOCVSim(val params: Parameters = Parameters()) {
"Couldn't finally claim lock file in \"${EOCVSimFolder.absolutePath}\"! " + "Is the folder opened by another EOCV-Sim instance?"
)

JOptionPane.showMessageDialog(
null,
"Another instance of EOCV-Sim is already running in this machine, please close it and try again.",
"Error",
JOptionPane.ERROR_MESSAGE
)

logger.error("Unable to continue with the execution, the sim will exit now.")
exitProcess(-1)
} else {
Expand Down
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
@@ -0,0 +1,60 @@
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.OutputPanel
import com.github.serivesmejia.eocvsim.gui.dialog.component.OutputPanel.DefaultBottomButtonsPanel
import java.awt.Dimension
import java.awt.Font
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 {
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,28 @@
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
import javax.swing.SwingUtilities

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() {
SwingUtilities.invokeLater(FlatArcDarkIJTheme::setup)
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
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class PluginManager(val eocvSim: EOCVSim) {
}

val repositoryManager by lazy {
PluginRepositoryManager(appender, haltLock, haltCondition)
PluginRepositoryManager(appender, eocvSim, haltLock, haltCondition)
}

private val _pluginFiles = mutableListOf<File>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlin.math.log

object PaperVisionChecker {

val LATEST_PAPERVISION = ParsedVersion(1, 0, 3)
val LATEST_PAPERVISION = ParsedVersion(1, 0, 4)

const val RESET_QUESTION = "o you wish to fix this by resetting back to the default settings? Please note this will wipe your plugins folder!"

Expand Down Expand Up @@ -52,12 +52,6 @@ object PaperVisionChecker {
logger.info("hash_check = ${eocvSim.config.flags["${hash}_check"]}")
logger.info("null_check = ${eocvSim.config.flags["null_check"]}")

if(eocvSim.config.flags["${hash}_check"] == true) {
return
} else {
eocvSim.config.flags["${hash}_check"] = true
}

val parsedVersion = try {
ParsedVersion(paperVisionPlugin!!.pluginVersion).apply {
logger.info("Parsed PaperVision version: $this")
Expand All @@ -67,6 +61,12 @@ object PaperVisionChecker {
null
}

if(eocvSim.config.flags["${hash}_check"] == true && (parsedVersion != null && parsedVersion >= LATEST_PAPERVISION)) {
return
} else {
eocvSim.config.flags["${hash}_check"] = true
}

if(paperVisionPlugin == null) {
SwingUtilities.invokeLater {
val result = JOptionPane.showOptionDialog(
Expand Down Expand Up @@ -102,7 +102,7 @@ object PaperVisionChecker {

eocvSim.config.flags["null_check"] = false
logger.warn("PaperVision plugin loaded from file")
} else if(parsedVersion == null || parsedVersion < LATEST_PAPERVISION) {
}/*else if(parsedVersion == null || parsedVersion < LATEST_PAPERVISION) {
SwingUtilities.invokeLater {
val result = JOptionPane.showOptionDialog(
eocvSim.visualizer.frame,
Expand All @@ -120,7 +120,6 @@ object PaperVisionChecker {
eocvSim.config.flags["null_check"] = false
logger.warn("PaperVision plugin outdated")
}
}*/
}

}
Loading

0 comments on commit 2057240

Please sign in to comment.