Slick2D Shader Crash

I’m using Slick2D’s ShaderProgram for shader-based drawing in my game. Some players report that after 3-10 minutes, the game inevitably crashes hard during what appears to be a setUniform4f operation that’s happened thousands of times before:


[error occurred during error reporting (printing native stack), id 0xc0000005]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J  org.lwjgl.opengl.ARBShaderObjects.nglUniform4fARB(IFFFFJ)V
J  com.zarkonnen.airships.Appearance.draw(Lcom/zarkonnen/catengine/Draw;DDDDILcom/zarkonnen/catengine/util/Clr;Z)V

Why might this happen? Is it a transient problem, or maybe a driver issue? I’m confused that this happens not when the shader is bound, or when textures are set, but at the point of this utterly mundane operation of setting a 4f value. I’m in fact pretty lost here, as I can’t even repro this on any of my own machines.

This is the culprit function in its entirety:


public void draw(Draw d, double x, double y, double w, double h, int ms, Clr tint, boolean flipped) {
if (shaderLoadFailed) {
	drawFallback(d, x, y, w, h, ms, tint, flipped);
	return;
}

if (tex == null) {
	tex = loadTex(SPRITESHEET);
	if (tex == null) {
		shaderLoadFailed = true;
	}
}
if (sp == null) {
	try {
		sp = ShaderProgram.loadProgram(
				AGame.getGameDirectoryPath("data/passthrough.vert"),
				AGame.getGameDirectoryPath("data/frag.frag"));
	} catch (Exception e) {
		e.printStackTrace();
		shaderLoadFailed = true;
	}
}

if (shaderLoadFailed) { return; }

sp.bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID());
sp.setUniform1i("tex", 0);
if (tint == null) {
	sp.setUniform4f("tint", 1.0f, 1.0f, 1.0f, 1.0f);
} else {
	sp.setUniform4f("tint", tint.r / 255.0f, tint.g / 255.0f, tint.b / 255.0f, 1.0f);
}

Img img = frames.get((ms / interval) % frames.size());

glBegin(GL_QUADS);
if (flipped ^ isFlipped) {
	glTexCoord2d(img.srcX, img.srcY);
	glVertex2d(x + w, y);
	glTexCoord2d(img.srcX, img.srcY + img.srcHeight);
	glVertex2d(x + w, y + h);
	glTexCoord2d(img.srcX + img.srcWidth, img.srcY + img.srcHeight);
	glVertex2d(x, y + h);
	glTexCoord2d(img.srcX + img.srcWidth, img.srcY);
	glVertex2d(x, y);
} else {
	glTexCoord2d(img.srcX, img.srcY);
	glVertex2d(x, y);
	glTexCoord2d(img.srcX, img.srcY + img.srcHeight);
	glVertex2d(x, y + h);
	glTexCoord2d(img.srcX + img.srcWidth, img.srcY + img.srcHeight);
	glVertex2d(x + w, y + h);
	glTexCoord2d(img.srcX + img.srcWidth, img.srcY);
	glVertex2d(x + w, y);
}
glEnd();
sp.unbind();
TextureImpl.bindNone();
}

And the shaders FWIW:

passthrough.vert


void main() {
   gl_TexCoord[0] = gl_MultiTexCoord0;
   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

frag.frag


uniform sampler2D tex;
uniform vec4 tint;

void main(void) {    
	gl_FragColor = texture2D(tex, floor(gl_TexCoord[0].st) / 1024.0) * tint;
}

As you can see, there’s very little to them.

To be honest, what concerns me is the error message.

  1. I’ve never seen a an error printing the native stack.
  2. The stack trace doesn’t make sense.

this function “org.lwjgl.opengl.ARBShaderObjects.nglUniform4fARB(IFFFFJ)V” is not called in the source you have shown us. The method you are calling is “setUniform4f()” in ShaderProgram.

Ah, I can explain!

  1. It’s an error.pid trace. The program crashed in native code.
  2. The disjoint between the function called and the function in the trace is because the JVM optimized out intermediate function calls. So setUniform4f calls nglUniform4fARB.

It could be either

  1. a driver bug or
  2. a bug in some code causing glUniform4f() to somehow read outside of the program’s memory, causing an access violation error.

Could you show us the entire crash dump file?

  1. I know it is a crash in native code. That much is evident, I meant that I’ve never seen it (Windows?) fail to print the native stack trace.
  2. Whilst the JVM may or may not optimize out deferred function calls, 99% of the time you will never see it in debugging, and the other 1% of the time, it is usually to do with implicit anonymous classes or automatic (un)boxing and the like.

I’m inclined to agree with @theagentd btw. Smells like a driver bug, random intermittent crashes in a function called repetitively in the same context. Try searching online to see if the graphics cards have any known problems.