JCEF Bowser выдаст исключение нулевой точки при изменении размера браузера - PullRequest
0 голосов
/ 17 сентября 2018

Запуск образца кода jcef в моих centos.

// 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);
  }
}

Затем измените размер броузера, это вызовет исключение нулевой точки. стек ошибок следующий, там исключение нулевого указателя, и кадр становится мерцанием

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 и почему это произошло? спасибо

...