LibGDX +Kryonet problem

Im very new to Multiplayer programming and i know the basics of kryonet. I made a little Top down shooter but when i try to do something that kryonet activates in the MainGame the game crashes and it gives me the error:“No opengl context in current thread”. I googled the problem and found out that it has something to do with Libgdx and kryo being on different Threads. I tried for an hour to figure out how to pass something from Kryonet to libgdx but everything doesnt work. My mainclass implements the runnable interface and has the method:


	@Override
	public void run() {
		 ((Game) Gdx.app.getApplicationListener()).setScreen(MainGame.JPlayScreen);
		
	}

and my Kryonet Customlistener has the method:

public void received(Connection c, Object o) {
		
		if(o instanceof Packet0LoginRequest) {
			Packet1LoginAnswer loginAnswer = new Packet1LoginAnswer();			
			loginAnswer.accepted = true;
			c.sendTCP(loginAnswer);		
			GameHolder.game.run();    //Gameholder class holds the gameclass
		
		}
		
	
}

But it still gives me the error:no opengl context found in current thread

I hope you can help me solve the problem :wink:
-Quexten

In kryonet, the Server and Clients run on their own threads. OpenGL is single threaded, so you have to do any GL calls on the main thread. In other words, if you want to call any functions that will touch GL, you need to do it indirectly from the network threads (add some data to a queue, and have the main thread process that queue every frame)

You can run all your listener methods on the libgdx render thread like this:

Listener listener = new Listener() {
	public void connected (Connection connection) {
		// ...
	}

	public void received (Connection connection, Object object) {
		// ...
	}

	// ...
};

client.addListener(new Listener.QueuedListener(listener) {
	protected void queue (Runnable runnable) {
		Gdx.app.postRunnable(runnable);
	}
});