Skip to content

Commit 38cf9f3

Browse files
authored
[rtextures] LoadTextureCubemap(): Copy image before generating mipmaps, to avoid dangling re-allocated pointers (#4439)
1 parent ff66b49 commit 38cf9f3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/rtextures.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -4194,12 +4194,15 @@ TextureCubemap LoadTextureCubemap(Image image, int layout)
41944194
faces = GenImageColor(size, size*6, MAGENTA);
41954195
ImageFormat(&faces, image.format);
41964196

4197-
//ImageMipmaps(&image); // WARNING: image is a copy, it can't be done here, no intention to pass image by reference...
4197+
Image mipmapped = ImageCopy(image);
4198+
ImageMipmaps(&mipmapped);
41984199
ImageMipmaps(&faces);
41994200

42004201
// NOTE: Image formatting does not work with compressed textures
42014202

4202-
for (int i = 0; i < 6; i++) ImageDraw(&faces, image, faceRecs[i], (Rectangle){ 0, (float)size*i, (float)size, (float)size }, WHITE);
4203+
for (int i = 0; i < 6; i++) ImageDraw(&faces, mipmapped, faceRecs[i], (Rectangle){ 0, (float)size*i, (float)size, (float)size }, WHITE);
4204+
4205+
UnloadImage(mipmapped);
42034206
}
42044207

42054208
// NOTE: Cubemap data is expected to be provided as 6 images in a single data array,

0 commit comments

Comments
 (0)