[Bf-blender-cvs] [3866161da85] blender2.7: Fix T61457, T61489, T61482: build errors and memory warning in Cycles.

Brecht Van Lommel noreply at git.blender.org
Wed Feb 13 14:22:29 CET 2019


Commit: 3866161da855d2b35ac48ef55958bcb567d4a740
Author: Brecht Van Lommel
Date:   Tue Feb 12 17:10:31 2019 +0100
Branches: blender2.7
https://developer.blender.org/rB3866161da855d2b35ac48ef55958bcb567d4a740

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.

===================================================================

M	intern/cycles/device/device.cpp
M	intern/cycles/render/denoising.cpp
M	intern/cycles/render/denoising.h
M	intern/cycles/util/util_guarded_allocator.h
M	source/blender/makesrna/intern/makesrna.c

===================================================================

diff --git a/intern/cycles/device/device.cpp b/intern/cycles/device/device.cpp
index 317e62b2f69..327ba8e2a59 100644
--- a/intern/cycles/device/device.cpp
+++ b/intern/cycles/device/device.cpp
@@ -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
diff --git a/intern/cycles/render/denoising.cpp b/intern/cycles/render/denoising.cpp
index 0016a067cf9..bbc9f61522c 100644
--- a/intern/cycles/render/denoising.cpp
+++ b/intern/cycles/render/denoising.cpp
@@ -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)) {
diff --git a/intern/cycles/render/denoising.h b/intern/cycles/render/denoising.h
index 15e690a2f45..85a1c7d0391 100644
--- a/intern/cycles/render/denoising.h
+++ b/intern/cycles/render/denoising.h
@@ -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;
diff --git a/intern/cycles/util/util_guarded_allocator.h b/intern/cycles/util/util_guarded_allocator.h
index 2c6f1790fd0..99edf77e2c7 100644
--- a/intern/cycles/util/util_guarded_allocator.h
+++ b/intern/cycles/util/util_guarded_allocator.h
@@ -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);
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index 54edf972e1d..b4c664e9c90 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -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"



More information about the Bf-blender-cvs mailing list