Skip to content

Commit

Permalink
[rtextures] LoadTextureCubemap(): Copy image before generating mipmap…
Browse files Browse the repository at this point in the history
…s, to avoid dangling re-allocated pointers (#4439)
  • Loading branch information
Not-Nik authored Oct 26, 2024
1 parent ff66b49 commit 38cf9f3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/rtextures.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 38cf9f3

Please sign in to comment.