Question

I have created a new thread in a project having this code :

battleStart = new Thread(new Runnable(){
        @Override
        public void run() {
            while(compteur<50){
                BattleStart.draw(0,0);
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {e.printStackTrace();}
                compteur++;
            }
        }
    });

but i got this exception : Exception in thread "Thread-3" java.lang.RuntimeException: No OpenGL context found in the current thread. What should I do to fix such an exception?

Was it helpful?

Solution

You probably can't. Multi-threading (see this thread) is not supported.

You might find a way around it with a lot of custom code (see here and here), but you should first reconsider your design. Is it really necessary to run this code in its own thread? Because it seems like a really bad idea to draw on the same context from different threads and I cannot really think of a situation where I would want to do that (it does not improve performance and makes the code harder to read and maintain).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top