From 3306a4a0d2300767eeef71ab877fdf1587d13475 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 15 Jan 2018 00:48:29 +0100 Subject: [PATCH] In ResampleEffect, use std::unique_ptr instead of managing ownership ourselves. --- resample_effect.cpp | 18 +++++++----------- resample_effect.h | 4 ++-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/resample_effect.cpp b/resample_effect.cpp index ffc64fb..1f6c47c 100644 --- a/resample_effect.cpp +++ b/resample_effect.cpp @@ -300,8 +300,7 @@ double compute_sum_sq_error(const Tap* weights, unsigned num_weights, } // namespace ResampleEffect::ResampleEffect() - : owns_effects(true), - input_width(1280), + : input_width(1280), input_height(720), offset_x(0.0f), offset_y(0.0f), zoom_x(1.0f), zoom_y(1.0f), @@ -311,9 +310,11 @@ ResampleEffect::ResampleEffect() register_int("height", &output_height); // The first blur pass will forward resolution information to us. - hpass = new SingleResamplePassEffect(this); + hpass_owner.reset(new SingleResamplePassEffect(this)); + hpass = hpass_owner.get(); CHECK(hpass->set_int("direction", SingleResamplePassEffect::HORIZONTAL)); - vpass = new SingleResamplePassEffect(nullptr); + vpass_owner.reset(new SingleResamplePassEffect(this)); + vpass = vpass_owner.get(); CHECK(vpass->set_int("direction", SingleResamplePassEffect::VERTICAL)); update_size(); @@ -321,21 +322,16 @@ ResampleEffect::ResampleEffect() ResampleEffect::~ResampleEffect() { - if (owns_effects) { - delete hpass; - delete vpass; - } } void ResampleEffect::rewrite_graph(EffectChain *graph, Node *self) { - Node *hpass_node = graph->add_node(hpass); - Node *vpass_node = graph->add_node(vpass); + Node *hpass_node = graph->add_node(hpass_owner.release()); + Node *vpass_node = graph->add_node(vpass_owner.release()); graph->connect_nodes(hpass_node, vpass_node); graph->replace_receiver(self, hpass_node); graph->replace_sender(self, vpass_node); self->disabled = true; - owns_effects = false; } // We get this information forwarded from the first blur pass, diff --git a/resample_effect.h b/resample_effect.h index 1822a3e..027a497 100644 --- a/resample_effect.h +++ b/resample_effect.h @@ -93,8 +93,8 @@ private: // Both of these are owned by us if owns_effects is true (before finalize()), // and otherwise owned by the EffectChain. - bool owns_effects; - SingleResamplePassEffect *hpass, *vpass; + std::unique_ptr hpass_owner, vpass_owner; + SingleResamplePassEffect *hpass = nullptr, *vpass = nullptr; int input_width, input_height, output_width, output_height; float offset_x, offset_y; -- 2.39.2