]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/error.cpp
Initial python support
[xonotic/netradiant.git] / radiant / error.cpp
index 4044cb742c80c91481479b349833b3d5d768cad3..375a9dd64fd5b9f08af965dda469dddef1967105 100644 (file)
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 1999-2007 id Software, Inc. and contributors.
+   Copyright (C) 1999-2006 Id Software, Inc. and contributors.
    For a list of contributors, see the accompanying CONTRIBUTORS file.
 
    This file is part of GtkRadiant.
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include "error.h"
+#include "globaldefs.h"
+
+#include "debugging/debugging.h"
+#include "igl.h"
+
+#include "gtkutil/messagebox.h"
+#include "console.h"
+#include "preferences.h"
+
+
+#if GDEF_OS_WINDOWS
 #define UNICODE
-#include "stdafx.h"
+#include <windows.h>
+#else
 
-#if defined ( __linux__ ) || defined ( __APPLE__ )
+#include <errno.h>
 #include <unistd.h>
+
 #endif
 
+
+
 /*
    =================
    Error
    if the crash happens before the game is loaded
  */
 
-void Error( const char *error, ... ){
-       va_list argptr;
-       char text[4096];
-
-       va_start( argptr,error );
-       vsprintf( text, error,argptr );
-       va_end( argptr );
-
-       strcat( text, "\n" );
-
-#if defined ( __linux__ ) || defined ( __APPLE__ )
-       if ( errno != 0 ) {
-               strcat( text, "errno: " );
-               strcat( text, strerror( errno ) );
-               strcat( text, "\n" );
-       }
+void Error(const char *error, ...)
+{
+    va_list argptr;
+    char text[4096];
+
+    va_start(argptr, error);
+    vsprintf(text, error, argptr);
+    va_end(argptr);
+
+    strcat(text, "\n");
+
+#if GDEF_OS_WINDOWS
+    if ( GetLastError() != 0 ) {
+        LPVOID lpMsgBuf;
+        FormatMessage(
+            FORMAT_MESSAGE_ALLOCATE_BUFFER |
+            FORMAT_MESSAGE_FROM_SYSTEM |
+            FORMAT_MESSAGE_IGNORE_INSERTS,
+            0,
+            GetLastError(),
+            MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), // Default language
+            (LPTSTR) &lpMsgBuf,
+            0,
+            0
+            );
+        strcat( text, "GetLastError: " );
+        /*
+           Gtk will only crunch 0<=char<=127
+           this is a bit hackish, but I didn't find useful functions in win32 API for this
+           http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=516
+         */
+        TCHAR *scan, *next = (TCHAR*)lpMsgBuf;
+        do
+        {
+            scan = next;
+            text[strlen( text ) + 1] = '\0';
+            if ( ( scan[0] >= 0 ) && ( scan[0] <= 127 ) ) {
+                text[strlen( text )] = char(scan[0]);
+            }
+            else{
+                text[strlen( text )] = '?';
+            }
+            next = CharNext( scan );
+        } while ( next != scan );
+        strcat( text, "\n" );
+        LocalFree( lpMsgBuf );
+    }
+#else
+    if (errno != 0) {
+        strcat(text, "errno: ");
+        strcat(text, strerror(errno));
+        strcat(text, "\n");
+    }
 #endif
 
-#ifdef _WIN32
-       if ( GetLastError() != 0 ) {
-               LPVOID lpMsgBuf;
-               FormatMessage(
-                       FORMAT_MESSAGE_ALLOCATE_BUFFER |
-                       FORMAT_MESSAGE_FROM_SYSTEM |
-                       FORMAT_MESSAGE_IGNORE_INSERTS,
-                       NULL,
-                       GetLastError(),
-                       MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), // Default language
-                       (LPTSTR) &lpMsgBuf,
-                       0,
-                       NULL
-                       );
-               strcat( text, "GetLastError: " );
-               /*
-                  Gtk will only crunch 0<=char<=127
-                  this is a bit hackish, but I didn't find useful functions in win32 API for this
-                */
-               TCHAR *scan, *next = (TCHAR*)lpMsgBuf;
-               do
-               {
-                       scan = next;
-                       text[strlen( text ) + 1] = '\0';
-                       if ( ( scan[0] >= 0 ) && ( scan[0] <= 127 ) ) {
-                               text[strlen( text )] = scan[0];
-                       }
-                       else{
-                               text[strlen( text )] = '?';
-                       }
-                       next = CharNext( scan );
-               } while ( next != scan );
-               strcat( text, "\n" );
-               LocalFree( lpMsgBuf );
-       }
+
+#if 0
+    // we need to have a current context to call glError()
+    if ( g_glwindow_globals.d_glBase != 0 ) {
+        // glGetError .. can record several errors, clears after calling
+        //++timo TODO: be able to deal with several errors if necessary, for now I'm just warning about pending error messages
+        // NOTE: forget that, most boards don't seem to follow the OpenGL standard
+        GLenum iGLError = glGetError();
+        if ( iGLError != GL_NO_ERROR ) {
+            // use our own gluErrorString
+            strcat( text, "gluErrorString: " );
+            strcat( text, (char*)gluErrorString( iGLError ) );
+            strcat( text, "\n" );
+        }
+    }
 #endif
 
-       // we need to have a current context to call glError()
-       if ( g_qeglobals_gui.d_glBase != NULL ) {
-               // qglGetError .. can record several errors, clears after calling
-               //++timo TODO: be able to deal with several errors if necessary, for now I'm just warning about pending error messages
-               // NOTE: forget that, most boards don't seem to follow the OpenGL standard
-               GLenum iGLError = qglGetError();
-               if ( iGLError != GL_NO_ERROR ) {
-                       // use our own gluErrorString
-                       strcat( text, "qgluErrorString: " );
-                       strcat( text, (char*)qgluErrorString( iGLError ) );
-                       strcat( text, "\n" );
-               }
-       }
-
-       strcat( text, "An unrecoverable error has occured.\n"
-                                 "Would you like to edit Preferences before exiting Radiant?" );
-
-       Sys_Printf( text );
-
-       if ( gtk_MessageBox( NULL, text, "Error", MB_YESNO ) == IDYES ) {
-               Sys_Printf( "Doing prefs..\n" );
-               g_PrefsDlg.LoadPrefs();
-               g_PrefsDlg.DoModal();
-       }
-
-       QGL_Shutdown();
-
-       g_PrefsDlg.Destroy();
-       g_dlgSurface.Destroy();
-       g_dlgFind.Destroy();
-
-       // force close logging if necessary
-       g_PrefsDlg.mGamesDialog.m_bLogConsole = false;
-       Sys_LogFile();
-
-       _exit( 1 );
-}
+    strcat(text, "An unrecoverable error has occured.\n");
 
-void WINAPI Error( char *error, ... ){
-       va_list argptr;
-       char text[1024];
+    ERROR_MESSAGE(text);
 
-       va_start( argptr,error );
-       vsprintf( text, error,argptr );
-       va_end( argptr );
+    // force close logging if necessary
+    Sys_LogFile(false);
 
-       Error( (const char *)text );
+    _exit(1);
 }