Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Internal error: couldn't create component peer"

I keep INTERMITTENTLY having this error when I start my game:

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)

I am unable to reproduce it, and it appears to simply happen randomly when I start the game - Sometimes, it starts fine, and other times, it has that error.

I'm initiating the display with this code:

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

Obviously it is something to do with the JFrame being created (since if I make the display without the JFrame it works fine), however I am currently unable to solve the issue (without ditching JFrames, which I can't do).

I am unsure if the issue has anything to do with LWJGL/OpenGL, so I have tagged it as such anyway.

like image 803
Joehot200 Avatar asked Jul 01 '26 10:07

Joehot200


1 Answers

From issue JDK-8151688:

The most probable cause of the issue: Windows rejects a new window creation because the maximum number of windows is reached.

like image 195
NateS Avatar answered Jul 03 '26 00:07

NateS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!