Screen Sometimes Blank at Game Start

Hello! I’ve been working on a simple game engine. All was going pretty well, and I got the foundation finished. By that, I mean, the game sets up with user defined display settings, initializes stuff, and starts the game loop. Everything works great, except I have an issue in both Windowed mode and full screen:

In Windowed mode, sometimes the screen will appear blank, until I resize or minimize the window.

In full screen, I only get a blank screen if I use the default Display resolution. Most of the other resolutions appear just fine.

Here is some code relevant to displaying the screen:

This is performed when the use presses the play button on the display settings dialog

public void actionPerformed(ActionEvent e) {
				DisplayMode dm = modes[resolutionBox.getSelectedIndex()];
				boolean fs = fullscreenBox.getSelectedItem().equals ("Fullscreen");
				boolean vs = vSyncCheckBox.isSelected();
			
				game.initScreen (dm, fs, vs);
				runGame (game);
				
				f.dispose();
			}
		});

private final void runGame(EGame g)
	{
		Thread t = new Thread (g);
		t.start();
	}

This is the run method in the EGame class

public final void run() {
		start();
		isRunning = true;
		gameLoop();
		endGame();
	}

The user of the engine will call the method setGameCanvas() in the start() method. Other things can go in the start() method, but for my test games, it just that method:

protected final void setGameCanvas(EGameCanvas c)
	{
		screen.remove (canvas);
		canvas = c;
		canvas.addKeyListener (keyboard);
		screen.add (canvas);
	}

And finally, here is the gameLoop:

private final void gameLoop()
	{
		// Final setup before starting game
		canvas.setBuffer (2);
		screen.addKeyListener (keyboard);
		canvas.addKeyListener (keyboard);
		
		int TARGET_FPS = screen.getTargetFps();
		final long OPTIMAL_TIME = 1000000000 / TARGET_FPS;
		
		long lastLoopTime = System.nanoTime();
		
		long now = 0;
		long lastFpsTime = 0;
		long updateLength = 0;
		double delta = 0;
		
		int fps = 0;
		
		while (isRunning)
		{
			now = System.nanoTime();
			updateLength = now - lastLoopTime;
			lastLoopTime = now;
			delta = updateLength / ((double) OPTIMAL_TIME);

			lastFpsTime += updateLength;
			fps++;

			if (lastFpsTime >= 1000000000)
			{
				screen.setFps (fps);
				lastFpsTime = 0;
				fps = 0;
			}
			
			keyboard.poll();
			keyboardEvents();
			
			update (delta);
			
			render();

			try {
				Thread.sleep( (lastLoopTime-System.nanoTime() + OPTIMAL_TIME)/1000000 );
			}
			catch (Exception ex) {}
		}
	}

Now, keep in mind, neither of my issues existed, until I added the run method and ran it in a separate thread. I can about guarantee it’s a threading issue.

But, I’m no expert, so any advice would be appreciated.