diff --git a/modules/gfx/src/impl/scene_fx.cc b/modules/gfx/src/impl/scene_fx.cc
index de0000484bf41a13d91220a312e54013ac643922..c1f87182e48c09e4f9102a56904117dac0bfab63 100644
--- a/modules/gfx/src/impl/scene_fx.cc
+++ b/modules/gfx/src/impl/scene_fx.cc
@@ -480,7 +480,11 @@ void SceneFX::prep_shadow_map()
     are first reverted, and then the light modelview and projection are applied, resulting (with the
     bias) in the proper 2D lookup into the shadow map
   */
-  shadow_tex_mat_ = bias*pmat*ltrans.GetMatrix()*geom::Invert(Scene::Instance().GetTransform().GetMatrix())*geom::Invert(pmat2);
+  try {
+    shadow_tex_mat_ = bias*pmat*ltrans.GetMatrix()*geom::Invert(Scene::Instance().GetTransform().GetMatrix())*geom::Invert(pmat2);
+  } catch (geom::GeomException& e) {
+    LOG_DEBUG("SceneFX: caught matrix inversion exception in prep_shadow_map()");
+  }
 }
 
 void SceneFX::prep_amb_occlusion()
@@ -516,7 +520,12 @@ void SceneFX::prep_amb_occlusion()
 
   glMatrixMode(GL_TEXTURE);
   glPushMatrix();
-  geom::Mat4 ipm(geom::Transpose(geom::Invert(geom::Transpose(geom::Mat4(pm)))));
+  geom::Mat4 ipm;
+  try {
+    ipm=(geom::Transpose(geom::Invert(geom::Transpose(geom::Mat4(pm)))));
+  } catch (geom::GeomException& e) {
+    LOG_DEBUG("SceneFX: caught matrix inversion exception in prep_amb_occlusion()");
+  }
   glLoadMatrix(ipm.Data());
   glMatrixMode(GL_MODELVIEW);
 
@@ -638,7 +647,11 @@ void SceneFX::prep_beacon()
 
   glGetv(GL_PROJECTION_MATRIX, glpmat);
   geom::Mat4 pmat2(geom::Transpose(geom::Mat4(glpmat)));
-  beacon.mat = geom::Invert(Scene::Instance().GetTransform().GetMatrix())*geom::Invert(pmat2);
+  try {
+    beacon.mat = geom::Invert(Scene::Instance().GetTransform().GetMatrix())*geom::Invert(pmat2);
+  } catch (geom::GeomException& e) {
+    beacon.mat=geom::Mat4();
+  }
 }
 
 void SceneFX::draw_beacon()
diff --git a/modules/gui/src/gosty.cc b/modules/gui/src/gosty.cc
index b881e5093bdd168c37c1679fe1e77ffc9af9448c..a0be0fae0762c45d1ae9596cdf57f65c168d8d5a 100644
--- a/modules/gui/src/gosty.cc
+++ b/modules/gui/src/gosty.cc
@@ -200,6 +200,23 @@ void prepare_scripts(int argc, char** argv, PythonInterpreter& py)
   py.RunScript(argv[1]);
 }
 
+class MyApplication : public QApplication
+{
+public:
+    MyApplication(int argc, char** argv) : QApplication(argc, argv) {}
+    virtual ~MyApplication() {}
+    virtual bool notify(QObject *rec, QEvent *ev)
+    {
+      try {
+        return QApplication::notify(rec, ev);
+      } catch( std::runtime_error& e) {
+        std::cerr << "runtime_error in Qt main loop: " << e.what() << std::endl;
+        exit(0);
+      }
+      return false;
+    }
+};
+
 
 }
 
@@ -208,7 +225,7 @@ int main(int argc, char** argv)
 {
   int dummy_argc=1;
   
-  QApplication app(dummy_argc,argv);
+  MyApplication app(dummy_argc,argv);
   QCoreApplication::setOrganizationName("OpenStructure");
   QCoreApplication::setOrganizationDomain("openstructure.org");
   QCoreApplication::setApplicationName(QString(argv[2]));