hoanghuynh2409 / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

CanvasFrame blank (on mac with java 7) #487

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a windowed CanvasFrame: CanvasFrame frame = new CanvasFrame("Some 
Title");
2. Load + Show an image: frame.showImage(ImageIO.read(..));

What is the expected output? What do you see instead?
The image is expected, but only an empty window is shown.

What version of the product are you using? On what operating system?

org.bytedeco.javacv, v0.9

Mac 10.9.5

java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

Please provide any additional information below.

What I found is that "canvas.createBufferStrategy(2);" was failing in 
"CanvasFrame.initCanvas()" .  It looks like the createBufferStrategy thread is 
attempting a first paint and failing because the size hasn't been set yet (if 
you catch the runtime exception, it shows: "java.lang.IllegalArgumentException: 
Width (0) and height (0) cannot be <= 0")

lwjgl has a similar issue that's addressed in: 
http://lwjgl.org/forum/index.php?topic=3341.0

My quick fix is to overwrite the initCanvas method by either extending the 
class or inline:

        CanvasFrame frame = new CanvasFrame("Some Title") {
            protected void initCanvas(boolean fullScreen, DisplayMode displayMode, double gamma) {
                try {
                    super.initCanvas(fullScreen, displayMode, gamma);
                }
                catch (RuntimeException ex) {
                    // will fail at the end of the function
                }
                if (!fullScreen) {
                        canvas.setSize(10, 10);
                        canvas.createBufferStrategy(2);
                        // canvas.setIgnoreRepaint(true); // you may be able to do this on the mac because of how quartz works
                }
            }
        };

Original issue reported on code.google.com by rddesm...@gmail.com on 11 Oct 2014 at 3:16

GoogleCodeExporter commented 9 years ago
Thanks for the fix! I'll reply on GitHub

Original comment by samuel.a...@gmail.com on 15 Oct 2014 at 1:10