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:

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

Another mesh is created, all of the polygons facing to the top may be moved.
For each frame from start to end:

A shape key is added to the mesh.

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

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
Okay, I got it working!
As batFINGER already suspected, it was about accessing a removed object.
I had an Vector variable, which was defined only once.
co = ocean.vertices[0].co

This line is now called every time the mesh changes in my script.
I also added a few lines to update bpy.data.meshes/.objects (I don't know if actually necessary), the whole code can be simplified for sure, but hey: it works!