Hallo @ll,
we are using VTK (Version: 9.0.1.1009) as Graphic API and have problems with a System.AccessViolationException : Attempt to read or write protected memory, which keeps occurring randomly, sometimes after 30 minutes or after 4 hours.
I really don’t know how to work around this problem anymore.
The exception producing code is actually nothing special. The error occurs when we populate, or pass, a glyph with a source connection, which can be either an arrow or a sphere.
glyph.SetSourceConnection(graphObj); // Line of Exception
At the given point it throws an exception, the vtkPolyData are filled with vtkPoints, but we have already checked them for validity. However, I don’t think this is our problem. The function we are using looks like this. Also, the way the Actor or PolyData is passed to the function doesn’t seem to matter (copy, ref, in: unimportant)
Code
private void InitPolyData(
ref vtkPolyData polyData,
ref vtkPoints points,
in string colorName,
in vtkAbstractArray colorArray,
in string velocityName,
in vtkAbstractArray velocityArray
)
{
this.InitPolyData(ref polyData, ref points, colorName, colorArray);
// Add Velocity Array (points) to polydata
polyData.GetPointData().AddArray(velocityArray);
polyData.GetPointData().SetActiveVectors(velocityName);
}
private void InitActor(
ref vtkActor actor,
in bool isArrow,
ref vtkPolyData inputData,
in bool extendedArgs
)
{
vtkGlyph3D glyph = new vtkGlyph3D();
vtkPolyDataMapper mapperMoving = new vtkPolyDataMapper();
vtkAppendPolyData polyDataListMoving = new vtkAppendPolyData();
vtkAlgorithmOutput graphObj;
if (isArrow)
{
/* Create Arrow geometry (sounds more complicated than it is :D) */
vtkArrowSource arrowSource = new vtkArrowSource();
arrowSource.SetShaftResolution(24);
arrowSource.SetTipResolution(36);
graphObj = arrowSource.GetOutputPort();
}
else
{
// Sphere for stationary points
vtkSphereSource sphereSource = new vtkSphereSource();
sphereSource.SetThetaResolution(20);
sphereSource.SetPhiResolution(20);
sphereSource.SetRadius(0.05);
graphObj = sphereSource.GetOutputPort();
}
mapperMoving.SetColorModeToDefault();
/* Create Actor for point cloud and add mapper */
// actor = new vtkActor();
actor.SetMapper(mapperMoving);
/* Set point size */
actor.GetProperty().SetPointSize(4);
glyph.SetSourceConnection(graphObj);
glyph.SetInputData(inputData);
if (extendedArgs)
{
glyph.OrientOn();
glyph.SetVectorModeToUseVector();
glyph.SetScaleModeToScaleByVectorComponents();
}
glyph.SetColorModeToColorByScalar();
glyph.SetScaleModeToDataScalingOff();
glyph.SetScaleFactor(10);
glyph.Update();
polyDataListMoving.AddInputData(glyph.GetOutput());
polyDataListMoving.Update();
actor.GetMapper().SetInputDataObject(polyDataListMoving.GetOutput());
}
Maybe someone knows this kind of error.
Thank you and best regards
Emanuel