Index: trunk/src/lib/event/event_handler.cc
===================================================================
--- trunk/src/lib/event/event_handler.cc	(revision 9235)
+++ trunk/src/lib/event/event_handler.cc	(revision 9240)
@@ -507,6 +507,6 @@
 int EventHandler::releaseMouse(void* p)
 {
+  SDL_ShowCursor(SDL_ENABLE);
   SDL_WM_GrabInput(SDL_GRAB_OFF);
-  SDL_ShowCursor(SDL_DISABLE);
   return 0;
 }
Index: trunk/src/lib/gui/gl/glgui_handler.cc
===================================================================
--- trunk/src/lib/gui/gl/glgui_handler.cc	(revision 9235)
+++ trunk/src/lib/gui/gl/glgui_handler.cc	(revision 9240)
@@ -268,7 +268,7 @@
 
 
-  Vector2D GLGuiHandler::cursorPositionOverFocusedWidget() const
-  {
-    return (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(0,0);
+  const Vector2D& GLGuiHandler::cursorPositionOverFocusedWidget() const
+  {
+    return (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D::nullVector();
   }
 
Index: trunk/src/lib/gui/gl/glgui_handler.h
===================================================================
--- trunk/src/lib/gui/gl/glgui_handler.h	(revision 9235)
+++ trunk/src/lib/gui/gl/glgui_handler.h	(revision 9240)
@@ -30,5 +30,5 @@
     GLGuiCursor* cursor() const { return this->_cursor; }
 
-    Vector2D cursorPositionOverFocusedWidget() const;
+    const Vector2D& cursorPositionOverFocusedWidget() const;
     const Vector2D& cursorPositionAbs() const;
     Vector2D cursorPositionRel(const GLGuiWidget* const widget) const;
Index: trunk/src/orxonox.cc
===================================================================
--- trunk/src/orxonox.cc	(revision 9235)
+++ trunk/src/orxonox.cc	(revision 9240)
@@ -88,5 +88,4 @@
 
 #ifndef __WIN32__
-REGISTER_ARG_FLAG( _, start_gdb_on_signal, "misc", "start-gdb", "Start gdb on signal", "1");
 REGISTER_ARG_FLAG( _, write_bt_to_file, "misc", "bt-to-file", "Write backtrace to file", "1");
 #endif
@@ -452,12 +451,7 @@
   }
 
-  if ( Preferences::getInstance()->getString("misc", "start-gdb", "0") == "1" )
-  {
-    SignalHandler::getInstance()->doCatch( argv[0], GDB_RUN_IN_FOREGROUND );
-    SignalHandler::getInstance()->registerCallback(EventHandler::releaseMouse, NULL);
-  }
-  else if ( Preferences::getInstance()->getString("misc", "bt-to-file", "1") == "1" )
-  {
-    SignalHandler::getInstance()->doCatch( argv[0], GDB_RUN_WRITE_TO_FILE );
+  if ( Preferences::getInstance()->getString("misc", "bt-to-file", "1") == "1" )
+  {
+    SignalHandler::getInstance()->doCatch( argv[0] );
 
   }
Index: trunk/src/util/signal_handler.cc
===================================================================
--- trunk/src/util/signal_handler.cc	(revision 9235)
+++ trunk/src/util/signal_handler.cc	(revision 9240)
@@ -21,11 +21,12 @@
 #ifndef __WIN32__
 
+#include <wait.h>
+
 SignalHandler::SignalHandler()
 {
 }
 
-void SignalHandler::doCatch( std::string appName, GdbRunType type )
-{
-  this->type = type;
+void SignalHandler::doCatch( std::string appName )
+{
   this->appName = appName;
 
@@ -77,42 +78,181 @@
 
   printf( "recieved signal %s\ntry to write backtrace to file orxonox.backtrace\n", sigName.c_str() );
-
-  int fd[2];
-
-  assert( pipe(fd) != -1 );
-
-  int pid = fork();
-
-  assert( pid != -1 );
-
-
-  if ( pid == 0 )
+  
+  int sigPipe[2];
+  if ( pipe(sigPipe) == -1 )
+  {
+    perror("pipe failed!\n");
+    exit(EXIT_FAILURE);
+  }
+  
+  int sigPid = fork();
+
+  if ( sigPid == -1 )
+  {
+    perror("fork failed!\n");
+    exit(EXIT_FAILURE);
+  }
+
+  // gdb will be attached to this process
+  if ( sigPid == 0 )
   {
     getInstance()->dontCatch();
-    sleep(2);
+    // wait for message from parent when it has attached gdb
+    int someData;
+
+    read( sigPipe[0], &someData, sizeof(someData) );
+
+    if ( someData != 0x12345678 )
+    {
+      printf("something went wrong :(\n");
+    }
 
     return;
   }
-  else
-  {
-    getInstance()->dontCatch();
-    if ( getInstance()->type == GDB_RUN_WRITE_TO_FILE && fork() == 0 )
-    {
-      sleep(1);
-      write( fd[1], "c\nbt\nq\n", 7 );
-
-      exit(0);
-    }
-
-    char command[256];
-    if ( getInstance()->type == GDB_RUN_WRITE_TO_FILE )
-    {
-      dup2( fd[0], STDIN_FILENO );
-      snprintf( command, 255, "gdb -p %d %s 1>>" GDB_BT_FILE " 2>&1", pid, getInstance()->appName.c_str() );
-    }
-    else
-      snprintf( command, 255, "gdb -p %d %s", pid, getInstance()->appName.c_str() );
-    execlp( "sh", "sh", "-c", command, (void*)NULL);
-  }
+
+  int gdbIn[2];
+  int gdbOut[2];
+  int gdbErr[2];
+  
+  if ( pipe(gdbIn) == -1 || pipe(gdbOut) == -1 || pipe(gdbErr) == -1 )
+  {
+    perror("pipe failed!\n");
+    kill( sigPid, SIGTERM );
+    waitpid( sigPid, NULL, 0 );
+    exit(EXIT_FAILURE);
+  }
+
+  int gdbPid = fork();
+  // this process will run gdb
+  
+  if ( gdbPid == -1 )
+  {
+    perror("fork failed\n");
+    kill( sigPid, SIGTERM );
+    waitpid( sigPid, NULL, 0 );
+    exit(EXIT_FAILURE);
+  }
+  
+  if ( gdbPid == 0 )
+  {
+    // start gdb
+    
+    close(gdbIn[1]);
+    close(gdbOut[0]);
+    close(gdbErr[0]);
+
+    dup2( gdbIn[0], STDIN_FILENO );
+    dup2( gdbOut[1], STDOUT_FILENO );
+    dup2( gdbErr[1], STDERR_FILENO );
+    
+    execlp( "sh", "sh", "-c", "gdb", (void*)NULL);
+  }
+
+  char cmd[256];
+  snprintf( cmd, 256, "file %s\nattach %d\nc\n", getInstance()->appName.c_str(), sigPid );
+  write( gdbIn[1], cmd, strlen(cmd) );
+
+  int charsFound = 0;
+  int promptFound = 0;
+  char byte;
+  while ( read( gdbOut[0], &byte, 1 ) == 1 )
+  {
+    if ( 
+      charsFound == 0 && byte == '(' ||
+      charsFound == 1 && byte == 'g' ||
+      charsFound == 2 && byte == 'd' ||
+      charsFound == 3 && byte == 'b' ||
+      charsFound == 4 && byte == ')' ||
+      charsFound == 5 && byte == ' '
+        )
+          charsFound++;
+
+    if ( charsFound == 6 )
+    {
+      promptFound++;
+      charsFound = 0;
+    }
+
+    if ( promptFound == 3 )
+    {
+      break;
+    }
+  }
+  
+  int someData = 0x12345678;
+  write( sigPipe[1], &someData, sizeof(someData) );
+
+  write( gdbIn[1], "bt\nq\n", 5 );
+
+  
+  charsFound = 0;
+  promptFound = 0;
+  std::string bt;
+  while ( read( gdbOut[0], &byte, 1 ) == 1 )
+  {
+    bt += std::string( &byte, 1 );
+
+    if ( 
+      charsFound == 0 && byte == '(' ||
+      charsFound == 1 && byte == 'g' ||
+      charsFound == 2 && byte == 'd' ||
+      charsFound == 3 && byte == 'b' ||
+      charsFound == 4 && byte == ')' ||
+      charsFound == 5 && byte == ' '
+        )
+          charsFound++;
+
+    if ( charsFound == 6 )
+    {
+      promptFound++;
+      charsFound = 0;
+      bt += "\n";
+    }
+
+    if ( promptFound == 2 )
+    {
+      break;
+    }
+  }
+
+
+  waitpid( sigPid, NULL, 0 );
+  waitpid( gdbPid, NULL, 0 );
+  
+  int wsRemoved = 0;
+
+  while ( wsRemoved < 2 && bt.length() > 0 )
+  {
+    if ( bt[1] == '\n' )
+      wsRemoved++;
+    bt.erase(0, 1);
+  }
+
+  if ( bt.length() > 0 )
+    bt.erase(0, 1);
+
+  time_t now = time(NULL);
+
+  std::string timeString = "\n\n\n\n"
+	                   "=======================================================\n"
+	                   "= time: " + std::string(ctime(&now)) +
+			   "=======================================================\n";
+  bt.insert(0, timeString);
+  
+  FILE * f = fopen( GDB_BT_FILE, "a" );
+
+  if ( !f )
+  {
+    perror("could not append to " GDB_BT_FILE);
+    exit(EXIT_FAILURE);
+  }
+
+  if ( fwrite( bt.c_str(), 1, bt.length(), f ) != bt.length() )
+  {
+    printf("could not write %d byte to " GDB_BT_FILE, bt.length());
+    exit(EXIT_FAILURE);
+  }
+
+  exit(EXIT_FAILURE);
 }
 
Index: trunk/src/util/signal_handler.h
===================================================================
--- trunk/src/util/signal_handler.h	(revision 9235)
+++ trunk/src/util/signal_handler.h	(revision 9240)
@@ -12,8 +12,4 @@
 
 #define GDB_BT_FILE "orxonox.backtrace"
-enum GdbRunType{
-  GDB_RUN_WRITE_TO_FILE = 1,
-  GDB_RUN_IN_FOREGROUND
-};
 
 typedef int (*SignalCallback)( void * someData );
@@ -48,5 +44,5 @@
     void registerCallback( SignalCallback cb, void * someData );
 
-    void doCatch( std::string appName, GdbRunType type = GDB_RUN_WRITE_TO_FILE );
+    void doCatch( std::string appName );
     void dontCatch();
 
@@ -61,6 +57,4 @@
     static SignalHandler * singletonRef;
 
-    GdbRunType type;
-
     std::string appName;
 };
@@ -71,5 +65,5 @@
  public:
    inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; };
-  void doCatch( std::string appName, GdbRunType type = GDB_RUN_WRITE_TO_FILE ) {};
+  void doCatch( std::string appName ) {};
   void dontCatch() {};
   void registerCallback( SignalCallback cb, void * someData ) {};
