TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::_internal Namespace Reference

Classes

class  _BinaryFormat
 
class  _GetComputeType
 
class  BasicThread
 
class  Indirector
 
class  VN
 
class  VNTi
 
class  Welder
 
class  WeldHelper
 

Functions

bool _handleDebugAssert_ (const char *expression, const std::string &message, const char *filename, int lineNumber, bool useGuiPrompt)
 
bool _handleErrorCheck_ (const char *expression, const std::string &message, const char *filename, int lineNumber, bool useGuiPrompt)
 
void _releaseInputGrab_ ()
 
void _restoreInputGrab_ ()
 
const char ** smartEnumParseNames (const char *enumValList)
 
G3DSpecificationg3dInitializationSpecification ()
 
static void createErrorMessage (const char *expression, const std::string &message, const char *filename, int lineNumber, std::string &outTitle, std::string &outMessage)
 

Variables

AssertionHook _debugHook = _handleDebugAssert_
 
AssertionHook _failureHook = _handleErrorCheck_
 
ConsolePrintHook _consolePrintHook
 
Set< std::string > currentFilesUsed
 

Function Documentation

bool G3D::_internal::_handleDebugAssert_ ( const char *  expression,
const std::string &  message,
const char *  filename,
int  lineNumber,
bool  useGuiPrompt 
)

Pops up an assertion dialog or prints an assertion

ignoreAlways - return result of pressing the ignore button. useGuiPrompt - if true, shows a dialog

141  {
142 
143  std::string dialogTitle = "Assertion Failure";
144  std::string dialogText = "";
145  createErrorMessage(expression, message, filename, lineNumber, dialogTitle, dialogText);
146 
147  #ifdef G3D_WINDOWS
148  DWORD lastErr = GetLastError();
149  postToClipboard(dialogText.c_str());
150  debugPrintf("\n%s\n", dialogText.c_str());
151  #endif
152 
153  const int cBreak = 0;
154  const int cIgnore = 1;
155  const int cAbort = 2;
156 
157  static const char* choices[] = {"Debug", "Ignore", "Exit"};
158 
159  // Log the error
160  Log::common()->print(std::string("\n**************************\n\n") + dialogTitle + "\n" + dialogText);
161 
162  int result = G3D::prompt(dialogTitle.c_str(), dialogText.c_str(), (const char**)choices, 3, useGuiPrompt);
163 
164 # ifdef G3D_WINDOWS
165  // Put the incoming last error back.
166  SetLastError(lastErr);
167 # endif
168 
169  switch (result) {
170  // -1 shouldn't actually occur because it means
171  // that we're in release mode.
172  case -1:
173  case cBreak:
174  return true;
175  break;
176 
177  case cIgnore:
178  return false;
179  break;
180 
181  case cAbort:
182  exit(-1);
183  break;
184  }
185 
186  // Should never get here
187  return false;
188 }
std::string __cdecl debugPrintf(const char *fmt...) G3D_CHECK_PRINTF_ARGS
Definition: debugAssert.cpp:355
static void createErrorMessage(const char *expression, const std::string &message, const char *filename, int lineNumber, std::string &outTitle, std::string &outMessage)
Definition: debugAssert.cpp:69
int prompt(const char *windowTitle, const char *promptx, const char **choice, int numChoices, bool useGui)
Definition: prompt.cpp:553
void SetLastError(int nError)
Definition: Common.cpp:75
static FileSystem * common
Definition: FileSystem.cpp:45
unsigned int DWORD
Definition: CascPort.h:139
int GetLastError()
Definition: Common.cpp:70

+ Here is the call graph for this function:

bool G3D::_internal::_handleErrorCheck_ ( const char *  expression,
const std::string &  message,
const char *  filename,
int  lineNumber,
bool  useGuiPrompt 
)
196  {
197 
198  std::string dialogTitle = "Critical Error";
199  std::string dialogText = "";
200 
201  createErrorMessage(expression, message, filename, lineNumber, dialogTitle, dialogText);
202 
203  // Log the error
204  Log::common()->print(std::string("\n**************************\n\n") + dialogTitle + "\n" + dialogText);
205  #ifdef G3D_WINDOWS
206  DWORD lastErr = GetLastError();
207  (void)lastErr;
208  postToClipboard(dialogText.c_str());
209  debugPrintf("\n%s\n", dialogText.c_str());
210  #endif
211 
212  static const char* choices[] = {"Ok"};
213 
214  const std::string& m =
215  std::string("An internal error has occured in this program and it will now close. "
216  "The specific error is below. More information has been saved in \"") +
217  Log::getCommonLogFilename() + "\".\n\n" + dialogText;
218 
219  int result = G3D::prompt("Error", m.c_str(), (const char**)choices, 1, useGuiPrompt);
220  (void)result;
221 
222  return true;
223 }
std::string __cdecl debugPrintf(const char *fmt...) G3D_CHECK_PRINTF_ARGS
Definition: debugAssert.cpp:355
static void createErrorMessage(const char *expression, const std::string &message, const char *filename, int lineNumber, std::string &outTitle, std::string &outMessage)
Definition: debugAssert.cpp:69
int prompt(const char *windowTitle, const char *promptx, const char **choice, int numChoices, bool useGui)
Definition: prompt.cpp:553
static FileSystem * common
Definition: FileSystem.cpp:45
unsigned int DWORD
Definition: CascPort.h:139
int GetLastError()
Definition: Common.cpp:70

+ Here is the call graph for this function:

void G3D::_internal::_releaseInputGrab_ ( )

Attempts to give the user back their mouse and keyboard if they were locked to the current window.

233  {
234  #ifdef G3D_WINDOWS
235 
236  GetCursorPos(&oldCursorPos);
237 
238  // Stop hiding the cursor if the application hid it.
239  oldShowCursorCount = ShowCursor(true) - 1;
240 
241  if (oldShowCursorCount < -1) {
242  for (int c = oldShowCursorCount; c < -1; ++c) {
243  ShowCursor(true);
244  }
245  }
246 
247  // Set the default cursor in case the application
248  // set the cursor to NULL.
249  oldCursor = GetCursor();
250  SetCursor(LoadCursor(NULL, IDC_ARROW));
251 
252  // Allow the cursor full access to the screen
253  GetClipCursor(&oldCursorRect);
254  ClipCursor(NULL);
255 
256  #elif defined(G3D_LINUX)
257 #if 0 /* G3DFIX: Disabled to avoid requirement for X11 libraries */
258  if (x11Display != NULL) {
259  XUngrabPointer(x11Display, CurrentTime);
260  XUngrabKeyboard(x11Display, CurrentTime);
261  if (x11Window != 0) {
262  //XUndefineCursor(x11Display, x11Window);
263  // TODO: Note that we leak this cursor; it should be
264  // freed in the restore code.
265  Cursor c = XCreateFontCursor(x11Display, 68);
266  XDefineCursor(x11Display, x11Window, c);
267  }
268  XSync(x11Display, false);
269  XAllowEvents(x11Display, AsyncPointer, CurrentTime);
270  XFlush(x11Display);
271  }
272 #endif
273  #elif defined(G3D_OSX)
274  // TODO: OS X
275  #endif
276 }
arena_t NULL
Definition: jemalloc_internal.h:624
void G3D::_internal::_restoreInputGrab_ ( )

Attempts to restore the state before releaseInputGrab.

279  {
280  #ifdef G3D_WINDOWS
281 
282  // Restore the old clipping region
283  ClipCursor(&oldCursorRect);
284 
285  SetCursorPos(oldCursorPos.x, oldCursorPos.y);
286 
287  // Restore the old cursor
288  SetCursor(oldCursor);
289 
290  // Restore old visibility count
291  if (oldShowCursorCount < 0) {
292  for (int c = 0; c > oldShowCursorCount; --c) {
293  ShowCursor(false);
294  }
295  }
296 
297  #elif defined(G3D_LINUX)
298  // TODO: Linux
299  #elif defined(G3D_OSX)
300  // TODO: OS X
301  #endif
302 }
static void G3D::_internal::createErrorMessage ( const char *  expression,
const std::string &  message,
const char *  filename,
int  lineNumber,
std::string &  outTitle,
std::string &  outMessage 
)
static

outTitle should be set before the call

75  {
76 
77  std::string le = "";
78  const char* newline = "\n";
79 
80  #ifdef G3D_WINDOWS
81  newline = "\r\n";
82 
83  // The last error value. (Which is preserved across the call).
84  DWORD lastErr = GetLastError();
85 
86  // The decoded message from FormatMessage
87  LPTSTR formatMsg = NULL;
88 
89  if (NULL == formatMsg) {
90  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
91  FORMAT_MESSAGE_IGNORE_INSERTS |
92  FORMAT_MESSAGE_FROM_SYSTEM,
93  NULL,
94  lastErr,
95  0,
96  (LPTSTR)&formatMsg,
97  0,
98  NULL);
99  }
100 
101  // Make sure the message got translated into something.
102  LPTSTR realLastErr;
103  if (NULL != formatMsg) {
104  realLastErr = formatMsg;
105  } else {
106  realLastErr = _T("Last error code does not exist.");
107  }
108 
109  if (lastErr != 0) {
110  le = G3D::format("Last Error (0x%08X): %s\r\n\r\n", lastErr, (LPCSTR)realLastErr);
111  }
112 
113  // Get rid of the allocated memory from FormatMessage.
114  if (NULL != formatMsg) {
115  LocalFree((LPVOID)formatMsg);
116  }
117 
118  char modulePath[MAX_PATH];
119  GetModuleFileNameA(NULL, modulePath, MAX_PATH);
120 
121  const char* moduleName = strrchr(modulePath, '\\');
122  outTitle = outTitle + string(" - ") + string(moduleName ? (moduleName + 1) : modulePath);
123 
124  #else
125  (void)outTitle;
126  #endif
127 
128  // Build the message.
129  outMessage =
130  G3D::format("%s%s%sExpression: %s%s%s:%d%s%s%s",
131  message.c_str(), newline, newline, expression, newline,
132  filename, lineNumber, newline, newline, le.c_str());
133 }
#define MAX_PATH
Definition: CascPort.h:160
arena_t NULL
Definition: jemalloc_internal.h:624
#define _T(x)
Definition: CascPort.h:171
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
unsigned int DWORD
Definition: CascPort.h:139
int GetLastError()
Definition: Common.cpp:70

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

G3DSpecification& G3D::_internal::g3dInitializationSpecification ( )

Set by initG3D, defined in initG3D.cpp

const char** G3D::_internal::smartEnumParseNames ( const char *  enumValList)

Variable Documentation

ConsolePrintHook G3D::_internal::_consolePrintHook
AssertionHook G3D::_internal::_debugHook = _handleDebugAssert_
AssertionHook G3D::_internal::_failureHook = _handleErrorCheck_
Set<std::string> G3D::_internal::currentFilesUsed