Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Jayesh Badwaik
VTK-m
Commits
1b62901e
Commit
1b62901e
authored
May 15, 2019
by
Robert Maynard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Empty DynamicCellSet doesn't segfault on certain queries.
Fixes #370
parent
be5b51fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
7 deletions
+72
-7
vtkm/cont/DynamicCellSet.h
vtkm/cont/DynamicCellSet.h
+32
-7
vtkm/cont/testing/UnitTestDynamicCellSet.cxx
vtkm/cont/testing/UnitTestDynamicCellSet.cxx
+40
-0
No files found.
vtkm/cont/DynamicCellSet.h
View file @
1b62901e
...
...
@@ -161,7 +161,10 @@ public:
DynamicCellSetBase
<
CellSetList
>
NewInstance
()
const
{
DynamicCellSetBase
<
CellSetList
>
newCellSet
;
newCellSet
.
CellSet
=
this
->
CellSet
->
NewInstance
();
if
(
this
->
CellSet
)
{
newCellSet
.
CellSet
=
this
->
CellSet
->
NewInstance
();
}
return
newCellSet
;
}
...
...
@@ -172,22 +175,44 @@ public:
const
vtkm
::
cont
::
CellSet
*
GetCellSetBase
()
const
{
return
this
->
CellSet
.
get
();
}
VTKM_CONT
std
::
string
GetName
()
const
{
return
this
->
CellSet
->
GetName
()
;
}
std
::
string
GetName
()
const
{
return
this
->
CellSet
?
this
->
CellSet
->
GetName
()
:
std
::
string
{}
;
}
VTKM_CONT
vtkm
::
Id
GetNumberOfCells
()
const
{
return
this
->
CellSet
->
GetNumberOfCells
();
}
vtkm
::
Id
GetNumberOfCells
()
const
{
return
this
->
CellSet
?
this
->
CellSet
->
GetNumberOfCells
()
:
0
;
}
VTKM_CONT
vtkm
::
Id
GetNumberOfFaces
()
const
{
return
this
->
CellSet
->
GetNumberOfFaces
();
}
vtkm
::
Id
GetNumberOfFaces
()
const
{
return
this
->
CellSet
?
this
->
CellSet
->
GetNumberOfFaces
()
:
0
;
}
VTKM_CONT
vtkm
::
Id
GetNumberOfEdges
()
const
{
return
this
->
CellSet
->
GetNumberOfEdges
();
}
vtkm
::
Id
GetNumberOfEdges
()
const
{
return
this
->
CellSet
?
this
->
CellSet
->
GetNumberOfEdges
()
:
0
;
}
VTKM_CONT
vtkm
::
Id
GetNumberOfPoints
()
const
{
return
this
->
CellSet
->
GetNumberOfPoints
();
}
vtkm
::
Id
GetNumberOfPoints
()
const
{
return
this
->
CellSet
?
this
->
CellSet
->
GetNumberOfPoints
()
:
0
;
}
VTKM_CONT
void
PrintSummary
(
std
::
ostream
&
stream
)
const
{
return
this
->
CellSet
->
PrintSummary
(
stream
);
}
void
PrintSummary
(
std
::
ostream
&
stream
)
const
{
if
(
this
->
CellSet
)
{
this
->
CellSet
->
PrintSummary
(
stream
);
}
else
{
stream
<<
" DynamicCellSet = nullptr"
<<
std
::
endl
;
}
}
private:
std
::
shared_ptr
<
vtkm
::
cont
::
CellSet
>
CellSet
;
...
...
vtkm/cont/testing/UnitTestDynamicCellSet.cxx
View file @
1b62901e
...
...
@@ -41,6 +41,43 @@ class DummyCellSet : public vtkm::cont::CellSet
{
};
void
CheckEmptyDynamicCellSet
()
{
vtkm
::
cont
::
DynamicCellSet
empty
;
VTKM_TEST_ASSERT
(
empty
.
GetName
()
==
std
::
string
{},
"DynamicCellSet should have no name"
);
VTKM_TEST_ASSERT
(
empty
.
GetNumberOfCells
()
==
0
,
"DynamicCellSet should have no cells"
);
VTKM_TEST_ASSERT
(
empty
.
GetNumberOfFaces
()
==
0
,
"DynamicCellSet should have no faces"
);
VTKM_TEST_ASSERT
(
empty
.
GetNumberOfEdges
()
==
0
,
"DynamicCellSet should have no edges"
);
VTKM_TEST_ASSERT
(
empty
.
GetNumberOfPoints
()
==
0
,
"DynamicCellSet should have no points"
);
empty
.
PrintSummary
(
std
::
cout
);
using
CellSet2D
=
vtkm
::
cont
::
CellSetStructured
<
2
>
;
using
CellSet3D
=
vtkm
::
cont
::
CellSetStructured
<
3
>
;
VTKM_TEST_ASSERT
(
!
empty
.
template
IsType
<
CellSet2D
>(),
"DynamicCellSet reports wrong type."
);
VTKM_TEST_ASSERT
(
!
empty
.
template
IsType
<
CellSet3D
>(),
"DynamicCellSet reports wrong type."
);
VTKM_TEST_ASSERT
(
!
empty
.
template
IsType
<
DummyCellSet
>(),
"DynamicCellSet reports wrong type."
);
CellSet2D
instance
;
VTKM_TEST_ASSERT
(
!
empty
.
IsSameType
(
instance
),
"DynamicCellSet reports wrong type."
);
bool
gotException
=
false
;
try
{
instance
=
empty
.
Cast
<
CellSet2D
>
();
}
catch
(
vtkm
::
cont
::
ErrorBadType
&
)
{
gotException
=
true
;
}
VTKM_TEST_ASSERT
(
gotException
,
"Empty DynamicCellSet should have thrown on casting"
);
auto
empty2
=
empty
.
NewInstance
();
VTKM_TEST_ASSERT
(
empty
.
GetCellSetBase
()
==
nullptr
,
"DynamicCellSet should contain a nullptr"
);
VTKM_TEST_ASSERT
(
empty2
.
GetCellSetBase
()
==
nullptr
,
"DynamicCellSet should contain a nullptr"
);
}
template
<
typename
CellSetType
,
typename
CellSetList
>
void
CheckDynamicCellSet
(
const
CellSetType
&
cellSet
,
vtkm
::
cont
::
DynamicCellSetBase
<
CellSetList
>
dynamicCellSet
)
...
...
@@ -119,6 +156,9 @@ void TestDynamicCellSet()
std
::
cout
<<
"*** Explicit Grid Constant Shape ********"
<<
std
::
endl
;
TryNonDefaultCellSet
(
vtkm
::
cont
::
CellSetExplicit
<
vtkm
::
cont
::
ArrayHandleConstant
<
vtkm
::
UInt8
>::
StorageTag
>
());
std
::
cout
<<
std
::
endl
<<
"Try empty DynamicCellSet."
<<
std
::
endl
;
CheckEmptyDynamicCellSet
();
}
}
// anonymous namespace
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment