Skip to content

Commit

Permalink
Fix unlogged device crash due to not logging the output
Browse files Browse the repository at this point in the history
  • Loading branch information
mchorse committed Jun 24, 2020
1 parent dd84db3 commit ed4cacd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/java/info/ata4/minecraft/minema/Minema.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;

import java.io.File;
import java.lang.reflect.Field;

/**
Expand Down Expand Up @@ -56,7 +57,7 @@ public class Minema {

@EventHandler
public void onPreInit(FMLPreInitializationEvent e) {
config = new MinemaConfig(new Configuration(e.getSuggestedConfigurationFile()));
config = new MinemaConfig(e.getSuggestedConfigurationFile());
container = Loader.instance().activeModContainer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.commons.lang3.text.WordUtils;
import org.lwjgl.opengl.Display;

import java.io.File;
import java.util.Arrays;
import java.util.List;

Expand All @@ -40,6 +41,8 @@ public class MinemaConfig {
private final ConfigCategory CAPTURING_CATEGORY;
private final ConfigCategory ENGINE_CATEGORY;

public final File dummyLog;

public static final String LANG_KEY = "minema.config";

public final ConfigBoolean useVideoEncoder = new ConfigBoolean(true);
Expand Down Expand Up @@ -70,7 +73,10 @@ public class MinemaConfig {
public final ConfigBoolean preloadChunks = new ConfigBoolean(true);
public final ConfigBoolean forcePreloadChunks = new ConfigBoolean(false);

public MinemaConfig(Configuration cfg) {
public MinemaConfig(File path) {
Configuration cfg = new Configuration(path);

this.dummyLog = new File(path.getParentFile(), "minema.log");
this.configForge = cfg;

ENCODING_CATEGORY = cfg.getCategory("encoding");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,19 @@ public void enable(String movieName, int width, int height) throws Exception {
// build encoder process and redirect output
ProcessBuilder pb = new ProcessBuilder(cmds);
pb.directory(path.toFile());
pb.redirectErrorStream(true);

if (cfg.enableEncoderLogging.get()) {
pb.redirectErrorStream(true);
pb.redirectOutput(path.resolve(movieName.concat(".log")).toFile());
} else {
// Apparently not redirecting the output to a file can lead to a
// crash of the game, but like not the one with crash log and stuff,
// and not even the native one that yields one of those hs_err_PID.log
// files, but like total unlogged crash...
//
// So yeah, I guess I'll just redirect it to a dummy file
cfg.dummyLog.delete();
pb.redirectOutput(cfg.dummyLog);
}

try {
Expand Down

0 comments on commit ed4cacd

Please sign in to comment.