forked from blender/blender
Caching generated image leads to infinite loop in preview render #53
@ -6,6 +6,7 @@
|
||||
#include "BKE_appdir.h"
|
||||
#include "BKE_image.h"
|
||||
#include "BKE_image_save.h"
|
||||
#include "BKE_image_format.h"
|
||||
#include "BLI_fileops.h"
|
||||
#include "BLI_path_util.h"
|
||||
|
||||
@ -22,28 +23,28 @@ std::string cache_image_file(Image *image,
|
||||
bool check_exist)
|
||||
{
|
||||
std::string file_path(FILE_MAX, 0);
|
||||
char file_name[32];
|
||||
snprintf(file_name, 32, "img_%016llx.hdr", (uintptr_t)image);
|
||||
BLI_path_join(file_path.data(),
|
||||
file_path.capacity(),
|
||||
BKE_tempdir_session(),
|
||||
"hydra_image_cache",
|
||||
file_name);
|
||||
|
||||
if (check_exist && BLI_exists(file_path.c_str())) {
|
||||
return file_path;
|
||||
}
|
||||
|
||||
Main *main = CTX_data_main(context);
|
||||
ImageSaveOptions opts;
|
||||
opts.im_format.imtype = R_IMF_IMTYPE_RADHDR;
|
||||
|
||||
auto prev_source = image->source;
|
||||
|
||||
if (BKE_image_save_options_init(&opts, main, scene, image, iuser, false, false)) {
|
||||
char file_name[32];
|
||||
const char *r_ext[BKE_IMAGE_PATH_EXT_MAX];
|
||||
snprintf(file_name, sizeof(file_name), "img_%016llx", (uintptr_t)image);
|
||||
BKE_image_path_ext_from_imtype(opts.im_format.imtype, r_ext);
|
||||
|
||||
int len = strlen(file_name);
|
||||
STR_CONCAT(file_name, len, *r_ext);
|
||||
BLI_path_join(file_path.data(),
|
||||
file_path.capacity(),
|
||||
BKE_tempdir_session(),
|
||||
"hydra_image_cache",
|
||||
file_name);
|
||||
|
||||
if (check_exist && BLI_exists(file_path.c_str())) {
|
||||
return file_path;
|
||||
}
|
||||
opts.save_copy = true;
|
||||
STRNCPY(opts.filepath, file_path.c_str());
|
||||
ReportList reports;
|
||||
if (BKE_image_save(&reports, main, image, iuser, &opts)) {
|
||||
if (BKE_image_save(nullptr, main, image, iuser, &opts)) {
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path.c_str());
|
||||
}
|
||||
else {
|
||||
@ -51,7 +52,6 @@ std::string cache_image_file(Image *image,
|
||||
}
|
||||
}
|
||||
BKE_image_save_options_free(&opts);
|
||||
image->source = prev_source;
|
||||
|
||||
return file_path;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user