mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
fixes for running applet as external vm
This commit is contained in:
@@ -798,11 +798,15 @@ public class PdeEditor extends JPanel {
|
||||
|
||||
public void run() {
|
||||
while (Thread.currentThread() == thread) {
|
||||
if ((runtime != null) && (runtime.applet != null)) {
|
||||
//System.out.println(runtime.applet.finished);
|
||||
buttons.running(!runtime.applet.finished);
|
||||
//} else {
|
||||
//System.out.println("still pooping");
|
||||
if (runtime != null) {
|
||||
if (runtime.applet != null) {
|
||||
//System.out.println(runtime.applet.finished);
|
||||
buttons.running(!runtime.applet.finished);
|
||||
//} else {
|
||||
//System.out.println("still pooping");
|
||||
} else if (runtime.process != null) {
|
||||
buttons.running(true); // ??
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(250);
|
||||
@@ -811,7 +815,9 @@ public class PdeEditor extends JPanel {
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
thread.stop();
|
||||
buttons.running(false);
|
||||
thread = null;
|
||||
//thread.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1551,7 +1557,11 @@ public class PdeEditor extends JPanel {
|
||||
|
||||
|
||||
public void doQuit() {
|
||||
doStop();
|
||||
// stop isn't sufficient with external vm & quit
|
||||
// instead use doClose() which will kill the external vm
|
||||
//doStop();
|
||||
doClose();
|
||||
|
||||
//if (!checkModified()) return;
|
||||
checkModified(DO_QUIT);
|
||||
//System.out.println("exiting doquit");
|
||||
|
||||
@@ -37,7 +37,6 @@ import gnu.io.*;
|
||||
|
||||
public class PdeRuntime implements PdeMessageConsumer {
|
||||
|
||||
Process process;
|
||||
BApplet applet;
|
||||
PdeException exception;
|
||||
Window window;
|
||||
@@ -48,6 +47,8 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
boolean newMessage;
|
||||
int messageLineCount;
|
||||
|
||||
Process process;
|
||||
OutputStream processOutput;
|
||||
boolean externalRuntime;
|
||||
String externalPaths;
|
||||
|
||||
@@ -85,13 +86,14 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
"-cp",
|
||||
externalPaths,
|
||||
"BApplet",
|
||||
"--location=" + x1 + "," + y1,
|
||||
"--external=" + x1 + "," + y1,
|
||||
className
|
||||
};
|
||||
|
||||
process = Runtime.getRuntime().exec(command);
|
||||
new PdeMessageSiphon(process.getInputStream(), this);
|
||||
new PdeMessageSiphon(process.getErrorStream(), this);
|
||||
processOutput = process.getOutputStream();
|
||||
|
||||
} else {
|
||||
Class c = Class.forName(className);
|
||||
@@ -305,23 +307,33 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
|
||||
public void stop() {
|
||||
//System.out.println();
|
||||
//System.out.println("* stopping");
|
||||
//System.out.println("PdeRuntime.stop()");
|
||||
|
||||
// check for null in case stop is called during compilation
|
||||
if (applet != null) applet.stop();
|
||||
//if (window != null) window.hide();
|
||||
if (applet != null) {
|
||||
applet.stop();
|
||||
//if (window != null) window.hide();
|
||||
|
||||
// above avoids NullPointerExceptions
|
||||
// but still threading is too complex, and so
|
||||
// some boogers are being left behind
|
||||
// above avoids NullPointerExceptions
|
||||
// but still threading is too complex, and so
|
||||
// some boogers are being left behind
|
||||
|
||||
applet = null;
|
||||
//window = null;
|
||||
applet = null;
|
||||
//window = null;
|
||||
|
||||
if (process != null) { // running externally
|
||||
} else if (process != null) { // running externally
|
||||
//System.out.println("killing external process");
|
||||
process.destroy();
|
||||
process = null;
|
||||
|
||||
try {
|
||||
//System.out.println("writing to stop process");
|
||||
processOutput.write('s');
|
||||
processOutput.flush();
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("error stopping external applet");
|
||||
e.printStackTrace();
|
||||
close();
|
||||
}
|
||||
|
||||
/*
|
||||
try {
|
||||
@@ -349,10 +361,27 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
window.dispose();
|
||||
window = null;
|
||||
}
|
||||
|
||||
if (process != null) {
|
||||
try {
|
||||
process.destroy();
|
||||
} catch (Exception e) {
|
||||
System.err.println("(ignored) error while destroying");
|
||||
e.printStackTrace();
|
||||
}
|
||||
process = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void message(String s) {
|
||||
if (s.indexOf(BApplet.EXTERNAL_QUIT) == 0) {
|
||||
//close();
|
||||
System.out.println("got proper quit message");
|
||||
editor.doClose();
|
||||
return;
|
||||
}
|
||||
|
||||
//System.err.println("message " + s.length() + ":" + s);
|
||||
if (s.length() > 2) System.err.println(s);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user