Skip to content
Newer
Older
100644 142 lines (116 sloc) 3.38 KB
0991a5c @tbradshaw The GtkRadiant sources as originally released under the GPL license.
tbradshaw authored
1 /*
2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
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.
11
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.
16
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
20 */
21
22 #include "error.h"
23
24 #include "debugging/debugging.h"
25 #include "igl.h"
26
27 #include "gtkutil/messagebox.h"
28 #include "console.h"
29 #include "preferences.h"
30
31
32 #ifdef WIN32
33 #define UNICODE
34 #include <windows.h>
35 #endif
36
37 #if defined (__linux__) || defined (__APPLE__)
38 #include <errno.h>
39 #include <unistd.h>
40 #endif
41
42
43
44 /*
45 =================
46 Error
47
48 For abnormal program terminations
49 =================
50 */
51
52 /*!
53 \todo
54 FIXME the prompt wether to do prefs dialog, may not even be possible
55 if the crash happens before the game is loaded
56 */
57
58 void Error (const char *error, ...)
59 {
60 va_list argptr;
61 char text[4096];
62
63 va_start (argptr,error);
64 vsprintf (text, error,argptr);
65 va_end (argptr);
66
67 strcat( text, "\n" );
68
69 #if defined (__linux__) || defined (__APPLE__)
70 if (errno != 0)
71 {
72 strcat( text, "errno: " );
73 strcat( text, strerror (errno));
74 strcat( text, "\n");
75 }
76 #endif
77
78 #ifdef WIN32
79 if (GetLastError() != 0)
80 {
81 LPVOID lpMsgBuf;
82 FormatMessage(
83 FORMAT_MESSAGE_ALLOCATE_BUFFER |
84 FORMAT_MESSAGE_FROM_SYSTEM |
85 FORMAT_MESSAGE_IGNORE_INSERTS,
86 0,
87 GetLastError(),
88 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
89 (LPTSTR) &lpMsgBuf,
90 0,
91 0
92 );
93 strcat( text, "GetLastError: " );
94 /*
95 Gtk will only crunch 0<=char<=127
96 this is a bit hackish, but I didn't find useful functions in win32 API for this
97 http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=516
98 */
99 TCHAR *scan, *next = (TCHAR*)lpMsgBuf;
100 do
101 {
102 scan = next;
103 text[strlen(text)+1] = '\0';
104 if ((scan[0] >= 0) && (scan[0] <= 127))
105 text[strlen(text)] = char(scan[0]);
106 else
107 text[strlen(text)] = '?';
108 next = CharNext(scan);
109 } while (next != scan);
110 strcat( text, "\n");
111 LocalFree( lpMsgBuf );
112 }
113 #endif
114
115 #if 0
116 // we need to have a current context to call glError()
117 if (g_glwindow_globals.d_glBase != 0)
118 {
119 // glGetError .. can record several errors, clears after calling
120 //++timo TODO: be able to deal with several errors if necessary, for now I'm just warning about pending error messages
121 // NOTE: forget that, most boards don't seem to follow the OpenGL standard
122 GLenum iGLError = glGetError();
123 if (iGLError != GL_NO_ERROR)
124 {
125 // use our own gluErrorString
126 strcat( text, "gluErrorString: " );
127 strcat( text, (char*)gluErrorString( iGLError ) );
128 strcat( text, "\n" );
129 }
130 }
131 #endif
132
133 strcat (text, "An unrecoverable error has occured.\n");
134
135 ERROR_MESSAGE(text);
136
137 // force close logging if necessary
138 Sys_LogFile(false);
139
140 _exit (1);
141 }
Something went wrong with that request. Please try again.