[vtkusers] [ActiViz] Attempted to read or write protected memory. Hold Reference?
ferluduena
xpelaox at gmail.com
Thu Jul 17 23:14:30 EDT 2014
Hi! I'm trying to port my working code on c++ to C#, but i cant get it to
work.
It compiles but i get this error :"Attempted to read or write protected
memory. This is often an indication that other memory is corrupt."
VTK is trying to acces an out of bounds array location.
I've been reading a lot, and the most logical explanation i got was that as
C# is managed, it might be that C# is deleting something that VTK will need
to use later. Some people talk about "Holding Managed references" and also
the importance of sometimes using the Dispose() function.
I tried a lot of things, but i just cant figure it out.
Hope someone can help! and Thanks in advance!
This is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Kitware.VTK;
namespace Prueba3D
{
public partial class Form1 : Form
{
vtkPolyData polydata;
vtkPoints points;
vtkSurfaceReconstructionFilter surf;
vtkPolyDataMapper Mapper;
vtkContourFilter cf;
vtkActor Actor;
vtkRenderWindow RenderWindow;
vtkRenderer Renderer;
public Form1()
{
InitializeComponent();
}
private void renderWindowControl1_Load(object sender, EventArgs e)
{
//Generate some points
//Z=0
double[] p0 = new double[] { 4, 4, 0 };
double[] p1 = new double[] { 3, 3, 0 };
double[] p2 = new double[] { 3, 4, 0 };
double[] p3 = new double[] { 3, 5, 0 };
double[] p4 = new double[] { 4, 3, 0 };
double[] p5 = new double[] { 4, 5, 0 };
double[] p6 = new double[] { 5, 3, 0 };
double[] p7 = new double[] { 5, 4, 0 };
// Create a vtkPoints object and store the points in it
points = vtkPoints.New();
points.InsertNextPoint(p0[0], p0[1], p0[2]);
points.InsertNextPoint(p1[0], p1[1], p1[2]);
points.InsertNextPoint(p2[0], p2[1], p2[2]);
points.InsertNextPoint(p3[0], p3[1], p3[2]);
points.InsertNextPoint(p4[0], p4[1], p4[2]);
points.InsertNextPoint(p5[0], p5[1], p5[2]);
points.InsertNextPoint(p6[0], p6[1], p6[2]);
points.InsertNextPoint(p7[0], p7[1], p7[2]);
polydata = vtkPolyData.New();
polydata.SetPoints(points);
surf = vtkSurfaceReconstructionFilter.New();
surf.SetInput(polydata);
// mapper
Mapper = vtkPolyDataMapper.New();
Mapper.ScalarVisibilityOff();
cf = vtkContourFilter.New();
cf.SetInputConnection(surf.GetOutputPort());
cf.SetValue(0, 0.0);
Mapper.SetInputConnection(cf.GetOutputPort());
// actor
Actor = vtkActor.New();
Actor.SetMapper(Mapper);
// get a reference to the renderwindow of our
renderWindowControl1
RenderWindow = renderWindowControl1.RenderWindow;
// get a reference to the renderer
Renderer = RenderWindow.GetRenderers().GetFirstRenderer();
// set background color
Renderer.SetBackground(0.2, 0.3, 0.4);
// add actor to the renderer
Renderer.AddActor(Actor);
// ensure all actors are visible (in this example not
necessarely needed,
// but in case more than one actor needs to be shown it might be
a good idea)
Renderer.ResetCamera();
}
}
}
--
View this message in context: http://vtk.1045678.n5.nabble.com/ActiViz-Attempted-to-read-or-write-protected-memory-Hold-Reference-tp5727902.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list