简体   繁体   English

slick2D游戏项目中的java RuntimeException

[英]java RuntimeException in slick2D game project

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. 但是我得到了这个异常: 线程“ Thread-3”中的异常java.lang.RuntimeException:在当前线程中找不到OpenGL上下文。 What should I do to fix such an exception? 我应该怎么做才能解决这种例外情况?

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). 因为从不同的线程中使用相同的上下文似乎是一个非常糟糕的主意,并且我无法真正想到我想要这样做的情况(它不会提高性能,并使代码难以阅读和维护)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM