• Register
0 votes
307 views

Problem :

I am working on a card game, and currently running into an error when I run it in eclipse. I am also using slick 2d.

Here is the error

java.lang.runtimeexception: no opengl context found in the current thread.

6 5 3
6,930 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

Depending on which LWJGL you're using, init your Display as shown bellow:

LWJGL 3 

if (!glfwInit()) {
   throw new IllegalStateException("Can't init GLFW");
}

LWJGL 2:

try {
   Display.setDisplayMode(new DisplayMode(800, 600));
   Display.create();
} catch (LWJGLException ex) {
   Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}

Please dont forget Display.create() .

Further Readings:

https://github.com/nifty-gui/nifty-gui/issues/111

9 7 4
38,600 points
0 votes

Solution:

This kind of error is common for LWJGL starters. The OpenGL context gets bound to a thread when it's been created. So you can only access this context from the same thread.

Explanation:

As it does not look that you're working with different threads there might be another cause. Slick2D seems to need a valid OpenGL context for its Image class.

So my first try would be to initialize an OpenGL context before initializing your card images.

Another Reason for occuring this error may be

This happened to me once, and I couldn't figure out what to do until I realized I was calling the image loader before OpenGL had initialized. Make sure that you aren't defining any variables with an image loader in the constructor(or any other method called) before OpenGL inits(what I did).

If you are not able to find solution yet then try this

In lwjgl 3.x and higher

GLContext.createFromCurrent();

If you're using libgdx, there is also

Gdx.app.postRunnable(...)

to post a

Runnable

on the render thread.

 

You can add old thread depending on which LWJGL you're using, init your Display:

LWJGL 3 (uses GLFW):

if (!glfwInit()) {
   throw new IllegalStateException("Can't init GLFW");
}

LWJGL 2:

try {
   Display.setDisplayMode(new DisplayMode(800, 600));
   Display.create();
} catch (LWJGLException ex) {
   Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}

 

Never forget 
Display.create() :)

 

10 6 4
31,120 points

Related questions

0 votes
1 answer 9 views
9 views
Problem: I’m a professional of Java. Recently I'm working on a card game, and currently have a good foundation but I'm running into an error when I run it in eclipse. I'm also using slick 2d. But it showing No OpenGL context found in the current thread. Has anybody seen this kind of problem before? How can I solve it? Thanks.
asked Mar 15 Shovo210 13.9k points
0 votes
1 answer 33 views
33 views
I can't see any errors and as I said, I've run this code before.
asked Jan 24 TeamScript 13.5k points
0 votes
1 answer 4 views
4 views
Problem: I am stuck now .. need some suggestions .. please help me .. How to check opengl version windows 7?
asked Apr 7 Ifra 24.4k points
0 votes
1 answer 4 views
4 views
PROBLEM : Need your help to solve this >'how to tell what opengl version i have' ?
asked Mar 17 Samiur1 38.4k points
0 votes
1 answer 1 view
1 view
Problem: anyone who know this problem please help? exception in thread "main" java.lang.runtimeexception: stub!
asked 5 days ago Rohit kr 16.2k points
0 votes
1 answer 432 views
432 views
Cannot create controller in thread that did not call Looper.prepare () What does the following exception mean? How can I fix it? Here is the code: Toast toast = Toast.makeText (mContext, "Something", Toast.LENGTH_SHORT); This is the exception: Java.lang.RuntimeException: Cannot ... :121)      on Android.widget.Toast. <init> (Toast.Java:68)      on Android.widget.Toast.makeText (Toast.Java:231)
asked Aug 17, 2020 game 4.6k points
0 votes
1 answer 2 views
2 views
Question: Say I have loaded a texture or two and maybe a some shaders, a VAO, a VBO, and I run the program. Say that the program hits some sort of runtime error and terminates before all of those buffer objects and textures can be deleted. Are they stuck in video memory until I restart my computer? I know that java does its own cleanup, but I don't think opengl does, so I'm curious what happens.
asked 2 days ago Atik03 10.1k points
0 votes
1 answer 18 views
18 views
problem: please hel. when i m trying to authenticate my account I m getting this error
asked Mar 22 Sana8989 8.9k points
0 votes
1 answer 8 views
8 views
Problem: I need someone to understand this problem and find out the solution. What language is blender written in? Thanks ..
asked Mar 25 Ifra 24.4k points
0 votes
1 answer 7 views
7 views
Problem: This is a feature of NoSuchMethodError in Java and complains about "main" which is the name of the method that JVM tries to connect to but doesn't find in the wrong class. java.lang.NoSuchMethodError
asked Feb 7 ahmedadel9090 3.1k points