Fix T73559: UDIM Crash Fill Tile
The function `gpu_texture_create_tile_array` checked for a valid tile ibuf when determining the packing location. During the actual packaging it didn't. As the tiles are already ignored when selecting the packing location, we can also ignore it when copying it to the glTexture. Therefore this patch removes the existing BLI_assert and replaces it with a NULL check. Reviewed By: Brecht van Lommel Differential Revision: https://developer.blender.org/D6738
This commit is contained in:
parent
831bb6bc77
commit
d237681cad
Notes:
blender-bot
2023-02-14 03:03:03 +01:00
Referenced by issue #73559, Crash after using Fill Tile in saved blend file
|
@ -363,85 +363,85 @@ static uint gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf)
|
|||
BKE_imageuser_default(&iuser);
|
||||
iuser.tile = tile->tile_number;
|
||||
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
|
||||
BLI_assert(ibuf != NULL);
|
||||
|
||||
bool needs_scale = (ibuf->x != tilesize[0] || ibuf->y != tilesize[1]);
|
||||
if (ibuf) {
|
||||
bool needs_scale = (ibuf->x != tilesize[0] || ibuf->y != tilesize[1]);
|
||||
|
||||
ImBuf *scale_ibuf = NULL;
|
||||
if (ibuf->rect_float) {
|
||||
float *rect_float = ibuf->rect_float;
|
||||
ImBuf *scale_ibuf = NULL;
|
||||
if (ibuf->rect_float) {
|
||||
float *rect_float = ibuf->rect_float;
|
||||
|
||||
const bool store_premultiplied = ima->alpha_mode != IMA_ALPHA_STRAIGHT;
|
||||
if (ibuf->channels != 4 || !store_premultiplied) {
|
||||
rect_float = MEM_mallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, __func__);
|
||||
IMB_colormanagement_imbuf_to_float_texture(
|
||||
rect_float, 0, 0, ibuf->x, ibuf->y, ibuf, store_premultiplied);
|
||||
const bool store_premultiplied = ima->alpha_mode != IMA_ALPHA_STRAIGHT;
|
||||
if (ibuf->channels != 4 || !store_premultiplied) {
|
||||
rect_float = MEM_mallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, __func__);
|
||||
IMB_colormanagement_imbuf_to_float_texture(
|
||||
rect_float, 0, 0, ibuf->x, ibuf->y, ibuf, store_premultiplied);
|
||||
}
|
||||
|
||||
float *pixeldata = rect_float;
|
||||
if (needs_scale) {
|
||||
scale_ibuf = IMB_allocFromBuffer(NULL, rect_float, ibuf->x, ibuf->y, 4);
|
||||
IMB_scaleImBuf(scale_ibuf, tilesize[0], tilesize[1]);
|
||||
pixeldata = scale_ibuf->rect_float;
|
||||
}
|
||||
|
||||
glTexSubImage3D(GL_TEXTURE_2D_ARRAY,
|
||||
0,
|
||||
tileoffset[0],
|
||||
tileoffset[1],
|
||||
tilelayer,
|
||||
tilesize[0],
|
||||
tilesize[1],
|
||||
1,
|
||||
GL_RGBA,
|
||||
GL_FLOAT,
|
||||
pixeldata);
|
||||
|
||||
if (rect_float != ibuf->rect_float) {
|
||||
MEM_freeN(rect_float);
|
||||
}
|
||||
}
|
||||
else {
|
||||
unsigned int *rect = ibuf->rect;
|
||||
|
||||
float *pixeldata = rect_float;
|
||||
if (needs_scale) {
|
||||
scale_ibuf = IMB_allocFromBuffer(NULL, rect_float, ibuf->x, ibuf->y, 4);
|
||||
IMB_scaleImBuf(scale_ibuf, tilesize[0], tilesize[1]);
|
||||
pixeldata = scale_ibuf->rect_float;
|
||||
if (!IMB_colormanagement_space_is_data(ibuf->rect_colorspace)) {
|
||||
rect = MEM_mallocN(sizeof(uchar) * 4 * ibuf->x * ibuf->y, __func__);
|
||||
IMB_colormanagement_imbuf_to_byte_texture((uchar *)rect,
|
||||
0,
|
||||
0,
|
||||
ibuf->x,
|
||||
ibuf->y,
|
||||
ibuf,
|
||||
internal_format == GL_SRGB8_ALPHA8,
|
||||
ima->alpha_mode == IMA_ALPHA_PREMUL);
|
||||
}
|
||||
|
||||
unsigned int *pixeldata = rect;
|
||||
if (needs_scale) {
|
||||
scale_ibuf = IMB_allocFromBuffer(rect, NULL, ibuf->x, ibuf->y, 4);
|
||||
IMB_scaleImBuf(scale_ibuf, tilesize[0], tilesize[1]);
|
||||
pixeldata = scale_ibuf->rect;
|
||||
}
|
||||
glTexSubImage3D(GL_TEXTURE_2D_ARRAY,
|
||||
0,
|
||||
tileoffset[0],
|
||||
tileoffset[1],
|
||||
tilelayer,
|
||||
tilesize[0],
|
||||
tilesize[1],
|
||||
1,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
pixeldata);
|
||||
|
||||
if (rect != ibuf->rect) {
|
||||
MEM_freeN(rect);
|
||||
}
|
||||
}
|
||||
|
||||
glTexSubImage3D(GL_TEXTURE_2D_ARRAY,
|
||||
0,
|
||||
tileoffset[0],
|
||||
tileoffset[1],
|
||||
tilelayer,
|
||||
tilesize[0],
|
||||
tilesize[1],
|
||||
1,
|
||||
GL_RGBA,
|
||||
GL_FLOAT,
|
||||
pixeldata);
|
||||
|
||||
if (rect_float != ibuf->rect_float) {
|
||||
MEM_freeN(rect_float);
|
||||
if (scale_ibuf != NULL) {
|
||||
IMB_freeImBuf(scale_ibuf);
|
||||
}
|
||||
}
|
||||
else {
|
||||
unsigned int *rect = ibuf->rect;
|
||||
|
||||
if (!IMB_colormanagement_space_is_data(ibuf->rect_colorspace)) {
|
||||
rect = MEM_mallocN(sizeof(uchar) * 4 * ibuf->x * ibuf->y, __func__);
|
||||
IMB_colormanagement_imbuf_to_byte_texture((uchar *)rect,
|
||||
0,
|
||||
0,
|
||||
ibuf->x,
|
||||
ibuf->y,
|
||||
ibuf,
|
||||
internal_format == GL_SRGB8_ALPHA8,
|
||||
ima->alpha_mode == IMA_ALPHA_PREMUL);
|
||||
}
|
||||
|
||||
unsigned int *pixeldata = rect;
|
||||
if (needs_scale) {
|
||||
scale_ibuf = IMB_allocFromBuffer(rect, NULL, ibuf->x, ibuf->y, 4);
|
||||
IMB_scaleImBuf(scale_ibuf, tilesize[0], tilesize[1]);
|
||||
pixeldata = scale_ibuf->rect;
|
||||
}
|
||||
glTexSubImage3D(GL_TEXTURE_2D_ARRAY,
|
||||
0,
|
||||
tileoffset[0],
|
||||
tileoffset[1],
|
||||
tilelayer,
|
||||
tilesize[0],
|
||||
tilesize[1],
|
||||
1,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
pixeldata);
|
||||
|
||||
if (rect != ibuf->rect) {
|
||||
MEM_freeN(rect);
|
||||
}
|
||||
}
|
||||
|
||||
if (scale_ibuf != NULL) {
|
||||
IMB_freeImBuf(scale_ibuf);
|
||||
}
|
||||
|
||||
BKE_image_release_ibuf(ima, ibuf, NULL);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue