Fix T61457, T61489, T61482: build errors and memory warning in Cycles.

For OIIO 2.x we must use unique_ptr. This also required updating the
guarded allocator for std::move to work. Since C++11 construct/destroy
have a default implementation that also works this case, so we just
leave it out.
This commit is contained in:
Brecht Van Lommel 2019-02-12 17:10:31 +01:00
parent 2a9c8da709
commit 3866161da8
Notes: blender-bot 2024-03-25 12:30:38 +01:00
Referenced by issue #61489, Broken build in denoising.cpp with OpenImage 2.0.5
Referenced by issue #61482, Warning: "Error: not freed memory blocks: 2"
Referenced by issue #61457, Recent commits prevent compiling Blender 2.8, February 19
5 changed files with 19 additions and 47 deletions

View File

@ -457,10 +457,10 @@ void Device::tag_update()
void Device::free_memory()
{
devices_initialized_mask = 0;
cuda_devices.clear();
opencl_devices.clear();
cpu_devices.clear();
network_devices.clear();
cuda_devices.free_memory();
opencl_devices.free_memory();
cpu_devices.free_memory();
network_devices.free_memory();
}
CCL_NAMESPACE_END

View File

@ -123,7 +123,7 @@ static void fill_mapping(vector<ChannelMapping> &map, int pos, string name, stri
}
static const int INPUT_NUM_CHANNELS = 15;
static vector<ChannelMapping> init_input_channels()
static vector<ChannelMapping> input_channels()
{
vector<ChannelMapping> map;
fill_mapping(map, 0, "Denoising Depth", "Z");
@ -137,16 +137,13 @@ static vector<ChannelMapping> init_input_channels()
}
static const int OUTPUT_NUM_CHANNELS = 3;
static vector<ChannelMapping> init_output_channels()
static vector<ChannelMapping> output_channels()
{
vector<ChannelMapping> map;
fill_mapping(map, 0, "Combined", "RGB");
return map;
}
static const vector<ChannelMapping> input_channels = init_input_channels();
static const vector<ChannelMapping> output_channels = init_output_channels();
/* Renderlayer Handling */
bool DenoiseImageLayer::detect_denoising_channels()
@ -155,7 +152,7 @@ bool DenoiseImageLayer::detect_denoising_channels()
input_to_image_channel.clear();
input_to_image_channel.resize(INPUT_NUM_CHANNELS, -1);
foreach(const ChannelMapping& mapping, input_channels) {
foreach(const ChannelMapping& mapping, input_channels()) {
vector<string>::iterator i = find(channels.begin(), channels.end(), mapping.name);
if(i == channels.end()) {
return false;
@ -170,7 +167,7 @@ bool DenoiseImageLayer::detect_denoising_channels()
output_to_image_channel.clear();
output_to_image_channel.resize(OUTPUT_NUM_CHANNELS, -1);
foreach(const ChannelMapping& mapping, output_channels) {
foreach(const ChannelMapping& mapping, output_channels()) {
vector<string>::iterator i = find(channels.begin(), channels.end(), mapping.name);
if(i == channels.end()) {
return false;
@ -554,18 +551,8 @@ DenoiseImage::~DenoiseImage()
void DenoiseImage::close_input()
{
foreach(ImageInput *i, in_neighbors) {
i->close();
ImageInput::destroy(i);
}
in_neighbors.clear();
if(in) {
in->close();
ImageInput::destroy(in);
in = NULL;
}
in.reset();
}
void DenoiseImage::free()
@ -675,7 +662,7 @@ bool DenoiseImage::load(const string& in_filepath, string& error)
return false;
}
in = ImageInput::open(in_filepath);
in.reset(ImageInput::open(in_filepath));
if(!in) {
error = "Couldn't open file: " + in_filepath;
return false;
@ -724,7 +711,7 @@ bool DenoiseImage::load_neighbors(const vector<string>& filepaths, const vector<
return false;
}
ImageInput *in_neighbor = ImageInput::open(filepath);
unique_ptr<ImageInput> in_neighbor(ImageInput::open(filepath));
if(!in_neighbor) {
error = "Couldn't open neighbor frame: " + filepath;
return false;
@ -733,8 +720,6 @@ bool DenoiseImage::load_neighbors(const vector<string>& filepaths, const vector<
const ImageSpec &neighbor_spec = in_neighbor->spec();
if(neighbor_spec.width != width || neighbor_spec.height != height) {
error = "Neighbor frame has different dimensions: " + filepath;
in_neighbor->close();
ImageInput::destroy(in_neighbor);
return false;
}
@ -744,13 +729,11 @@ bool DenoiseImage::load_neighbors(const vector<string>& filepaths, const vector<
neighbor_spec.channelnames))
{
error = "Neighbor frame misses denoising data passes: " + filepath;
in_neighbor->close();
ImageInput::destroy(in_neighbor);
return false;
}
}
in_neighbors.push_back(in_neighbor);
in_neighbors.push_back(std::move(in_neighbor));
}
return true;
@ -776,7 +759,7 @@ bool DenoiseImage::save_output(const string& out_filepath, string& error)
/* Write to temporary file path, so we denoise images in place and don't
* risk destroying files when something goes wrong in file saving. */
string tmp_filepath = OIIO::Filesystem::temp_directory_path() + "/" + OIIO::Filesystem::unique_path() + ".exr";
ImageOutput *out = ImageOutput::create(tmp_filepath);
unique_ptr<ImageOutput> out(ImageOutput::create(tmp_filepath));
if(!out) {
error = "Failed to open temporary file " + tmp_filepath + " for writing";
@ -786,7 +769,6 @@ bool DenoiseImage::save_output(const string& out_filepath, string& error)
/* Open temporary file and write image buffers. */
if(!out->open(tmp_filepath, out_spec)) {
error = "Failed to open file " + tmp_filepath + " for writing: " + out->geterror();
ImageOutput::destroy(out);
return false;
}
@ -801,7 +783,7 @@ bool DenoiseImage::save_output(const string& out_filepath, string& error)
ok = false;
}
ImageOutput::destroy(out);
out.reset();
/* Copy temporary file to outputput filepath. */
if(ok && !OIIO::Filesystem::rename(tmp_filepath, out_filepath)) {

View File

@ -24,6 +24,7 @@
#include "util/util_string.h"
#include "util/util_vector.h"
#include "util/util_unique_ptr.h"
#include <OpenImageIO/imageio.h>
@ -84,7 +85,7 @@ struct DenoiseImageLayer {
vector<int> input_to_image_channel;
/* input_to_image_channel of the secondary frames, if any are used. */
vector<vector<int> > neighbor_input_to_image_channel;
vector<vector<int>> neighbor_input_to_image_channel;
/* Write i-th channel of the processing output to output_to_image_channel[i]-th channel of the file. */
vector<int> output_to_image_channel;
@ -116,8 +117,8 @@ public:
array<float> pixels;
/* Image file handles */
ImageInput *in;
vector<ImageInput*> in_neighbors;
unique_ptr<ImageInput> in;
vector<unique_ptr<ImageInput>> in_neighbors;
/* Render layers */
vector<DenoiseImageLayer> layers;

View File

@ -97,18 +97,6 @@ public:
return *this;
}
void construct(T *p, const T& val)
{
if(p != NULL) {
new ((T *)p) T(val);
}
}
void destroy(T *p)
{
p->~T();
}
size_t max_size() const
{
return size_t(-1);

View File

@ -3555,6 +3555,7 @@ static void rna_generate_header(BlenderRNA *UNUSED(brna), FILE *f)
static const char *cpp_classes = ""
"\n"
"#include <stdlib.h> /* for malloc */\n"
"#include <string>\n"
"#include <string.h> /* for memcpy */\n"
"\n"