• Register
0 votes
249 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 132 views
132 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 585 views
585 views
Problem : I am getting the run time exception in my program while I am reading a file through a Scanner. exception in thread "main" java.util.nosuchelementexception: no line found
asked Oct 23, 2019 peterlaw 6.9k points
0 votes
1 answer 3 views
0 votes
1 answer 17 views
17 views
Problem: I have a fragment I am trying to add into a view. FragmentManager fragMgr=getSupportFragmentManager(); feed_parser_activity content = (feed_parser_activity)fragMgr .findFragmentById(R.id.feedContentContainer); FragmentTransaction xaction=fragMgr.beginTransaction(); if ... setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .addToBackStack(null) .commit(); Log.e("Abstract", "DONE"); }
asked Dec 6, 2020 Mashhoodch 5.6k points
0 votes
1 answer 25 views
25 views
I got these errors.... Any one have some hint..?
asked Dec 7, 2020 TeamScript 9.5k points
0 votes
1 answer 3 views
3 views
Please help me.
asked 22 hours ago TeamScript 9.5k points
0 votes
1 answer 5 views
5 views
Thank you in advance for any help?
asked Jan 5 TeamScript 9.5k points
0 votes
1 answer 8 views
8 views
Help me by solving this problem.
asked Jan 2 TeamScript 9.5k points