From 17d6ccc32db6609bd01ace39f00ca3a907e6bce4 Mon Sep 17 00:00:00 2001 From: Alberto Torres Date: Tue, 10 Sep 2024 00:57:16 +0200 Subject: [PATCH] Fix missing `tex_type` in one of `newTexture`. Prevent nil access in `destroy`. --- src/graphics/texture.nim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/graphics/texture.nim b/src/graphics/texture.nim index c4cedec..c1638d4 100644 --- a/src/graphics/texture.nim +++ b/src/graphics/texture.nim @@ -329,8 +329,9 @@ proc unbindAllTextures*() = next_texture = 0 proc destroy*(texture: Texture) = - texture.unbind() - texture.freeTextureStorage() + if texture.storage != nil: + texture.unbind() + texture.freeTextureStorage() proc loadFromPixelsPointer*(self: Texture, pixels: pointer) = let ts = self.storage @@ -467,7 +468,7 @@ proc newTexture*(engine: MyouEngine, name: string, file_name: string, is_sRGB: b # TODO: Api that stores the LoadableResource so it can be re-loaded later # note: format does not matter at this point, will be replaced later - let self = engine.newTexture(name, 0, 0, filter=filter, format=RGBA_u8) + let self = engine.newTexture(name, 0, 0, filter=filter, format=RGBA_u8, tex_type=tex_type) self.is_sRGB = is_sRGB var res: LoadableResource proc load(ok: bool, err: string, data: SliceMem[byte]) =