LWJGL3 EXCEPTION_ACCESS_VIOLATION while calling glTexImage2D

0

I was trying to load and display a simple texture with lwjgl3, but whenever I call glTexImage2D I get an EXCEPTION_ACCESS_VIOLATION.

I've made a small example, replacing the loading code with a red 8x8 texture:

Texture.java:

package tabaqui.lwjgl;

import java.nio.ByteBuffer;

import org.lwjgl.opengl.GL11;

public class Texture {

    private int id;
    private int w;
    private int h;

    public Texture(ByteBuffer data, int w, int h) {
        this.w = w;
        this.h = h;
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        id = GL11.glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, w, h, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data);
    }

    public int getId() {
        return id;
    }

    public int getW() {
        return w;
    }

    public int getH() {
        return h;
    }
}

Game.java:

package tabaqui;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;

import tabaqui.lwjgl.Texture;

public class Game {

    private long id;

    private Texture t;

    public static final String TITLE = "Texture test";
    public static final int W = 640;
    public static final int H = 480;

    public void create() {
        int w = 8;
        int h = 8;
        ByteBuffer bb = ByteBuffer.allocate(w * h * 4);
        for (int y = 0; y < h; y++)
            for (int x = 0; x < w; x++) {
                bb.put((byte)0xff); // R
                bb.put((byte)0x00); // G
                bb.put((byte)0x00); // B
                bb.put((byte)0xff); // A
            }
        bb.flip();
        t = new Texture(bb, w, h);
    }

    public void render() {
        // TODO
    }

    public void dispose() {
        GL11.glDeleteTextures(t.getId());
    }

    public void start() {
        // GLFW init
        GLFWErrorCallback.createPrint(System.err).set();
        if (!GLFW.glfwInit())
            throw new RuntimeException("[GLFW] glfwInit error");
        GLFW.glfwDefaultWindowHints();
        GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE);
        GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GLFW.GLFW_FALSE);
        id = GLFW.glfwCreateWindow(W, H, TITLE, MemoryUtil.NULL, MemoryUtil.NULL);
        if (id == MemoryUtil.NULL)
            throw new RuntimeException("[GLFW] glfwCreateWindow error");
        try (MemoryStack stack = MemoryStack.stackPush()) {
            IntBuffer pw = stack.mallocInt(1);
            IntBuffer ph = stack.mallocInt(1);
            GLFW.glfwGetWindowSize(id, pw, ph);
            GLFWVidMode vm = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
            GLFW.glfwSetWindowPos(id, (vm.width() - pw.get(0)) / 2, (vm.height() - ph.get(0)) / 2);
        }
        GLFW.glfwMakeContextCurrent(id);
        GLFW.glfwSwapInterval(1);
        GLFW.glfwShowWindow(id);
        // OpenGL init
        GL.createCapabilities();
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        GL11.glViewport(0, 0, W, H);
        GL11.glOrtho(0, W, H, 0, 1, -1);
        GL11.glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
        create();
        // Game loop
        while (!GLFW.glfwWindowShouldClose(id)) {
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
            render();
            GLFW.glfwSwapBuffers(id);
            GLFW.glfwPollEvents();
        }
        dispose();
    }

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

Whenever I run my program I get the following message:

A fatal error has been detected by the Java Runtime Environment:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000644c34b9, pid=27816, tid=12096

JRE version: Java(TM) SE Runtime Environment (11.0.1+13) (build 11.0.1+13-LTS) Java VM: Java HotSpot(TM) 64-Bit Server VM (11.0.1+13-LTS, mixed mode, tiered, compressed oops, g1 gc, windows-amd64) Problematic frame: C [nvoglv64.DLL+0xd634b9]

No core dump will be written. Minidumps are not enabled by default on client versions of Windows

An error report file with more information is saved as: C:\Users\Marco\eclipse-workspace\GameLw3\hs_err_pid27816.log

If you would like to submit a bug report, please visit: http://bugreport.java.com/bugreport/crash.jsp The crash happened outside the Java Virtual Machine in native code. See problematic frame for where to report the bug.

Am i missing something?

java
opengl
lwjgl
access-violation
texture2d
asked on Stack Overflow May 1, 2019 by Tabaqui • edited May 1, 2019 by Rumit Patel

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0