Debugging mode?

I’ve been running a script(the current version of Pantograph) that crashes Blender (seg fault) about 25% of the time. I’d like to fix this once and for all - but the debug mode of Blender doesn’t give any info on the crash. I’d like to isolate what happens or at least file a decent bug, but the crash happens at slightly different places in the script (memory problem?) and gives up no useful information.

Any of the wizards out there have a good idea?

Best,
RS

I use print statements to track where the code flows. When it stops flowing, you go back to the last print issued and look for errors.

If you can get it to crash by running via command line (i.e. set up Blender to run your script from command line), you could try one of the standard debug tools like gdb or something similar (some of the other tools, especially for memory inspection escape me, but they’re out there). You can then go in and inspect pretty much everything, and figure out pretty accurately what’s happening/what’s the cause.

Is the crash consistent at least to within a function, loop, etc. just occurring at different operations within that block?

@Atom,
Yeah, me too!

@forTe,
I’ll check that out. It happens at inconsistent points - I tried putting in markers, but its definitely not one single statement. I thought it was a BGL problem (this happened when I added a Blender GUI), but now I’m not sure.

RS

Hi RocketShip,
This is very possible if you use SPE (the Python IDE for Blender) with the WinPDB debugger:

sudo apt-get install spe

You just can add a breakpoint by adding:

import rpdb2; rpdb2.start_embedded_debugger('password')

When your scripts finds this line, it will take a break and wait until you’ve attached the debugger. So place this script just before where you would expect the bug to happen.

To do this, just start the winpdb debugger and choose File>Attach, give your password and WinPDB lets you step through your gui with your program. You can even inspect local variables and change values and so on…

I’ve been debugging my python applications and works like a charm. If you have no clue where the bug occurs and your program does not crash Blender, but just throws an exception, press the run button in WinPdb. When an exception occurs, WinPdb lets you analyze it.

Stani,

I use SPE every day :slight_smile:

Would this help debug a crash in blender-bin, though? I’d love to get a trace of what happens until the seg-fault. It happens at roughly the same time, but I can’t isolate any Python call that is making it happen. I’m assuming this is a Blender bug - Python shouldn’t be able to crash the whole program without throwing an exception.

I don’t think so. You can only execute your program step by step or run from breakpoint to breakpoint. that might help you. Another suggestion is to dump your locals and globals to a file, so you can review there values to the just before crash value:

import pprint

dump = open('/tmp/locals.py','wb')
dump.write(pprint.pformat(locals())
dump.close()
dump = open('/tmp/globals.py','wb')
dump.write(pprint.pformat(globals())
dump.close()