"内部错误:无法创建组件对等"

时间:2015-02-01 12:30:59

标签: java swing opengl lwjgl

当我开始游戏时,我会间歇性地出现这个错误:

Exception in thread "main" java.lang.InternalError: couldn't create component peer
at sun.awt.windows.WComponentPeer.checkCreation(Unknown Source)
at sun.awt.windows.WComponentPeer.<init>(Unknown Source)
at sun.awt.windows.WCanvasPeer.<init>(Unknown Source)
at sun.awt.windows.WPanelPeer.<init>(Unknown Source)
at sun.awt.windows.WWindowPeer.<init>(Unknown Source)
at sun.awt.windows.WFramePeer.<init>(Unknown Source)
at sun.awt.windows.WToolkit.createFrame(Unknown Source)
at java.awt.Frame.addNotify(Unknown Source)
at java.awt.Window.show(Unknown Source)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at Joehot200.TerrainDemo.setUpDisplay(TerrainDemo.java:3569)
at Joehot200.TerrainDemo.startGame(TerrainDemo.java:3640)
at StartScreenExperiments.Test2.resartTDemo(Test2.java:55)
at StartScreenExperiments.Test2.main(Test2.java:41)

我无法重现它,它似乎只是在我开始游戏时随机发生 - 有时,它开始很好,有时,它有错误。

我使用此代码启动显示:

private void setUpDisplay() {
    //System.setProperty("org.lwjgl.librarypath", new File("D:/Downloads/mcp/ship/Ship/lib/natives-win").getAbsolutePath());
    try {
        DisplayMode displayMode = null;
        DisplayMode[] modes = Display.getAvailableDisplayModes();

         for (int i = 0; i < modes.length; i++)
         {
             if (modes[i].isFullscreenCapable())
               {
                    displayMode = modes[i];
               }
         }
         if (displayMode == null){
             displayMode = new DisplayMode(100, 100);
         }
         displayMode = Display.getDesktopDisplayMode();
         //Display.setDisplayModeAndFullscreen(new DisplayMode(200, 200));
        //Display.setDisplayMode(new DisplayMode(WINDOW_DIMENSIONS[0], WINDOW_DIMENSIONS[1]));
         Display.setDisplayMode(displayMode);
        Display.setResizable(true);
        Display.setTitle("Pirate game");
        //Display.setFullscreen(true);
        try {Thread.sleep(3000);} catch (InterruptedException e1) {}

        frame = new JFrame();

        Canvas canvas = new Canvas();
        frame.add(canvas);
        frame.setSize(500, 500);
        frame.setVisible(true);
        try {
            try {Thread.sleep(3000);} catch (InterruptedException e1) {}
            Display.setParent(canvas);

            Display.create();

        } catch (LWJGLException e) {
            e.printStackTrace();
        }
        try {Thread.sleep(3000);} catch (InterruptedException e1) {}
        frame.setVisible(true);
        frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
        frame.repaint();

    } catch (LWJGLException e) {
        e.printStackTrace();
        //cleanUp(true);
    }
}

显然它与正在创建的JFrame有关(因为如果我在没有JFrame的情况下显示它工作正常),但是我目前无法解决问题(没有放弃JFrame,我可以&#t; t做)。

我不确定该问题是否与LWJGL / OpenGL有关,所以无论如何我都将其标记为。

1 个答案:

答案 0 :(得分:1)

来自问题JDK-8151688

此问题的最可能原因:Windows拒绝创建新窗口,因为达到了最大窗口数。