Hiya everybody,
I’m planning to build a cross platform 3D application in Haskell and I’m thinking about using Regal (https://github.com/p3/regal ) as an abstraction layer so I can support OpenGL 2.x, 3.x, 4.x and ES 2.0 with the same code base. Has any of you have tried to use it with HopenGL / OpenGLRaw?
Cheers,
Jelle
Hi all,
I don't have a github.com account, so reporting here. Hope that's ok.
I found these bugs after Cale posted a link to some problematic
behaviour (which probably failed initially due to lack of an OpenGL
context):
http://lpaste.net/118704
The first bug is lack of error checking in createShader:
---8<---
createShader :: ShaderType -> IO Shader
createShader = fmap Shader . glCreateShader . marshalShaderType
---8<---
http://hackage.haskell.org/package/OpenGL-2.10.0.0/docs/src/Graphics-Render…
glCreateShader returns 0 on error, and using that "not a shader" id for
other calls is bound to cause chaos.
https://www.opengl.org/sdk/docs/man/html/glCreateShader.xhtml
The second bug is much more serious, a lack of error checking in shaderVar:
---8<---
shaderVar :: (GLint -> a) -> GetShaderPName -> Shader -> GettableStateVar a
shaderVar f p shader =
makeGettableStateVar $
alloca $ \buf -> do
glGetShaderiv (shaderID shader) (marshalGetShaderPName p) buf
peek1 f buf
---8<---
http://hackage.haskell.org/package/OpenGL-2.10.0.0/docs/src/Graphics-Render…
glGetShaderiv doesn't modifiy the contents of buf on error. This means
uninitialized memory is read by peek1 and then presumably used by f,
which can cause a crash (in the best case) or wrong/undefined behaviour
(in the worst case).
https://www.opengl.org/sdk/docs/man/html/glGetShader.xhtml
Thanks for reading,
Claude
--
http://mathr.co.uk