Can't get a GL object while screenshot

Having problems with building or using the JCEF Java binding? Ask your questions here.

Can't get a GL object while screenshot

Postby own » Fri Dec 02, 2022 12:22 am

Hi. I'm new at CEF, so sorry for the possibly stupid question.
I'm using Ubuntu 20.04.5 and Java 1.8 (also tried java 16, same problem)

I'm trying to make a screenshot using JCEF and always getting a NullPointerException while invoking org.cef.browser.CefBrowserOsr::createScreenshot.
At the third line of this method (pinned below), where it's trying "get OpenGL internals" using this.canvas_.getGL().getGL2(), the ::getGL method is returning null, so the next ::getGL2 method can't be invoked.

Link to problem line: https://github.com/JetBrains/jcef/blob/ ... .java#L470

Code:
Code: Select all
public class Test extends JFrame {
    public ChromiumRenderer(String[] args) {
        if (!CefApp.startup(args))
            System.out.println("Startup initialization failed!");

        CefSettings settings = new CefSettings();
        settings.windowless_rendering_enabled = true;

        CefApp app = CefApp.getInstance(args, settings);
        this.browser = app.createClient().createBrowser(
                "https://www.google.com",
                true, false,
                CefRequestContext.getGlobalContext()
        );

        super.getContentPane().add(this.browser.getUIComponent(), BorderLayout.CENTER);
        super.pack();
        super.setSize(800, 800);
        super.setVisible(false);

        // The problem is here
        Image result = this.browser.createScreenshot(true).join();
    }
}


Can anyone help me with this and explain what I'm doing wrong? It feels like I forgot to configure something.
I will be very grateful for help.
own
Newbie
 
Posts: 1
Joined: Thu Dec 01, 2022 11:53 pm

Re: Can't get a GL object while screenshot

Postby magreenblatt » Mon Dec 12, 2022 4:40 pm

You need to wait for browser creation and content loading, which occurs asynchronously. For example, from CefLoadHandler.onLoadingStateChange.
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 23 guests