diff --git a/core/src/net/sf/openrocket/gui/figure3d/JoglDebugAdaptor.java b/core/src/net/sf/openrocket/gui/figure3d/JoglDebugAdaptor.java new file mode 100644 index 000000000..b9669e6bd --- /dev/null +++ b/core/src/net/sf/openrocket/gui/figure3d/JoglDebugAdaptor.java @@ -0,0 +1,42 @@ +package net.sf.openrocket.gui.figure3d; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; + +import net.sf.openrocket.logging.LogHelper; +import net.sf.openrocket.startup.Application; + +/** + * Redirects system err into OpenRocket's log.debug() if openrocket.debug is enabled. + * This lets me capture JOGL debug as log events, which can be included in error reports etc. + * I wish I could get the JOGL debug log on a separate printstream, so I do not have to take + * over all of ERR. + * + * @author bkuker + * + */ +final class JoglDebugAdaptor { + private static final LogHelper log = Application.getLogger(); + + final static void plumbJoglDebug() { + if (RocketFigure3d.is3dEnabled() && System.getProperty("openrocket.debug") != null) { + System.setProperty("jogl.debug", "all"); + + System.setErr(new PrintStream(new OutputStream() { + StringBuilder sb = new StringBuilder(); + + @Override + public synchronized void write(int b) throws IOException { + if (b == '\r' || b == '\n') { + if (sb.toString().trim().length() > 0) + log.debug(sb.toString()); + sb = new StringBuilder(); + } else { + sb.append((char) b); + } + } + })); + } + } +} diff --git a/core/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java b/core/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java index 25155c44b..0b15e19cb 100644 --- a/core/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java +++ b/core/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java @@ -52,6 +52,8 @@ public class RocketFigure3d extends JPanel implements GLEventListener { private static final LogHelper log = Application.getLogger(); static { + JoglDebugAdaptor.plumbJoglDebug(); + //this allows the GL canvas and things like the motor selection //drop down to z-order themselves. JPopupMenu.setDefaultLightWeightPopupEnabled(false);