# AccessViolationException when exit

**URL:** https://discourse.vtk.org/t/accessviolationexception-when-exit/12157
**Category:** Support
**Created:** [August 16, 2023, 6:13am UTC](https://discourse.vtk.org/t/accessviolationexception-when-exit/12157 "2023-08-16T06:13:23Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![liuzhongshu](https://discourse.vtk.org/user_avatar/discourse.vtk.org/liuzhongshu/32/6921_2.png) [@liuzhongshu](https://discourse.vtk.org/u/liuzhongshu)
#### Post date: [August 16, 2023, 6:13am UTC](https://discourse.vtk.org/t/accessviolationexception-when-exit/12157/1 "2023-08-16T06:13:24Z")

</div>

My .net WPF application use [Activiz.net](http://Activiz.net) 5.8, and sometimes will get an exception on exit.

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.  
at Kitware.VTK.vtkObjectBase.vtkObjectBase\_UnRegister\_12(HandleRef pThis, HandleRef o)  
at Kitware.VTK.vtkObjectBase.Dispose(Boolean disposing)  
at Kitware.VTK.vtkOpenGLRenderer.Dispose(Boolean disposing)  
at Kitware.mummy.Runtime.WrappedObject.Finalize()

This exception happens very rarely, usually when it runs for a long time (several hours) and exits.  
How to find the cause of this excepton?

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 17, 2023, 2:08pm UTC](https://discourse.vtk.org/t/accessviolationexception-when-exit/12157/2 "2023-08-17T14:08:04Z")

</div>

@mwestphal

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [August 17, 2023, 2:21pm UTC](https://discourse.vtk.org/t/accessviolationexception-when-exit/12157/3 "2023-08-17T14:21:50Z")

</div>

@LucasGandel @lgivord

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [August 17, 2023, 2:22pm UTC](https://discourse.vtk.org/t/accessviolationexception-when-exit/12157/4 "2023-08-17T14:22:25Z")

</div>

@liuzhongshu Activiz 5.8 is very old, I’m not sure you will find much help with it.

> **[ActiViz - 3D Visualization Library for .Net C# and Unity | Kitware](https://www.kitware.eu/activiz/)**
>
> Unleash the power of the Visualization Toolkit for your 3D content in C#, .Net and Unity Software. Integrate 3D visualization in your application easily.

---

<div class="post-metadata">

### Author: ![lgivord](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lgivord/32/3543_2.png) [@lgivord](https://discourse.vtk.org/u/lgivord)
#### Post date: [August 17, 2023, 2:26pm UTC](https://discourse.vtk.org/t/accessviolationexception-when-exit/12157/5 "2023-08-17T14:26:19Z")

</div>

maybe @alexy.pellegrini may have an idea 🤔

---

<div class="post-metadata">

### Author: ![LucasGandel](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lucasgandel/32/1831_2.png) [@LucasGandel](https://discourse.vtk.org/u/LucasGandel)
#### Post date: [August 22, 2023, 11:07am UTC](https://discourse.vtk.org/t/accessviolationexception-when-exit/12157/6 "2023-08-22T11:07:18Z")

</div>

You might want to check if this still happens with the latest version by requesting a trial version on the Activiz website.

Disposing the renderer and other VTK objects on the WindowsFormHost “closing” event (or any other event triggered before the exception) might also help.

---

<div class="post-metadata">

### Author: ![liuzhongshu](https://discourse.vtk.org/user_avatar/discourse.vtk.org/liuzhongshu/32/6921_2.png) [@liuzhongshu](https://discourse.vtk.org/u/liuzhongshu)
#### Post date: [August 24, 2023, 1:52am UTC](https://discourse.vtk.org/t/accessviolationexception-when-exit/12157/7 "2023-08-24T01:52:43Z")

</div>

@LucasGandel Thanks, I tried Dispose, but the problem still exists.

I will try using a new trial version to compare, but my code is old, I need to modify the code first to be compatible with the new version.
