Commit 2ed1bb72 authored by Robert Maynard's avatar Robert Maynard Committed by Kitware Robot

Merge topic 'color_table_stop_leaking_memory'

86c487e6 Properly clean up ColorTable's memory.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Kenneth Moreland's avatarKenneth Moreland <kmorel@sandia.gov>
Acked-by: James Kress's avatarJames Kress <james@jameskress.com>
Merge-request: !1141
parents 71514173 86c487e6
......@@ -153,12 +153,10 @@ ColorSpace ColorTable::GetColorSpace() const
//----------------------------------------------------------------------------
void ColorTable::SetColorSpace(ColorSpace space)
{
if (this->Impl->CSpace != space || this->Impl->HostSideCache == nullptr)
if (this->Impl->CSpace != space || this->Impl->HostSideCache.get() == nullptr)
{
this->Impl->CSpace = space;
//Remove any existing host and execution data
delete this->Impl->HostSideCache;
delete this->Impl->ExecHandle;
using HandleType = vtkm::cont::VirtualObjectHandle<vtkm::exec::ColorTableBase>;
switch (space)
......@@ -166,36 +164,36 @@ void ColorTable::SetColorSpace(ColorSpace space)
case vtkm::cont::ColorSpace::RGB:
{
auto* hostPortal = new vtkm::exec::ColorTableRGB();
this->Impl->ExecHandle = new HandleType(hostPortal, false);
this->Impl->HostSideCache = hostPortal;
this->Impl->ExecHandle.reset(new HandleType(hostPortal, false));
this->Impl->HostSideCache.reset(hostPortal);
break;
}
case vtkm::cont::ColorSpace::HSV:
{
auto* hostPortal = new vtkm::exec::ColorTableHSV();
this->Impl->ExecHandle = new HandleType(hostPortal, false);
this->Impl->HostSideCache = hostPortal;
this->Impl->ExecHandle.reset(new HandleType(hostPortal, false));
this->Impl->HostSideCache.reset(hostPortal);
break;
}
case vtkm::cont::ColorSpace::HSV_WRAP:
{
auto* hostPortal = new vtkm::exec::ColorTableHSVWrap();
this->Impl->ExecHandle = new HandleType(hostPortal, false);
this->Impl->HostSideCache = hostPortal;
this->Impl->ExecHandle.reset(new HandleType(hostPortal, false));
this->Impl->HostSideCache.reset(hostPortal);
break;
}
case vtkm::cont::ColorSpace::LAB:
{
auto* hostPortal = new vtkm::exec::ColorTableLab();
this->Impl->ExecHandle = new HandleType(hostPortal, false);
this->Impl->HostSideCache = hostPortal;
this->Impl->ExecHandle.reset(new HandleType(hostPortal, false));
this->Impl->HostSideCache.reset(hostPortal);
break;
}
case vtkm::cont::ColorSpace::DIVERGING:
{
auto* hostPortal = new vtkm::exec::ColorTableDiverging();
this->Impl->ExecHandle = new HandleType(hostPortal, false);
this->Impl->HostSideCache = hostPortal;
this->Impl->ExecHandle.reset(new HandleType(hostPortal, false));
this->Impl->HostSideCache.reset(hostPortal);
break;
}
default:
......@@ -864,14 +862,14 @@ vtkm::cont::VirtualObjectHandle<vtkm::exec::ColorTableBase>* ColorTable::GetHand
if (this->Impl->ColorArraysChanged || this->Impl->OpacityArraysChanged)
{
vtkm::cont::TryExecute(
detail::transfer_color_table_to_device{}, this->Impl->HostSideCache, this->Impl.get());
detail::transfer_color_table_to_device{}, this->Impl->HostSideCache.get(), this->Impl.get());
this->Impl->HostSideCache->Modified();
}
this->Impl->ColorArraysChanged = false;
this->Impl->OpacityArraysChanged = false;
return this->Impl->ExecHandle;
return this->Impl->ExecHandle.get();
}
//---------------------------------------------------------------------------
......
......@@ -48,9 +48,9 @@ struct ColorTableInternals
// AboveRangeColor
//Note the pointers inside the host side portal are not valid, as they
//are execution
vtkm::exec::ColorTableBase* HostSideCache = nullptr;
std::unique_ptr<vtkm::exec::ColorTableBase> HostSideCache;
//Execution side version of the ColorTableBase.
vtkm::cont::VirtualObjectHandle<vtkm::exec::ColorTableBase>* ExecHandle = nullptr;
std::unique_ptr<vtkm::cont::VirtualObjectHandle<vtkm::exec::ColorTableBase>> ExecHandle;
std::vector<double> ColorNodePos;
std::vector<vtkm::Vec<float, 3>> ColorRGB;
......
......@@ -69,6 +69,15 @@ public:
vtkm::cont::ColorTable tableRGBA(range, rgba1, rgba2, diverging);
VTKM_TEST_ASSERT(tableRGBA.GetColorSpace() == diverging, "color space not saved");
VTKM_TEST_ASSERT(tableRGBA.GetRange() == range, "color range not saved");
//verify we can store a vector of tables
std::vector<vtkm::cont::ColorTable> tables;
tables.push_back(table);
tables.push_back(tableRGB);
tables.push_back(tableRGBA);
tables.push_back(tableRGBA);
tables.push_back(tableRGB);
tables.push_back(table);
}
static void TestLoadPresets()
......
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