fixed bug with deletion from std::map
This commit is contained in:
parent
a6ab9be5a6
commit
3830a0b5b2
@ -149,8 +149,8 @@ namespace cv
|
||||
VizStorage(); // Static
|
||||
~VizStorage();
|
||||
|
||||
static void add(Viz3d window);
|
||||
static Viz3d get(const String &window_name);
|
||||
static void add(const Viz3d& window);
|
||||
static Viz3d& get(const String &window_name);
|
||||
static void remove(const String &window_name);
|
||||
static bool windowExists(const String &window_name);
|
||||
static void removeUnreferenced();
|
||||
|
@ -112,7 +112,7 @@ namespace cv { namespace viz
|
||||
cv::viz::VizMap cv::viz::VizStorage::storage;
|
||||
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);
|
||||
VizMap::iterator vm_itr = storage.find(name);
|
||||
@ -120,7 +120,7 @@ cv::viz::Viz3d cv::viz::VizStorage::get(const String &window_name)
|
||||
return vm_itr->second;
|
||||
}
|
||||
|
||||
void cv::viz::VizStorage::add(Viz3d window)
|
||||
void cv::viz::VizStorage::add(const Viz3d& window)
|
||||
{
|
||||
String window_name = window.getWindowName();
|
||||
VizMap::iterator vm_itr = storage.find(window_name);
|
||||
@ -136,9 +136,11 @@ bool cv::viz::VizStorage::windowExists(const String &window_name)
|
||||
|
||||
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)
|
||||
storage.erase(pos);
|
||||
storage.erase(pos++);
|
||||
else
|
||||
++pos;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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(); }
|
||||
|
@ -62,7 +62,8 @@ cv::viz::Viz3d& cv::viz::Viz3d::operator=(const Viz3d& other)
|
||||
{
|
||||
release();
|
||||
impl_ = other.impl_;
|
||||
if (impl_) CV_XADD(&impl_->ref_counter, 1);
|
||||
if (impl_)
|
||||
CV_XADD(&impl_->ref_counter, 1);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@ -89,10 +90,15 @@ void cv::viz::Viz3d::create(const String &window_name)
|
||||
void cv::viz::Viz3d::release()
|
||||
{
|
||||
if (impl_ && CV_XADD(&impl_->ref_counter, -1) == 1)
|
||||
{
|
||||
delete impl_;
|
||||
impl_ = 0;
|
||||
}
|
||||
|
||||
if (impl_ && impl_->ref_counter == 1)
|
||||
VizStorage::removeUnreferenced();
|
||||
|
||||
impl_ = 0;
|
||||
VizStorage::removeUnreferenced();
|
||||
}
|
||||
|
||||
void cv::viz::Viz3d::spin() { impl_->spin(); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user