NewtCanvasAWT in JSplitPane on macOS

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

NewtCanvasAWT in JSplitPane on macOS

bogdanni
Hello,

The following program doesn't work quite right on macOS. Resizing with the divider doesn't resize the top canvas component. It works when the canvas is the bottom component.

I'm aware there were issues in the past, but not all are fixed. It works as expected in Linux.

package abc;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;

import com.jogamp.newt.awt.NewtCanvasAWT;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;

public class Main {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            MainWindow w = new MainWindow();
            w.setPreferredSize(new Dimension(640, 480));
            w.pack();
            w.setVisible(true);
        });
    }

    private static class MainWindow extends JFrame {
        private static final long serialVersionUID = -1;

        MainWindow() {
            GLProfile profile = GLProfile.getDefault();
            GLCapabilities caps = new GLCapabilities(profile);

            GLWindow glWindow = GLWindow.create(caps);
            glWindow.addGLEventListener(new MainGLEventListener());

            NewtCanvasAWT canvas = new NewtCanvasAWT(glWindow);

            JPanel canvasPanel = new JPanel(new BorderLayout());
            canvasPanel.setMinimumSize(new Dimension(1, 1));
            canvasPanel.add(canvas);

            JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
            pane.setBottomComponent(new JButton("Button"));
            pane.setTopComponent(canvasPanel);

            getContentPane().add(pane);
        }

        private class MainGLEventListener implements GLEventListener {
            private double time;

            public void init(GLAutoDrawable drawable) {
            }

            public void dispose(GLAutoDrawable drawable) {
            }

            public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
                // System.out.println(">>> " + w + " " + h);
            }

            public void display(GLAutoDrawable drawable) {
                GL gl = drawable.getGL();
                float r = (float) Math.abs(Math.sin(time));
                float g = (float) Math.abs(Math.sin(time + 0.3));
                float b = (float) Math.abs(Math.sin(time + 0.6));
                gl.glClearColor(r, g, b, 1);
                gl.glClear(GL.GL_COLOR_BUFFER_BIT);
                time += 0.01;
            }
        }
    }

}

Best regards,
Bogdan
Reply | Threaded
Open this post in threaded view
|

Re: NewtCanvasAWT in JSplitPane on macOS

gouessej
Administrator
Hello

Have you checked whether there is already a bug report for this? Have you tried a nightly build?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: NewtCanvasAWT in JSplitPane on macOS

bogdanni
Searching bugzilla for JSplitPane doesn't return anything.
I was using Wade Walker's java-11-fixes build + main thread patch for Mojave.
Where are those nightly builds?
Reply | Threaded
Open this post in threaded view
|

Re: NewtCanvasAWT in JSplitPane on macOS

bogdanni
Btw, other JSplitPane issues (e.g., similar to bug 1378, but for NewtCanvasAWT) gave me lots of trouble over the years.
I notice them coming back in Java 13 which I believe is built with the Mojave SDK.
I maintain a list of patches at https://github.com/Helioviewer-Project/JHelioviewer-SWHV/commits/master/extra/jogl.patch (most of those are now fixed in trunk).
Reply | Threaded
Open this post in threaded view
|

Re: NewtCanvasAWT in JSplitPane on macOS

gouessej
Administrator
In reply to this post by bogdanni
http://jogamp.org/deployment/autobuilds/master/

I see that you use an old version of a fix I modified in the mean time concerning Mesa under GNU Linux. The most recent autobuilds contain the last version of my fix.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: NewtCanvasAWT in JSplitPane on macOS

bogdanni
Thanks. Yes, this still happens with nightly build.
From the inspection of the commits, there was no patch related to this with respect to the source tree I was using.
Reply | Threaded
Open this post in threaded view
|

Re: NewtCanvasAWT in JSplitPane on macOS

gouessej
Administrator
Ok. If you think that it's a distinct bug, please fill a bug report, don't forget to provide a reproducer.

The fix I improved is related to the bug 1357.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: NewtCanvasAWT in JSplitPane on macOS

bogdanni
I have trouble filing a bug (there's no apparent way to create an account).
The reproducer is in the first message of this thread.

In the meanwhile, I managed to find the root of the problem: it's the code dealing with `superlayer` in fixCALayerLayout() of OSXmisc.m (in jogl/src/nativewindow/native/macosx). Commenting out the whole block before `if( NULL != subLayer ) {` fixes it. I verified that it also fixes my application with Java 13. It may also help with bug 1378.
Reply | Threaded
Open this post in threaded view
|

Re: NewtCanvasAWT in JSplitPane on macOS

Sven Gothel
Administrator
On 4/24/19 4:30 PM, bogdanni [via jogamp] wrote:
> In the meanwhile, I managed to find the root of the problem: it's the code
> dealing with `superlayer` in fixCALayerLayout() of OSXmisc.m (in
> jogl/src/nativewindow/native/macosx). Commenting out the whole block before
> `if( NULL != subLayer ) {` fixes it. I verified that it also fixes my
> application with Java 13. It may also help with bug 1378.

Thank you bogdanni, this is the quality contribution I love.
Hope we can discuss this scenario in more detail with your
upcoming bugzilla report. Please report as detailed as much
and include your small test case (best: a unit test).
Great job!

I reversed the order of your reply,
as this is surely the most important piece regarding this issue.

> I have trouble filing a bug (there's no apparent way to create an account).
> The reproducer is in the first message of this thread.

Please send me or Julian an email and we can create an account for you.
The password reset function shall then be used, so you can setup your password.

This was sadly necessary due to all the bugzilla + wiki spam accounts
created and ruining the DB.

Please do so, as bugs need to be documented well in bugzilla
before hey get worked on and have a git commit.

Shameless reminder to well funded companies:
Commercial Support is available
<http://jogamp.org/wiki/index.php/Maintainer_and_Contacts#Commercial_Support>

~Sven
Reply | Threaded
Open this post in threaded view
|

Re: NewtCanvasAWT in JSplitPane on macOS

bogdanni
Thank you, this has been now filed as bug 1379.