I am currently experiencing a jvm crash when calling GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); when the data is generated on a second thread and passed back to the main thread. My project is a voxel based game engine, where I generate the mesh data for each chunk on a separate thread to increase performance. Sometimes when running I will not experience the crash; however, normally it breaks after 5-6 seconds when attempting to store a array in a vbo causing the jvm to crash and report the error included below.
hs_err_pid2608
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffb15f41d74, pid=2608, tid=6544
#
# JRE version: Java(TM) SE Runtime Environment (13.0.1+9) (build 13.0.1+9)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (13.0.1+9, mixed mode, sharing, tiered, compressed oops, g1 gc, windows-amd64)
# Problematic frame:
# C [nvoglv64.dll+0xc81d74]
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# 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.
#
--------------- S U M M A R Y ------------
Command Line: -Dfile.encoding=Cp1252 brass_engine.Main
Host: AMD FX(tm)-6300 Six-Core Processor , 6 cores, 15G, Windows 10 , 64 bit Build 18362 (10.0.18362.329)
Time: Fri Dec 13 22:32:44 2019 Eastern Standard Time elapsed time: 5 seconds (0d 0h 0m 5s)
--------------- T H R E A D ---------------
Current thread (0x0000022407452000): JavaThread "main" [_thread_in_native, id=6544, stack(0x0000006b49700000,0x0000006b49800000)]
Stack: [0x0000006b49700000,0x0000006b49800000], sp=0x0000006b497fe528, free space=1017k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [nvoglv64.dll+0xc81d74]
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J 1050 org.lwjgl.opengl.GL15C.nglBufferData(IJJI)V (0 bytes) @ 0x000002241747ff9e [0x000002241747ff40+0x000000000000005e]
J 1068 c1 content.Content.storeDataInAttributeLists(III[F)V (71 bytes) @ 0x000002240ffb1ca4 [0x000002240ffb0b40+0x0000000000001164]
j content.Content.loadToVAO(Lcontent/mesh/Mesh;[FI[F[F[I)V+17
j content.Content.storeMesh(Lcontent/mesh/Mesh;Lcontent/data/MeshData;)V+49
j content.Content.prepareChunk(Lcontent/thread/ticket/ChunkMeshTicket;)V+16
J 921 c1 content.Content.poll()V (142 bytes) @ 0x0000022410086b3c [0x0000022410085a20+0x000000000000111c]
j brass_engine.Main.<init>()V+181
j brass_engine.Main.main([Ljava/lang/String;)V+3
v ~StubRoutines::call_stub
siginfo: EXCEPTION_ACCESS_VIOLATION (0xc0000005), reading address 0x000002243711e83c
Register to memory mapping:
RIP=0x00007ffb15f41d74 nvoglv64.dll
RAX=0x000002243711e85c is an unknown value
RBX=0x000002243711e83c is an unknown value
RCX=0x000002242e2cf020 points into unknown readable memory: 00 00 7c 42 00 00 40 40
RDX=0x000002243711e83c is an unknown value
RSP=0x0000006b497fe528 is pointing into the stack for thread: 0x0000022407452000
RBP=0x00000000000007c0 is an unknown value
RSI=0x0 is NULL
RDI=0x000002242e2cefc0 points into unknown readable memory: 00 00 7c 42 00 00 80 40
R8 =0x0000000000000020 is an unknown value
R9 =0x000000000000000c is an unknown value
R10=0x0 is NULL
R11=0x0000000000000006 is an unknown value
R12=0x0000000000000030 is an unknown value
R13=0x000000000000000c is an unknown value
R14=0x000000000000004a is an unknown value
R15=0x00007ffb15f5b630 nvoglv64.dll
Registers:
RAX=0x000002243711e85c, RBX=0x000002243711e83c, RCX=0x000002242e2cf020, RDX=0x000002243711e83c
RSP=0x0000006b497fe528, RBP=0x00000000000007c0, RSI=0x0000000000000000, RDI=0x000002242e2cefc0
R8 =0x0000000000000020, R9 =0x000000000000000c, R10=0x0000000000000000, R11=0x0000000000000006
R12=0x0000000000000030, R13=0x000000000000000c, R14=0x000000000000004a, R15=0x00007ffb15f5b630
RIP=0x00007ffb15f41d74, EFLAGS=0x0000000000010246
Top of Stack: (sp=0x0000006b497fe528)
0x0000006b497fe528: 00007ffb15f41a0d 0000000000000000
0x0000006b497fe538: 00000000001ba440 00000000001ba440
0x0000006b497fe548: 0000000000000018 0000000000000018
0x0000006b497fe558: 000000000013a444 000000000007fffc
0x0000006b497fe568: 000002242bf42780 000002242bf3a730
0x0000006b497fe578: 00007ffb15f4a3c6 000002242e2747c0
0x0000006b497fe588: 000000000007fffc 00000224370c403c
0x0000006b497fe598: 000002242bf3a730 00007ffb15f5b630
0x0000006b497fe5a8: 00000224340a54e0 0000006b000001ff
0x0000006b497fe5b8: 00000224340a5401 00000000071947b0
0x0000006b497fe5c8: 0000000006f00000 0000000000000000
0x0000006b497fe5d8: 00000224337ea0f0 00000000ff1fe038
0x0000006b497fe5e8: 0000000000000000 0000000000000000
0x0000006b497fe5f8: 0000000000000000 0000000000000001
0x0000006b497fe608: 0000000000000000 0000000000000000
0x0000006b497fe618: 0000000000000000 0000000000000000
Instructions: (pc=0x00007ffb15f41d74)
0x00007ffb15f41c74: eb 71 48 83 fd 40 72 40 48 8b cd 48 c1 e9 06 48
0x00007ffb15f41c84: 6b c1 c0 48 03 e8 66 0f 1f 44 00 00 0f 10 03 0f
0x00007ffb15f41c94: 10 5b 10 0f 10 53 20 0f 10 4b 30 48 83 c3 40 0f
0x00007ffb15f41ca4: 2b 06 0f 2b 5e 10 0f 2b 56 20 0f 2b 4e 30 48 83
0x00007ffb15f41cb4: c6 40 48 83 e9 01 75 d4 48 83 fd 10 72 22 48 8b
0x00007ffb15f41cc4: cd 48 c1 e9 04 48 6b c1 f0 48 03 e8 0f 10 03 48
0x00007ffb15f41cd4: 83 c3 10 0f 2b 06 48 83 c6 10 48 83 e9 01 75 ec
0x00007ffb15f41ce4: 0f ae f8 48 85 ed 74 0e 4c 8b c5 48 8b d3 48 8b
0x00007ffb15f41cf4: ce e8 f6 b9 31 00 48 8b 5c 24 38 48 8b 6c 24 40
0x00007ffb15f41d04: 48 83 c4 20 5e c3 cc cc cc cc cc cc 4c 8b ca 48
0x00007ffb15f41d14: 8b c1 41 83 e1 0f 83 e0 0f 4d 85 c0 0f 84 e7 00
0x00007ffb15f41d24: 00 00 48 83 c1 20 4d 85 c9 74 6f 48 85 c0 48 8d
0x00007ffb15f41d34: 42 20 74 38 0f 1f 84 00 00 00 00 00 48 8d 49 40
0x00007ffb15f41d44: 0f 10 58 e0 0f 10 50 f0 0f 10 08 0f 10 40 10 48
0x00007ffb15f41d54: 8d 40 40 0f 11 59 a0 0f 11 51 b0 0f 11 49 c0 0f
0x00007ffb15f41d64: 11 41 d0 49 83 e8 01 75 d3 c3 66 90 48 8d 49 40
0x00007ffb15f41d74: 0f 10 58 e0 0f 10 50 f0 0f 10 08 0f 10 40 10 48
0x00007ffb15f41d84: 8d 40 40 0f 11 59 a0 0f 11 51 b0 0f 11 49 c0 0f
0x00007ffb15f41d94: 11 41 d0 49 83 e8 01 75 d3 c3 48 85 c0 48 8d 42
0x00007ffb15f41da4: 20 74 39 66 0f 1f 84 00 00 00 00 00 0f 10 58 e0
0x00007ffb15f41db4: 48 8d 49 40 0f 10 50 f0 0f 10 08 0f 10 40 10 48
0x00007ffb15f41dc4: 8d 40 40 0f 11 59 a0 0f 11 51 b0 0f 11 49 c0 0f
0x00007ffb15f41dd4: 11 41 d0 49 83 e8 01 75 d3 c3 66 90 0f 10 58 e0
0x00007ffb15f41de4: 48 8d 49 40 0f 10 50 f0 0f 10 08 0f 10 40 10 48
0x00007ffb15f41df4: 8d 40 40 0f 11 59 a0 0f 11 51 b0 0f 11 49 c0 0f
0x00007ffb15f41e04: 11 41 d0 49 83 e8 01 75 d3 c3 cc cc 48 89 4c 24
0x00007ffb15f41e14: 08 53 55 56 57 41 54 41 55 41 56 41 57 48 81 ec
0x00007ffb15f41e24: c8 00 00 00 48 8b 01 4c 8b e9 49 8b 7d 08 4d 8b
0x00007ffb15f41e34: 55 10 48 8b 08 45 8b 5d 58 41 8b 55 5c 45 8b 45
0x00007ffb15f41e44: 60 45 8b 65 50 45 03 c3 8b 87 a4 05 00 00 45 2b
0x00007ffb15f41e54: e3 8b 9f 9c 05 00 00 03 c3 44 8b 8f a0 05 00 00
0x00007ffb15f41e64: 8b af a8 05 00 00 45 8b ba a4 05 00 00 41 03 e9
Stack slot to memory mapping:
stack at sp + 0 slots: 0x00007ffb15f41a0d nvoglv64.dll
stack at sp + 1 slots: 0x0 is NULL
stack at sp + 2 slots: 0x00000000001ba440 is an unknown value
stack at sp + 3 slots: 0x00000000001ba440 is an unknown value
stack at sp + 4 slots: 0x0000000000000018 is an unknown value
stack at sp + 5 slots: 0x0000000000000018 is an unknown value
stack at sp + 6 slots: 0x000000000013a444 is an unknown value
stack at sp + 7 slots: 0x000000000007fffc is an unknown value
main game loop
while(!GLFW.glfwWindowShouldClose(Display.window)) {
boolean shouldRender = true;
long now = System.nanoTime();
unprocessed += (now - lastTime) / nsPerTick;
lastTime = now;
while (unprocessed >= 1) { // fixed update 60 times per second.
currentTick = System.nanoTime();
deltaTime = (currentTick / 1000000000.0) - (lastTick / 1000000000.0);
lastTick = currentTick;
GLFW.glfwPollEvents();
Input.pollInputs();
// check if the screen size has changed.
Display.updateBuffers();
Renderer.camera.update();
// if Content.poll() is here it will not crash, but runs badly.
tick(deltaTime);
ticks++;
unprocessed -= 1;
shouldRender = true;
}
Content.poll(); // this is where the content.poll() should be, but causes crashes.
// if possible try to sleep to share resources.
try {
Thread.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(shouldRender) {
render();
frames++;
}
code to store mesh data
private static void loadToVAO(Mesh mesh, float[] positions, int floatsPerPosition, float[] textureCoords, float[] normals, int[] indices) {
int vao = createVAO();
bindIndicesBuffer(vao, indices);
storeDataInAttributeLists(vao, 0, floatsPerPosition, positions);
storeDataInAttributeLists(vao, 1, 2, textureCoords);
storeDataInAttributeLists(vao, 2, 3, normals);
unbindVAO();
mesh.vao = vao;
mesh.vertexCount = indices.length;
}
private static int createVAO() {
int vao = GL30.glGenVertexArrays();
vaos.put(vao, new ArrayList<Integer>());
GL30.glBindVertexArray(vao);
return vao;
}
private static void storeDataInAttributeLists(int vao, int attributeNumber, int coordinateSize, float[] data) {
int vbo = GL15.glGenBuffers();
vaos.get(vao).add(vbo);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
FloatBuffer buffer = storeDataInFloatBuffer(data);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); // THIS IS WHERE IT CRASHES
GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}
private static FloatBuffer storeDataInFloatBuffer(float[] data) {
FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
buffer.put(data);
buffer.flip();
return buffer;
}
private static void unbindVAO() {
GL30.glBindVertexArray(0);
}
private static void bindIndicesBuffer(int vao, int[] indices) {
int vbo = GL15.glGenBuffers();
vaos.get(vao).add(vbo);
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vbo);
IntBuffer buffer = storeDataInIntBuffer(indices);
GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
}
private static IntBuffer storeDataInIntBuffer(int[] data) {
IntBuffer buffer = BufferUtils.createIntBuffer(data.length);
buffer.put(data);
buffer.flip();
return buffer;
}
mesh data class each of these fields are sent to the above loadToVao and this data is passed through a volatile LinkedList acting as an queue for finished work.
public class MeshData extends ContentData {
public volatile float[] positions;
public volatile float[] textureCoords;
public volatile float[] normals;
public volatile int[] indices;
public volatile int floatsPerPosition = 3;
public MeshData(float[] positions, int floatsPerPosition, float[] textureCoords, float[] normals, int[] indices) {
this.positions = positions;
this.floatsPerPosition = floatsPerPosition;
this.textureCoords = textureCoords;
this.normals = normals;
this.indices = indices;
}
}
If anyone knows why I might be experience this seemingly random crash please help. Sorry if this is very complicated, first post and i've been working on this issue for longer than I care to admit.
User contributions licensed under CC BY-SA 3.0