treeform / boxy

2D GPU rendering with a tiling atlas.
MIT License
102 stars 7 forks source link

boxy.grow can overgrow and corrupt existing texture #60

Closed viralpoetry closed 11 months ago

viralpoetry commented 12 months ago

hello, while loading multiple images to boxy I found out, that once boxy calls grow procedure that doubles texture size, at certain point it will overgrow supported hardware size and fail with OpenGL error. I can catch it as an exception however it will corrupt existing texture and all images once rendered are have glitches.

Please, is there any mechanism to prevent the corruption? Or, indirectly, to prevent overgrowing the texture?

Error once it happens:

/.nimble/pkgs/boxy-0.4.1/boxy.nim(413) addImage
/.nimble/pkgs/boxy-0.4.1/boxy.nim(356) takeFreeTile
/.nimble/pkgs/boxy-0.4.1/boxy.nim(329) grow
/.nimble/pkgs/boxy-0.4.1/boxy.nim(147) createAtlasTexture
/.nimble/pkgs/boxy-0.4.1/boxy/textures.nim(53) bindTextureData
/.nimble/pkgs/opengl-1.2.6/opengl/private/errors.nim(44) glTexImage2D
/.nimble/pkgs/opengl-1.2.6/opengl/private/errors.nim(99) checkGLerror
Error: unhandled exception: OpenGL error: invalid value [GLerror]

This code is showing max size for my PC:

var intBuffer: GLint
glGetIntegerv(GL_MAX_TEXTURE_SIZE, intBuffer.addr)
echo intBuffer.GLuint
# RESULT in my case = 16384
treeform commented 11 months ago

Thank you for the bug report! I now raise a proper exception.

viralpoetry commented 11 months ago

Thank you for the quick fix, will try new version.