<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
I stumbled across a bug using vtkImplicitPlaneWidget by calling
OutsideBoundsOff() that causes an access violation to occur as soon
as the widget is enabled.<br>
<br>
I traced the code to here:<br>
<title>Snippet</title>
<pre style="font-family:Consolas;font-size:13;color:black;background:white;"><span style="color:blue;">
void</span> <span style="color:blue;">vtkImplicitPlaneWidget</span>::<span style="color:#880000;">UpdateRepresentation</span>()
{
<span style="color:blue;">if</span> ( ! <span style="color:blue;">this</span>-><span style="color:navy;">CurrentRenderer</span> )
{
<span style="color:blue;">return</span>;
}
<span style="color:blue;">double</span> *<span style="color:navy;">origin</span> = <span style="color:blue;">this</span>-><span style="color:blue;">Plane</span>-><span style="color:#880000;">GetOrigin</span>();
<span style="color:blue;">double</span> *<span style="color:navy;">normal</span> = <span style="color:blue;">this</span>-><span style="color:blue;">Plane</span>-><span style="color:#880000;">GetNormal</span>();
<span style="color:blue;">double</span> <span style="color:navy;">p2</span>[3];
<span style="color:blue;">if</span>( !<span style="color:blue;">this</span>-><span style="color:navy;">OutsideBounds</span> )
{
<span style="color:blue;">double</span> *<span style="color:navy;">bounds</span> = <span style="color:blue;">this</span>-><span style="color:#880000;">GetInput</span>()-><span style="color:#880000;">GetBounds</span>();
<span style="color:blue;">for</span> (<span style="color:blue;">int</span> <span style="color:navy;">i</span>=0; <span style="color:navy;">i</span><3; <span style="color:navy;">i</span>++)
{
<span style="color:blue;">if</span> ( <span style="color:navy;">origin</span>[<span style="color:navy;">i</span>] < <span style="color:navy;">bounds</span>[2*<span style="color:navy;">i</span>] )
{
...
</pre>
It crashes because the widget is blindly getting the bounds of it's
input that was never set. So the access violation happens in the
call to GetBounds(). According to the documentation in vtk3DWidget:<br>
<title>Snippet</title>
<pre style="font-family:Consolas;font-size:13;color:black;background:white;">
<span style="color:green;">// Description:</span>
<span style="color:green;">// Specify the input dataset. This is not required, but if supplied,</span>
<span style="color:green;">// and no vtkProp3D is specified, it is used to initially position </span>
<span style="color:green;">// the widget.</span>
<span style="color:blue;">virtual</span> <span style="color:blue;">void</span> <span style="color:#880000;">SetInput</span>(<span style="color:blue;">vtkDataSet</span>*);
<span style="color:#a000a0;">vtkGetObjectMacro</span>(<span style="color:navy;">Input</span>,<span style="color:blue;">vtkDataSet</span>);
</pre>
So shouldn't the code in UpdateRepresentation() check the return
value of GetInput() before getting it's bounds?<br>
In addition, the returned bounds might be NULL or not initialized.<br>
Perhaps the code should be changed to something like this:<br>
<pre style="font-family:Consolas;font-size:13;color:black;background:white;">
<span style="color:blue;">if</span>( !<span style="color:blue;">this</span>-><span style="color:navy;">OutsideBounds</span> )
{
vtkDataSet *dataset = <span style="color:blue;">this</span>-><span style="color:#880000;">GetInput</span>();
<span style="color:blue;">double</span> *<span style="color:navy;">bounds</span> = dataset != NULL ? dataset-><span style="color:#880000;">GetBounds</span>() : NULL;
if ( bounds != NULL && vtkMath::AreBoundsInitialized(bounds) )
{
<span style="color:blue;">for</span> (<span style="color:blue;">int</span> <span style="color:navy;">i</span>=0; <span style="color:navy;">i</span><3; <span style="color:navy;">i</span>++)
{
...
</pre>
<br>
Question #1: Has anyone else seen this before?<br>
Question #2: Can anyone else corroborate?<br>
Question #3: Can a contributor make this (or an equivalent) fix? :-)<br>
<br>
I don't particularly need this for my application, but I thought
that I'd report the problem to the group in the hopes that it gets
fixed and for posterity in case someone searches for this in the
future.<br>
<div class="moz-signature">-- <br>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<title>Signature</title>
<a href="http:://www.infolytica.com">www.infolytica.com </a><br>
300 Leo Pariseau, Suite 2222, Montreal, QC, Canada, H2X 4B3<br>
(514) 849-8752 x236, Fax: (514) 849-4239
</div>
</body>
</html>