Memory Error, too

Help
Yi Lu
2008-03-01
2013-04-25
  • Yi Lu
    Yi Lu
    2008-03-01

    I wrote a code imitating the tutorial program in this forum, trying to let vtkformwindow display a single dicom image. But when the function is called, I get an exception
    "An unhandled exception of type 'System.AccessViolationException' occurred in vtkRenderingDotNet.dll"
    and the following information:
    "Attempt to read or write protected memory. This is often an indication that ohter memory is corrupt.  At vtk.vtkRenderWindow.Render()"

    What is strange is that the same code in C++ grammar can run correctly in native VTK and VC++6.0 environment. And when I use vtkBMPImageReader, it is OK too. Anyone who has idea what happens here? Thanks a lot.This is graduation project.

    Here is my code:

    -----------------------------------------------------------------------
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using vtk;

    namespace VTKtest
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                this.AddConeToWindow(this.VTKform.GetRenderWindow());
                this.AddConeToWindow(this.vtkForm2.GetRenderWindow());
            }

            void AddConeToWindow(vtk.vtkRenderWindow renWin)
            {
                vtk.vtkConeSource cone = new vtk.vtkConeSource();
                cone.SetHeight(3.0f);
                cone.SetRadius(1.0f);
                cone.SetResolution(30);

                vtk.vtkPolyDataMapper coneMapper = new vtk.vtkPolyDataMapper();
                coneMapper.SetInput(cone.GetOutput());

                vtk.vtkActor coneActor = new vtk.vtkActor();
                coneActor.SetMapper(coneMapper);

                vtk.vtkRenderer ren1 = new vtk.vtkRenderer();
                ren1.AddActor(coneActor);
                ren1.SetBackground(0.0f, 0.0f, 0.0f);
                renWin.AddRenderer(ren1);
            }

            void AddDicomToWindow(vtk.vtkRenderWindow renWin)
            {
                try
                {
                    vtkDICOMImageReader reader = new vtkDICOMImageReader();

                    reader.SetFileName("C:/MedData/Import1/SIMON_10.dcm");
                    reader.SetDataByteOrderToLittleEndian();

                    vtkImageData image1 = new vtkImageData();
                    image1 = reader.GetOutput();

                    vtkImageMapper mapper1 = new vtkImageMapper();
                    mapper1.SetInput(image1);

                    vtkActor2D actor1 = new vtkActor2D();
                    actor1.SetMapper(mapper1);

                    vtkRenderer ren = new vtkRenderer();
                    ren.AddActor2D(actor1);
                    renWin.AddRenderer(ren);

                    renWin.SetSize(vtkForm4.Size.Width, vtkForm4.Size.Height);
                    vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();

                    iren.SetRenderWindow(renWin);
                    renWin.Render();//

                    iren.Initialize();
                    iren.Start();
                    //renWin.Dispose();

                }
                catch (Exception e)
                {
                   // MessageBox.Show(e.Message + "\n" + e.StackTrace);
                }

            }

            private void button2_Click(object sender, EventArgs e)
            {
                this.AddDicomToWindow(this.vtkForm4.GetRenderWindow());
            }

        }
    }

     
    • Bane D
      Bane D
      2009-06-15

      I am having a similar issue with VTK.net with my graduate project. This appears to be a common issue with vtk.net and it could be related to the amount of memory allocated to .net framework in windows. Restricting the amount of memory that vtk uses has not resolved my problem either.