Commit 3830a0b5 authored by Anatoly Baksheev's avatar Anatoly Baksheev

fixed bug with deletion from std::map

parent a6ab9be5
...@@ -149,8 +149,8 @@ namespace cv ...@@ -149,8 +149,8 @@ namespace cv
VizStorage(); // Static VizStorage(); // Static
~VizStorage(); ~VizStorage();
static void add(Viz3d window); static void add(const Viz3d& window);
static Viz3d get(const String &window_name); static Viz3d& get(const String &window_name);
static void remove(const String &window_name); static void remove(const String &window_name);
static bool windowExists(const String &window_name); static bool windowExists(const String &window_name);
static void removeUnreferenced(); static void removeUnreferenced();
......
...@@ -112,7 +112,7 @@ namespace cv { namespace viz ...@@ -112,7 +112,7 @@ namespace cv { namespace viz
cv::viz::VizMap cv::viz::VizStorage::storage; cv::viz::VizMap cv::viz::VizStorage::storage;
void cv::viz::VizStorage::unregisterAll() { storage.clear(); } void cv::viz::VizStorage::unregisterAll() { storage.clear(); }
cv::viz::Viz3d cv::viz::VizStorage::get(const String &window_name) cv::viz::Viz3d& cv::viz::VizStorage::get(const String &window_name)
{ {
String name = generateWindowName(window_name); String name = generateWindowName(window_name);
VizMap::iterator vm_itr = storage.find(name); VizMap::iterator vm_itr = storage.find(name);
...@@ -120,7 +120,7 @@ cv::viz::Viz3d cv::viz::VizStorage::get(const String &window_name) ...@@ -120,7 +120,7 @@ cv::viz::Viz3d cv::viz::VizStorage::get(const String &window_name)
return vm_itr->second; return vm_itr->second;
} }
void cv::viz::VizStorage::add(Viz3d window) void cv::viz::VizStorage::add(const Viz3d& window)
{ {
String window_name = window.getWindowName(); String window_name = window.getWindowName();
VizMap::iterator vm_itr = storage.find(window_name); VizMap::iterator vm_itr = storage.find(window_name);
...@@ -136,9 +136,11 @@ bool cv::viz::VizStorage::windowExists(const String &window_name) ...@@ -136,9 +136,11 @@ bool cv::viz::VizStorage::windowExists(const String &window_name)
void cv::viz::VizStorage::removeUnreferenced() void cv::viz::VizStorage::removeUnreferenced()
{ {
for(VizMap::iterator pos = storage.begin(); pos != storage.end(); ++pos) for(VizMap::iterator pos = storage.begin(); pos != storage.end();)
if(pos->second.impl_->ref_counter == 1) if(pos->second.impl_->ref_counter == 1)
storage.erase(pos); storage.erase(pos++);
else
++pos;
} }
cv::String cv::viz::VizStorage::generateWindowName(const String &window_name) cv::String cv::viz::VizStorage::generateWindowName(const String &window_name)
...@@ -159,5 +161,5 @@ cv::String cv::viz::VizStorage::generateWindowName(const String &window_name) ...@@ -159,5 +161,5 @@ cv::String cv::viz::VizStorage::generateWindowName(const String &window_name)
return output; return output;
} }
cv::viz::Viz3d cv::viz::get(const String &window_name) { return Viz3d(window_name); } cv::viz::Viz3d cv::viz::get(const String &window_name) { return Viz3d (window_name); }
void cv::viz::unregisterAllWindows() { VizStorage::unregisterAll(); } void cv::viz::unregisterAllWindows() { VizStorage::unregisterAll(); }
...@@ -62,7 +62,8 @@ cv::viz::Viz3d& cv::viz::Viz3d::operator=(const Viz3d& other) ...@@ -62,7 +62,8 @@ cv::viz::Viz3d& cv::viz::Viz3d::operator=(const Viz3d& other)
{ {
release(); release();
impl_ = other.impl_; impl_ = other.impl_;
if (impl_) CV_XADD(&impl_->ref_counter, 1); if (impl_)
CV_XADD(&impl_->ref_counter, 1);
} }
return *this; return *this;
} }
...@@ -89,10 +90,15 @@ void cv::viz::Viz3d::create(const String &window_name) ...@@ -89,10 +90,15 @@ void cv::viz::Viz3d::create(const String &window_name)
void cv::viz::Viz3d::release() void cv::viz::Viz3d::release()
{ {
if (impl_ && CV_XADD(&impl_->ref_counter, -1) == 1) if (impl_ && CV_XADD(&impl_->ref_counter, -1) == 1)
{
delete impl_; delete impl_;
impl_ = 0;
}
if (impl_ && impl_->ref_counter == 1)
VizStorage::removeUnreferenced();
impl_ = 0; impl_ = 0;
VizStorage::removeUnreferenced();
} }
void cv::viz::Viz3d::spin() { impl_->spin(); } void cv::viz::Viz3d::spin() { impl_->spin(); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment