How to find corrupted meshes?

I’m still making games in Blender 2.79. That’s my hobby, and always will be. I love this software, I love logic bricks, and solving my idead with it, and that’s enough for me. Sadly sometimes some meshes are getting corrupted, and it can destroy all scene and crash Blender. In the past I found a script to write in concole, and find which meshes have to be repaired. Results were like:

Cube001 (False)
Cube002 (False)
Cube003 (True)
...

And where there was True I knew what to fix. I lost the script, and I cant find it on internet anymore. Can someone help please? I would be greatful for lifetime. I would print the script and put it on frame above my desk. I can’t script but I remember something like this:

for m in D.meshes:
print (true)

There was something more but I dont remember :sob:

1 Like

If you mark your known, “corrupted,” objects with a game property called Corrupted.

image

You can then run this script at runtime and get the names of all of the objects that posses that particular game property.

import bge

def main(self):

  for obj in self.owner.scene.objects:
    for prop in obj.getPropertyNames():
      if prop == "Corrupted":
        print(obj.name)

Side note, moved thread from Python Support to Game Engine Support and Discussion.

The problem is I don’t know what object are corrupted. I don’t even know why they are corrupted. It’s very often thing. I would say for 100 created object there will be 1-5 that I must fix (delete, and create new one) . It’s all about the mesh. Sometimes something bad is happining to some objects. This script I had was showing me the name of objects with bad mesh causing a problem. Once I almost lost all my project, I could not open it becouse Blender was crashing.

1 ) Did you open or import from a blend from Blender 2.79 into a Blender 2.8+ version. Or vice-versa?
2 ) Are you using custom split normals by chance?
3 ) Do you still have the old, check mesh if corrupted script by chance?

  1. No everything is made in 2.79 and stays there
  2. I’ve never heard about it.
  3. I can not find it. I only remember something like this. Probably it’s wrong, and doesn’t work but the script was similar and the same length:
for m in D.meshes:
if m.valiadate(True):
print(m.name);

Or maybe there is another way to find bad meshes, objects that can crash Blender?

I’m guessing that the script was not executed in game. I checked the API and I found a validate method for meshes, in BPY.

Validate geometry, return True when the mesh has had invalid geometry corrected/removed

This should validate the meshes so Blender doesn’t crash when trying to edit them.

import bpy

for o in bpy.data.objects:
    if o.type == 'MESH':
        mesh = o.data
        if mesh.validate():
            print(o.name, 'invalid geometry corrected/removed')
3 Likes

Thank you very much. This script is working, but I can’t see any object name. I only know I have 1 problem now.

Bez tytułu

That’s odd. I get the name of the validated object after running the script via the Text Editor in vanilla Blender 2.79b.

image

I even tried in the Python Console Editor like you did.

I’m using the corrupted Flower_grow.blend test blend from here.

Help please :pray::sob:

The results are printed to the system console when executed from the text editor, and both to the system and the python console when run from the python console. Also, I don’t know why you get those True and False, as the script only prints a message telling you the names of the objects with invalid geometry.

I see no results in the system or python console when I run script from text editor.

The script is almost good. I removed 'invalid geometry corrected/removed' and now I have the list with names of objects. Is it the list of bad meshes?

But the script can be used only one time. There is no more results if I run it again :headstone:

It’s possible you accidentally clicked into the terminal on load. This is well known to pause the terminal until you hit escape.

Side question, what kind of operating system are you using?

They should be, yes.

After you run the script, don’t save your blend. Instead just re-open your blend and the changes shouldn’t be saved when you load your blend.

The text you removed explains why there are no more results when you run the script again: validate corrects or removes the invalid geometry from the mesh data, that’s why the second time it shows nothing: all the meshes are already valid.
You can always copy the results of the first run from the console or even output it to a text block.

So something was removed, and I don’t know what. Nice.

You can use validate(True) to show what has been checked and the invalid mesh data fixed, but it will show it for every mesh, valid or not. It removes references to indices out of range, egdes with matching vertex indices, etc. You can’t use validate without it fixing those errors, that’s how it works. Maybe it’s something else that you were using, you should check the API documentation.

Yes it was just showing the list of all objects with True or False. When I saw False on the list, I knew what to fix. But removing corrupted objects is shocking to me. However, thank you all <3

Validate doesn’t remove the objects, just corrects or removes any invalid mesh data.

1 Like

That’s great! So the script is good. Thank you very much :smiley: