2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "debugging/debugging.h"
27 #include "gtkutil/messagebox.h"
29 #include "preferences.h"
46 For abnormal program terminations
52 FIXME the prompt wether to do prefs dialog, may not even be possible
53 if the crash happens before the game is loaded
56 void Error( const char *error, ... ){
60 va_start( argptr,error );
61 vsprintf( text, error,argptr );
67 if ( GetLastError() != 0 ) {
70 FORMAT_MESSAGE_ALLOCATE_BUFFER |
71 FORMAT_MESSAGE_FROM_SYSTEM |
72 FORMAT_MESSAGE_IGNORE_INSERTS,
75 MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), // Default language
80 strcat( text, "GetLastError: " );
82 Gtk will only crunch 0<=char<=127
83 this is a bit hackish, but I didn't find useful functions in win32 API for this
84 http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=516
86 TCHAR *scan, *next = (TCHAR*)lpMsgBuf;
90 text[strlen( text ) + 1] = '\0';
91 if ( ( scan[0] >= 0 ) && ( scan[0] <= 127 ) ) {
92 text[strlen( text )] = char(scan[0]);
95 text[strlen( text )] = '?';
97 next = CharNext( scan );
98 } while ( next != scan );
100 LocalFree( lpMsgBuf );
104 strcat( text, "errno: " );
105 strcat( text, strerror( errno ) );
106 strcat( text, "\n" );
112 // we need to have a current context to call glError()
113 if ( g_glwindow_globals.d_glBase != 0 ) {
114 // glGetError .. can record several errors, clears after calling
115 //++timo TODO: be able to deal with several errors if necessary, for now I'm just warning about pending error messages
116 // NOTE: forget that, most boards don't seem to follow the OpenGL standard
117 GLenum iGLError = glGetError();
118 if ( iGLError != GL_NO_ERROR ) {
119 // use our own gluErrorString
120 strcat( text, "gluErrorString: " );
121 strcat( text, (char*)gluErrorString( iGLError ) );
122 strcat( text, "\n" );
127 strcat( text, "An unrecoverable error has occured.\n" );
129 ERROR_MESSAGE( text );
131 // force close logging if necessary
132 Sys_LogFile( false );