Added support in threaded compositor to copy the viewer
image safely away, prevents crashing especially for
people using blender -E or redrawing viewer while it
composites.

(Note; reloading images in nodes, render result, and
probably other cases have to be checked still)
This commit is contained in:
Ton Roosendaal 2009-01-27 19:32:44 +00:00
parent 92b0cbd6da
commit 764168d62a
3 changed files with 46 additions and 0 deletions

View File

@ -148,6 +148,12 @@ void BKE_image_memorypack(struct Image *ima);
/* prints memory statistics for images */
void BKE_image_print_memlist(void);
/* empty image block, of similar type and filename */
struct Image *BKE_image_copy(struct Image *ima);
/* merge source into dest, and free source */
void BKE_image_merge(struct Image *dest, struct Image *source);
#ifdef __cplusplus
}
#endif

View File

@ -91,6 +91,7 @@
/* quick lookup: supports 1 million frames, thousand passes */
#define IMA_MAKE_INDEX(frame, index) ((frame)<<10)+index
#define IMA_INDEX_FRAME(index) (index>>10)
#define IMA_INDEX_PASS(index) (index & ~1023)
/* ******** IMAGE PROCESSING ************* */
@ -332,6 +333,33 @@ static void image_assign_ibuf(Image *ima, ImBuf *ibuf, int index, int frame)
}
}
/* empty image block, of similar type and filename */
Image *BKE_image_copy(Image *ima)
{
Image *new= image_alloc(ima->id.name+2, ima->source, ima->type);
BLI_strncpy(new->name, ima->name, sizeof(ima->name));
new->gen_x= ima->gen_x;
new->gen_y= ima->gen_y;
new->gen_type= ima->gen_type;
return new;
}
void BKE_image_merge(Image *dest, Image *source)
{
ImBuf *ibuf;
while((ibuf= source->ibufs.first)) {
BLI_remlink(&source->ibufs, ibuf);
image_assign_ibuf(dest, ibuf, IMA_INDEX_PASS(ibuf->index), IMA_INDEX_FRAME(ibuf->index));
}
free_libblock(&G.main->image, source);
}
/* checks if image was already loaded, then returns same image */
/* otherwise creates new. */
/* does not load ibuf itself */

View File

@ -2487,6 +2487,12 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree)
/* ensure new user input gets handled ok */
node->need_exec= 0;
if(ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
if(node->id && (node->flag & NODE_DO_OUTPUT)) {
node->new_node->id= (ID *)BKE_image_copy((Image *)node->id);
}
}
for(sock= node->outputs.first; sock; sock= sock->next) {
sock->new_sock->ns.data= sock->ns.data;
@ -2555,6 +2561,12 @@ void ntreeLocalMerge(bNodeTree *localtree, bNodeTree *ntree)
lnode->preview= NULL;
}
if(ELEM(lnode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
if(lnode->id && (lnode->flag & NODE_DO_OUTPUT)) {
BKE_image_merge((Image *)lnode->new_node->id, (Image *)lnode->id);
}
}
for(lsock= lnode->outputs.first; lsock; lsock= lsock->next) {
if(outsocket_exists(lnode->new_node, lsock->new_sock)) {
lsock->new_sock->ns.data= lsock->ns.data;