DefinesAssert.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #define WIN32_LEAN_AND_MEAN
00022 #include <stdlib.h>
00023 #include <stdarg.h>
00024 #include <common/Defines.h>
00025 #include <common/Logger.h>
00026 #include <windows.h>
00027 #include <string>
00028 
00029 #pragma warning(disable : 4996)
00030 
00031 extern bool wxWindowInit;
00032 
00033 void S3D::dialogMessage(const std::string &header, const std::string &text)
00034 {
00035         std::string newtext;
00036         int count = 0;
00037         for (const char *t=text.c_str(); *t; t++)
00038         {
00039                 if (*t == '\n') count = 0;
00040                 else count++;
00041                 if (count > 75)
00042                 {
00043                         newtext.append("...\n");
00044                         count = 0;
00045                 }
00046 
00047                 newtext.push_back(*t);
00048         }
00049 
00050         // Make sure that this is logged
00051         Logger::log(newtext.c_str());
00052         Logger::instance()->processLogEntries();
00053 
00054         // Show the dialog (if any)
00055 #if defined(_WIN32) && !defined(S3D_SERVER)
00056         MessageBox(NULL, newtext.c_str(), header.c_str(), MB_OK);
00057 #else
00058         printf("%s : %s\n", header.c_str(), newtext.c_str());
00059 #endif
00060 }
00061 
00062 void S3D::glAssert(unsigned int e, const int line, const char *file)
00063 {
00064         // Dont use formatString here as this method is called by formatString.
00065         char buffer[20048];
00066         snprintf(buffer, 20048, "%u\n%i:%s", e, line, file);
00067         //S3D::dialogMessage("GL Assert", buffer);
00068         //exit(64);
00069 }
00070 
00071 void S3D::dialogAssert(const char *lineText, const int line, const char *file)
00072 {
00073         // Dont use formatString here as this method is called by formatString.
00074         char buffer[20048];
00075         snprintf(buffer, 20048, "%s\n%i:%s", lineText, line, file);
00076         S3D::dialogMessage("Program Assert", buffer);
00077         exit(64);
00078 }
00079 
00080 void S3D::dialogExit(const std::string &header, const std::string &text)
00081 {
00082         S3D::dialogMessage(header, text);
00083         exit(64);
00084 }

Generated on Mon Feb 16 15:14:48 2009 for Scorched3D by  doxygen 1.5.3