Fix #108243: Crash when save before close with modified image

A mistake in the recent API refactor for the buffer sharing.

Pull Request: https://projects.blender.org/blender/blender/pulls/108259
This commit is contained in:
Sergey Sharybin
2023-05-25 09:59:23 +02:00
committed by Sergey Sharybin
parent 0e7b81dd32
commit f669f6cd8c
3 changed files with 5 additions and 2 deletions

View File

@@ -1352,8 +1352,8 @@ static bool image_memorypack_imbuf(
ImagePackedFile *imapf;
PackedFile *pf = MEM_cnew<PackedFile>("PackedFile");
pf->data = IMB_steal_encoded_buffer(ibuf);
pf->size = ibuf->encoded_size;
pf->data = IMB_steal_encoded_buffer(ibuf);
imapf = static_cast<ImagePackedFile *>(MEM_mallocN(sizeof(ImagePackedFile), "Image PackedFile"));
STRNCPY(imapf->filepath, filepath);

View File

@@ -179,7 +179,8 @@ void IMB_make_writable_byte_buffer(struct ImBuf *ibuf);
void IMB_make_writable_float_buffer(struct ImBuf *ibuf);
/* Steal the buffer data pointer: the ImBuf is no longer an owner of this data.
* NOTE: If the ImBuf does not own the data the behavior is undefined. */
* NOTE: If the ImBuf does not own the data the behavior is undefined.
* NOTE: Stealing encoded buffer resets the encoded size. */
uint8_t *IMB_steal_byte_buffer(struct ImBuf *ibuf);
float *IMB_steal_float_buffer(struct ImBuf *ibuf);
uint8_t *IMB_steal_encoded_buffer(struct ImBuf *ibuf);

View File

@@ -100,6 +100,7 @@ bool imb_alloc_buffer(
}
buffer.ownership = IB_TAKE_OWNERSHIP;
buffer.implicit_sharing = nullptr;
return true;
}
@@ -416,6 +417,7 @@ bool imb_enlargeencodedbufferImBuf(ImBuf *ibuf)
imb_free_buffer(ibuf->encoded_buffer);
ibuf->encoded_buffer = new_buffer;
ibuf->encoded_buffer_size = newsize;
ibuf->flags |= IB_mem;