# Why does my Python script crash Blender (EXCEPTION_ACCESS_VIOLATION)?

I wrote a Python script in Blender which creates a blocky version of an object with an ocean modifier, so you need to have this object added and animated by yourself.

It should work like this:

1. An ocean mesh is created by using the original ocean object's mesh, applying all modifiers.

2. Another mesh is created, all of the polygons facing to the top may be moved.

For each frame from start to end:

3. A shape key is added to the mesh.

4. The shape key data is being filled with rounded positions from the ocean.

5. Keyframes are inserted to make the shape key only influence the mesh at the current frame.

Use the system console to see at which frame it is working at the moment.

But every time I run the script, Blender crashes at a different frame.
The last message (right before the windows close) is this:

Here's my script: BlockyOcean.py

• Please write minimal example code that shows your problem. See stackoverflow.com/help/mcve for the how & why. – dr. Sybren Sep 5 '17 at 10:05
• Maybe related to this question? blender.stackexchange.com/questions/79164/… – lucblender Sep 5 '17 at 10:25
• Firstly welcome, and kudos for having a red hot go. Quite likely the issue is you are referencing an object after it has been removed. The outer loop for o in bpy.data.objects will loop thru all the objects in the file (often scene.objects is a better option) ... but then you are adding to that collection as you go, removing meshes ... it's a little hard to follow.... Questions like these are difficult to answer because you've put a lot of time an effort into writing the script, to which I'd do it this way instead may not be appreciated. – batFINGER Sep 5 '17 at 10:49
• @dr.Sybren ... as long as it's minimal runable and testable .. having to edit in register and import code etc can be a PITA. IMO..(might make a good meta q ) In this case, writing a stripped down version for the question will most likely provide ("debug") a solution. – batFINGER Sep 5 '17 at 10:56
• Please include any relevant code in the question body itself instead of linking to it, just in case the link goes down in future. – Ray Mairlot Sep 5 '17 at 11:18

co = ocean.vertices[0].co