调整浏览器大小时,JCEF Bowser将引发空点异常

时间:2018-09-17 07:43:41

标签: opengl jogl chromium-embedded

在我的centos中运行示例jcef代码。

// Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights

package simple;

public class MainFrame extends JFrame {
  private static final long serialVersionUID = -5570653778104813836L;
  private final JTextField address_;
  private final CefApp cefApp_;
  private final CefClient client_;
  private final CefBrowser browser_;
  private final Component browerUI_;


  private MainFrame(String startURL, boolean useOSR, boolean isTransparent) {
    CefApp.addAppHandler(new CefAppHandlerAdapter(null) {
      @Override
      public void stateHasChanged(org.cef.CefApp.CefAppState state) {
        // Shutdown the app if the native CEF part is terminated
        if (state == CefAppState.TERMINATED)
          System.exit(0);
      }

      @Override
      public void onBeforeCommandLineProcessing(String arg0, CefCommandLine commandLine) {
        commandLine.appendSwitch("enable-begin-frame-scheduling");
        commandLine.appendSwitch("disable-gpu");
        commandLine.appendSwitch("disable-gpu-compositing");
        commandLine.appendSwitchWithValue("off-screen-frame-rate", "60");
        super.onBeforeCommandLineProcessing(arg0, commandLine);

      }

    });
    CefSettings settings = new CefSettings();
    settings.windowless_rendering_enabled = useOSR;
    cefApp_ = CefApp.getInstance(settings);

    client_ = cefApp_.createClient();
    browser_ = client_.createBrowser(startURL, useOSR, isTransparent);
    browerUI_ = browser_.getUIComponent();

    address_ = new JTextField(startURL, 100);
    address_.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        browser_.loadURL(address_.getText());
      }
    });

    getContentPane().add(address_, BorderLayout.NORTH);
    getContentPane().add(browerUI_, BorderLayout.CENTER);
    pack();
    setSize(800, 600);
    setVisible(true);

    addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosing(WindowEvent e) {
        CefApp.getInstance().dispose();
        dispose();
      }
    });
  }

  public static void main(String[] args) {
    new MainFrame("localhost:8080/upload/line-simple.html", OS.isLinux(), false);
  }
}

然后调整Broser的大小,它将触发空点异常。错误堆栈随之而来,出现空指针异常引发并且帧闪烁

libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at org.cef.browser.CefBrowserOsr.onPaint(CefBrowserOsr.java:294)
    at org.cef.CefClient.onPaint(CefClient.java:806)
    at org.cef.CefApp.N_DoMessageLoopWork(Native Method)
    at org.cef.CefApp$7.run(CefApp.java:525)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)

查看CefBrowserOsr的源代码:

renderer_.onPaint(canvas_.getGL().getGL2(), popup, dirtyRects, buffer, width, height);

似乎canvas_.getGL()抛出的结果为null。 有人可能拥有CEF,为什么会这样? 谢谢

0 个答案:

没有答案