Caching generated image leads to infinite loop in preview render #53

Merged
Bogdan Nagirniak merged 12 commits from BLEN-409 into hydra-render 2023-06-13 18:39:39 +02:00
Showing only changes of commit b8793017cf - Show all commits

View File

@ -6,6 +6,7 @@
#include "BKE_appdir.h" #include "BKE_appdir.h"
#include "BKE_image.h" #include "BKE_image.h"
#include "BKE_image_save.h" #include "BKE_image_save.h"
#include "BKE_image_format.h"
#include "BLI_fileops.h" #include "BLI_fileops.h"
#include "BLI_path_util.h" #include "BLI_path_util.h"
@ -22,8 +23,16 @@ std::string cache_image_file(Image *image,
bool check_exist) bool check_exist)
{ {
std::string file_path(FILE_MAX, 0); std::string file_path(FILE_MAX, 0);
Main *main = CTX_data_main(context);
ImageSaveOptions opts;
if (BKE_image_save_options_init(&opts, main, scene, image, iuser, false, false)) {
char file_name[32]; char file_name[32];
snprintf(file_name, 32, "img_%016llx.hdr", (uintptr_t)image); 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(), BLI_path_join(file_path.data(),
file_path.capacity(), file_path.capacity(),
BKE_tempdir_session(), BKE_tempdir_session(),
@ -33,17 +42,9 @@ std::string cache_image_file(Image *image,
if (check_exist && BLI_exists(file_path.c_str())) { if (check_exist && BLI_exists(file_path.c_str())) {
return file_path; return file_path;
} }
opts.save_copy = true;
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)) {
STRNCPY(opts.filepath, file_path.c_str()); STRNCPY(opts.filepath, file_path.c_str());
ReportList reports; if (BKE_image_save(nullptr, main, image, iuser, &opts)) {
if (BKE_image_save(&reports, main, image, iuser, &opts)) {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path.c_str()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path.c_str());
} }
else { else {
@ -51,7 +52,6 @@ std::string cache_image_file(Image *image,
} }
} }
BKE_image_save_options_free(&opts); BKE_image_save_options_free(&opts);
image->source = prev_source;
return file_path; return file_path;
} }