From 4586583ddac25d7abc9394770583a82f6384ba7f Mon Sep 17 00:00:00 2001 From: Not-Nik Date: Sat, 26 Oct 2024 14:00:28 +0200 Subject: [PATCH] [rtextures] LoadTextureCubemap(): Copy image before generating mipmaps, to avoid dangling re-allocated pointers --- src/rtextures.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rtextures.c b/src/rtextures.c index 84144068d15b..92186dd96d01 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -4194,12 +4194,15 @@ TextureCubemap LoadTextureCubemap(Image image, int layout) faces = GenImageColor(size, size*6, MAGENTA); ImageFormat(&faces, image.format); - //ImageMipmaps(&image); // WARNING: image is a copy, it can't be done here, no intention to pass image by reference... + Image mipmapped = ImageCopy(image); + ImageMipmaps(&mipmapped); ImageMipmaps(&faces); // NOTE: Image formatting does not work with compressed textures - for (int i = 0; i < 6; i++) ImageDraw(&faces, image, faceRecs[i], (Rectangle){ 0, (float)size*i, (float)size, (float)size }, WHITE); + for (int i = 0; i < 6; i++) ImageDraw(&faces, mipmapped, faceRecs[i], (Rectangle){ 0, (float)size*i, (float)size, (float)size }, WHITE); + + UnloadImage(mipmapped); } // NOTE: Cubemap data is expected to be provided as 6 images in a single data array,