Stop using interrupts to abort the rendering process (fixes #119)

They ended up lingering around and breaking any further blocking operations,
resulting in random errors afterwards. And using them was really unnecessary
anyway.
This commit is contained in:
Jonas Herzig
2020-04-06 20:56:22 +02:00
parent e3f621b86a
commit 3f4156b91b

View File

@@ -30,7 +30,7 @@ public class Pipeline<R extends Frame, P extends Frame> implements Runnable {
private final Object consumerLock = new Object(); private final Object consumerLock = new Object();
private final FrameConsumer<P> consumer; private final FrameConsumer<P> consumer;
private Thread runningThread; private volatile boolean abort;
public Pipeline(FrameCapturer<R> capturer, FrameProcessor<R, P> processor, FrameConsumer<P> consumer) { public Pipeline(FrameCapturer<R> capturer, FrameProcessor<R, P> processor, FrameConsumer<P> consumer) {
this.capturer = capturer; this.capturer = capturer;
@@ -40,7 +40,6 @@ public class Pipeline<R extends Frame, P extends Frame> implements Runnable {
@Override @Override
public synchronized void run() { public synchronized void run() {
runningThread = Thread.currentThread();
consumerNextFrame = 0; consumerNextFrame = 0;
int processors = Runtime.getRuntime().availableProcessors(); int processors = Runtime.getRuntime().availableProcessors();
int processThreads = Math.max(1, processors - 2); // One processor for the main thread and one for ffmpeg, sorry OS :( int processThreads = Math.max(1, processors - 2); // One processor for the main thread and one for ffmpeg, sorry OS :(
@@ -60,13 +59,13 @@ public class Pipeline<R extends Frame, P extends Frame> implements Runnable {
}, new ThreadPoolExecutor.DiscardPolicy()); }, new ThreadPoolExecutor.DiscardPolicy());
MinecraftClient mc = MCVer.getMinecraft(); MinecraftClient mc = MCVer.getMinecraft();
while (!capturer.isDone() && !Thread.currentThread().isInterrupted()) { while (!capturer.isDone() && !abort) {
//#if MC>=11400 //#if MC>=11400
if (GLFW.glfwWindowShouldClose(getWindow(mc).getHandle()) || ((MinecraftAccessor) mc).getCrashReporter() != null) { if (GLFW.glfwWindowShouldClose(getWindow(mc).getHandle()) || ((MinecraftAccessor) mc).getCrashReporter() != null) {
//#else //#else
//$$ if (Display.isCloseRequested() || ((MinecraftAccessor) mc).getCrashReporter() != null) { //$$ if (Display.isCloseRequested() || ((MinecraftAccessor) mc).getCrashReporter() != null) {
//#endif //#endif
Thread.currentThread().interrupt(); processService.shutdown();
return; return;
} }
R rawFrame = capturer.process(); R rawFrame = capturer.process();
@@ -93,9 +92,7 @@ public class Pipeline<R extends Frame, P extends Frame> implements Runnable {
} }
public void cancel() { public void cancel() {
if (runningThread != null) { abort = true;
runningThread.interrupt();
}
} }
@RequiredArgsConstructor @RequiredArgsConstructor