# Why do (bgl) exceptions in modal crash blender

No matter what I type into the console, or execute from the text buffer, blender shows an error but continues on as usual. However, I recently noticed that many exceptions (involving bgl callbacks) make blender crash if they happen inside the modal operator.

Why is that?

• care to elaborate on the code in the modal function? bgl callbacks? – zeffii Apr 26 '15 at 7:41

## 1 Answer

### bgl callbacks

The modal part of your operator needs to return something each time it's called, in the case of an exception that is probably return {'CANCELLED'}. Most exceptions are not fatal, but exceptions in bgl callbacks can be.

One crash is one too many, you might have to stick in a try/except (with traceback), at least until you find the cause of the exception in the bgl callback and find a way to prevent it, you also need to correct the GL state before the callback function ends. Else expect undefined behaviour.

• Yes, bgl callbacks indeed, but I was more curious as to why it isn't "safety-wrapped" like the other execution contexts, than looking for a solution. I did co with try/except blocks, no worries. – Ludwik Apr 26 '15 at 7:41
• modal bgl is one of the few scenarios where i've seen pretty gruesome 'close to desktop' style crashing. Solved by correcting the logic in the bgl callback.. I think you are right to ask why that should be any different, it perhaps deserves a dedicated question, or rename your question to include the term involving exceptions in bgl callbacks – zeffii Apr 26 '15 at 7:49
• I might do that later today – Ludwik Apr 26 '15 at 9:57