PDA

View Full Version : Crash if app ends without delete uniform buffer



Leadwerks
04-09-2008, 02:47 PM
I use a uniform buffer for GPU instancing. If I delete the uniform buffer before ending the program, everything is fine. If I do not delete the buffer, my program freezes. This is on an 8800 GTS, and has been happening for six months.

Leadwerks
04-10-2008, 12:20 AM
The uniform buffer is bound to some shaders.

If I detach the uniform buffer from the shaders before closing the program, the crash does not occur.

Here's the really bad part:
If I use a full-screen graphics window and the user hits the window key to minimize my window, the program freezes up, just like if I end the program without detaching the uniform buffer.

I was able to reproduce the crash in a minimal program:
http://www.leadwerks.com/post/crash.zip

The second problem is the one I am really worried about. I can work around the first. Here is the source code to produce the second error. I have used GPU instancing extensively. If there was something I was doing that was fundamentally wrong, I think I would not be able to use instancing. The second error will only occur if all of the conditions below are met:
-A shader is enabled and bound to uniform buffer
-A triangle is drawn
-Data is sent to the uniform buffer

Otherwise no crash will occur.

Strict

Framework brl.GLGraphics
Import leadwerks.glewex
Import brl.standardio

AppTitle=StripAll(AppFile)

Notify "Try hitting the windows key to go back to the desktop once the program starts. You might have to go back and forth a few times."

SetGraphicsDriver GLGraphicsDriver()
Graphics 640,480,32
glewexinit()

Local source$=LoadString("shader.vert")

Local program=glCreateProgramObjectARB()

Local vertObject=glCreateShaderObjectARB(GL_VERTEX_SHADE R_ARB)
Local hsource:Byte Ptr
hsource=source.tocstring()
glShaderSourceARB(vertObject,1,Varptr hsource,Null)
MemFree hsource
glCompileShaderARB vertObject

Local result
glGetObjectParameterivARB(vertObject,GL_OBJECT_COM PILE_STATUS_ARB,Varptr result)
If result
Print "Compiled vert object"
Else
Print "Failed to compile"
Print GLShaderObjectLog(vertObject)
End
EndIf

glAttachObjectARB program,vertObject

glLinkProgramARB program

glGetObjectParameterivARB(program,GL_OBJECT_LINK_S TATUS_ARB,Varptr result)
If result
Print "Linked program"
Print GLShaderObjectLog(program)
Else
Print "Failed to link shader program."
Print GLShaderObjectLog(program)
End
EndIf

Local InstancingMatrixBuffer

Local uniform_InstanceMatrix=glGetUniformLocation(progra m,"InstanceMatrix")
If uniform_InstanceMatrix=-1
Print "bindable uniform not found."
End
Else

glgenbuffersarb 1,Varptr InstancingMatrixBuffer
glBindBufferARB GL_UNIFORM_BUFFER_EXT,InstancingMatrixBuffer
glBindBufferARB GL_UNIFORM_BUFFER_EXT,0

glBindBufferARB GL_UNIFORM_BUFFER_EXT,InstancingMatrixBuffer
glUniformBufferEXT program,uniform_InstanceMatrix,InstancingMatrixBuf fer
glBindBufferARB GL_UNIFORM_BUFFER_EXT,0
EndIf

glUseProgramObjectARB program

Local data:Float[16]

While Not KeyHit(KEY_ESCAPE)

If glgeterror() RuntimeError "OpenGL Error."

glBindBufferARB GL_UNIFORM_BUFFER_EXT,InstancingMatrixBuffer
glBufferDataARB GL_UNIFORM_BUFFER_EXT,64,data,GL_STATIC_READ

glbegin GL_TRIANGLES
glvertex3f 1,0,0
glvertex3f 0,0,2
glvertex3f 1,2,0
glend

glBindBufferARB GL_UNIFORM_BUFFER_EXT,0

Flip 1
Wend

Function GLShaderObjectLog$(obj)
Local slen:Int = 0
Local clog:Byte[10204]
glGetInfoLogARB(obj,clog.length-1,Varptr slen,Varptr clog[0])
Local err:String
Local i:Int
slen=Min(clog.length-1,slen)
For i = 0 To slen-1
err:+Chr(clog[i])
Next
Return err.Trim()
EndFunction

Here is shader.vert:

#extension GL_EXT_gpu_shader4 : enable
#extension GL_EXT_bindable_uniform : enable
bindable uniform mat4 InstanceMatrix[ 32 ];

void main() {
gl_Position=InstanceMatrix[0] * gl_Vertex;
}

V-man
04-10-2008, 07:12 PM
I did not get any crash. I tried running crash.bat crash2.bat
I have 8600 with Vista 32 bit. I had 156.55, no problem.
I upgraded to 174.31, no problem.

Leadwerks
04-10-2008, 11:22 PM
I am running WindowsXP Pro with an 8800 GTS and drivers 169.25.

Nigel over at NVidia responded to my post there, so hopefully they are looking at this now.

Thanks for trying it.