Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java GLFW引擎和主线程发出IntelliJ_Java_Macos_Intellij Idea_Lwjgl - Fatal编程技术网

Java GLFW引擎和主线程发出IntelliJ

Java GLFW引擎和主线程发出IntelliJ,java,macos,intellij-idea,lwjgl,Java,Macos,Intellij Idea,Lwjgl,我正在使用MacOSX。我的IDE是Intellij。由于某些原因,我在尝试运行此代码时出错。代码是一个lwjgl游戏引擎 import org.lwjgl.glfw.*; import org.lwjgl.opengl.*; import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.system.MemoryUtil.*; import static

我正在使用MacOSX。我的IDE是Intellij。由于某些原因,我在尝试运行此代码时出错。代码是一个lwjgl游戏引擎

import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;

import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.glfw.Callbacks.*;
import org.lwjgl.*;

import java.awt.*;
import java.util.*;
import java.text.DateFormat;
import java.applet.Applet;

public class Main implements Runnable{

private int width = 1280;
private int height =720;
private String title = "Flappy";

private boolean running = false;
private Thread thread;
private long window;

public void start(){
    running = true;

    thread = new Thread(this, "Display");
    //this will call the run method that we created below by using our implemented Runnable
    thread.start();
}

public void run(){
    init();
    running = true;
      while(running){
        update();
        render();
        if(glfwWindowShouldClose(window)){
            running = false;
        }
    }
}

//init initializes all of our stuff
private void init(){

    if(!glfwInit()){
        throw new IllegalStateException("Unable to initialize GLFW YOOO");
    }

    // Configure our window
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // the window will stay hidden after creation
    glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // the window will be resizable

    window = glfwCreateWindow(width, height, title, NULL, NULL);

    if(window == NULL){
        throw new RuntimeException("Failed to create the GLFW window");
    }


    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
    // Make the OpenGL context current
    glfwMakeContextCurrent(window);
    // Enable v-sync
    glfwSwapInterval(1);

    // Make the window visible
    glfwShowWindow(window);

}



public void update(){
    glfwPollEvents();
}

public void render(){
    glfwSwapBuffers(window);
}


public static void main(String[] args){
    new Main().start();
}
}
在阅读一些帖子时,我尝试添加-xstartonfirsthread来编辑Configure和program参数,但没有帮助。我的错误如下。如果有人能帮忙,谢谢。。。再次使用带有Intellij的Mac。下面添加了错误:

Caused by: java.lang.IllegalStateException: GLFW windows may only be created on the main thread and that thread must be the first thread in the process. Please run the JVM with -XstartOnFirstThread. For offscreen rendering, make sure another window toolkit (e.g. AWT or JavaFX) is initialized before GLFW.

您得到的异常非常清楚这个问题,您的
init()
方法调用
glfwCreateWindow()
来创建
GLFW窗口
应该从
主线程调用。因此,将您的
init()
方法公开,并删除
init()
run()方法中调用。相反,把你的主要方法改成这个

public static void main(String[] args){
   Main main = new Main();
   main.init();
   main.start();
}

我在Intellij 2017.1.3中遇到了相同的错误;macos10.12.4;lwjgl-release-3.1

通过单击菜单-运行->编辑配置解决此问题。。。然后将参数-XstartOnFirstThread添加到VM选项旁边的文本框中:

丝网印刷:

可能重复的内容如何才能更具体?这个问题在另一篇文章中得到了解决,我在那里提供的答案是不言自明的。我将它改为在主线程上运行。我把它和这里展示的一模一样:还是一样error@NikBabinchuk您是否注意到“警告:下面的代码需要最新的夜间构建才能编译和运行”链接?我不认为你正在使用最新的夜间构建。那么f'n解决方案是什么呢?我把它改回了上面的代码,去掉了我创建的线程,在主线程上运行所有的东西。仍然会得到相同的错误。。。。。