diff --git a/source/g3d_viewer/renderer.cpp b/source/g3d_viewer/renderer.cpp index 1f9ea2e21..55bce5a49 100644 --- a/source/g3d_viewer/renderer.cpp +++ b/source/g3d_viewer/renderer.cpp @@ -489,7 +489,7 @@ Texture2D * Renderer::getPlayerColorTexture(PlayerColor playerColor) { customTexture= customTextureMagenta; break; default: - assert(false); + throw megaglest_runtime_error("Unknown playercolor: " + intToStr(playerColor)); break; } diff --git a/source/glest_game/ai/path_finder.cpp b/source/glest_game/ai/path_finder.cpp index 14b99a2c7..11f3814e5 100644 --- a/source/glest_game/ai/path_finder.cpp +++ b/source/glest_game/ai/path_finder.cpp @@ -11,7 +11,6 @@ #include "path_finder.h" #include -#include #include "config.h" #include "map.h" @@ -1173,7 +1172,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout //a) push starting pos into openNodes Node *firstNode= newNode(factions[unitFactionIndex],maxNodeCount); - assert(firstNode != NULL); if(firstNode == NULL) { throw megaglest_runtime_error("firstNode == NULL"); } diff --git a/source/glest_game/ai/path_finder.h b/source/glest_game/ai/path_finder.h index b370323d6..7f0604341 100644 --- a/source/glest_game/ai/path_finder.h +++ b/source/glest_game/ai/path_finder.h @@ -216,7 +216,6 @@ private: //Node * minHeuristicFastLookup(FactionState &faction); inline static Node * minHeuristicFastLookup(FactionState &faction) { - assert(faction.openNodesList.empty() == false); if(faction.openNodesList.empty() == true) { throw megaglest_runtime_error("openNodesList.empty() == true"); } diff --git a/source/glest_game/facilities/components.cpp b/source/glest_game/facilities/components.cpp index 2bf040569..4882cb781 100644 --- a/source/glest_game/facilities/components.cpp +++ b/source/glest_game/facilities/components.cpp @@ -11,7 +11,6 @@ #include "components.h" -//#include #include #include "metrics.h" diff --git a/source/glest_game/world/tileset.cpp b/source/glest_game/world/tileset.cpp index d792751ba..ea1f48505 100644 --- a/source/glest_game/world/tileset.cpp +++ b/source/glest_game/world/tileset.cpp @@ -227,15 +227,50 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck else { // read single big texture and cut it into pieces const XmlNode *textureNode= surfaceNode->getChild("texture", 0); - Pixmap2D *pixmap=new Pixmap2D(); - pixmap->init(3); - pixmap->load(textureNode->getAttribute("path")->getRestrictedValue(currentPath)); - loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile,textureNode->getAttribute("path")->getRestrictedValue())); - int width=pixmap->getW(); - int heith=pixmap->getW(); + + // There is no way to figure out parts without loading the texture + // unfortunately we must load it even for headless server + // to get width and height + bool switchOffNonGraphicalModeEnabled = GlobalStaticFlags::getIsNonGraphicalModeEnabled(); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + GlobalStaticFlags::setIsNonGraphicalModeEnabled(false); + } + + string exceptionError = ""; + Pixmap2D *pixmap = NULL; + int width = 0; + int heith = 0; + + try { + pixmap=new Pixmap2D(); + pixmap->init(3); + pixmap->load(textureNode->getAttribute("path")->getRestrictedValue(currentPath)); + loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile,textureNode->getAttribute("path")->getRestrictedValue())); + + width = pixmap->getW(); + heith = pixmap->getW(); + } + catch(const exception &ex) { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + + exceptionError = "Error: " + path + "\n" + ex.what(); + } + + if(switchOffNonGraphicalModeEnabled == true) { + GlobalStaticFlags::setIsNonGraphicalModeEnabled(true); + + delete pixmap; + pixmap = NULL; + } + + if(exceptionError != "") { + throw megaglest_runtime_error(exceptionError.c_str()); + } + assert(width==heith); assert(width%64==0); assert(width%partsize==0); + int parts=width/partsize; int numberOfPieces=parts*parts; partsArray[i]=parts; @@ -244,9 +279,11 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck int j=0; for(int x = 0; x < parts; ++x) { for(int y = 0; y < parts; ++y) { - surfPixmaps[i][j] = new Pixmap2D(); - surfPixmaps[i][j]->init(partsize,partsize,3); - surfPixmaps[i][j]->copyImagePart(x*partsize,y*partsize,pixmap); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { + surfPixmaps[i][j] = new Pixmap2D(); + surfPixmaps[i][j]->init(partsize,partsize,3); + surfPixmaps[i][j]->copyImagePart(x*partsize,y*partsize,pixmap); + } surfProbs[i][j]=-1; j++; } diff --git a/source/shared_lib/sources/graphics/BMPReader.cpp b/source/shared_lib/sources/graphics/BMPReader.cpp index 094a543e0..60dd95fe7 100644 --- a/source/shared_lib/sources/graphics/BMPReader.cpp +++ b/source/shared_lib/sources/graphics/BMPReader.cpp @@ -74,7 +74,9 @@ BMPReader::BMPReader(): FileReader(getExtensionsBmp()) {} *Path is used for printing error messages *@return NULL if the Pixmap2D could not be read, else the pixmap*/ Pixmap2D* BMPReader::read(ifstream& in, const string& path, Pixmap2D* ret) const { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } //read file header BitmapFileHeader fileHeader; diff --git a/source/shared_lib/sources/graphics/JPGReader.cpp b/source/shared_lib/sources/graphics/JPGReader.cpp index bcbac6674..1dfd9b7d7 100644 --- a/source/shared_lib/sources/graphics/JPGReader.cpp +++ b/source/shared_lib/sources/graphics/JPGReader.cpp @@ -70,7 +70,10 @@ static inline std::vector getExtensions() { JPGReader::JPGReader(): FileReader(getExtensions()) {} Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + //Read file is.seekg(0, ios::end); streampos length = is.tellg(); diff --git a/source/shared_lib/sources/graphics/PNGReader.cpp b/source/shared_lib/sources/graphics/PNGReader.cpp index 1544f8a78..1af6899ec 100644 --- a/source/shared_lib/sources/graphics/PNGReader.cpp +++ b/source/shared_lib/sources/graphics/PNGReader.cpp @@ -63,7 +63,10 @@ static inline std::vector getExtensionsPng() { PNGReader::PNGReader(): FileReader(getExtensionsPng()) {} Pixmap2D* PNGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + //Read file is.seekg(0, ios::end); //size_t length = is.tellg(); diff --git a/source/shared_lib/sources/graphics/TGAReader.cpp b/source/shared_lib/sources/graphics/TGAReader.cpp index 33d12a6e5..c0099821a 100644 --- a/source/shared_lib/sources/graphics/TGAReader.cpp +++ b/source/shared_lib/sources/graphics/TGAReader.cpp @@ -68,7 +68,10 @@ TGAReader3D::TGAReader3D(): FileReader(getExtensionStrings()) {} Pixmap3D* TGAReader3D::read(ifstream& in, const string& path, Pixmap3D* ret) const { //printf("In [%s] line: %d\n",__FILE__,__LINE__); // try { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + //read header TargaFileHeader fileHeader; in.read((char*)&fileHeader, sizeof(TargaFileHeader)); diff --git a/source/shared_lib/sources/graphics/font.cpp b/source/shared_lib/sources/graphics/font.cpp index 4f066b25a..2ad5f7a26 100644 --- a/source/shared_lib/sources/graphics/font.cpp +++ b/source/shared_lib/sources/graphics/font.cpp @@ -218,7 +218,9 @@ string FontMetrics::wordWrapText(string text, int maxWidth) { // =============================================== Font::Font(FontTextHandlerType type) { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } inited = false; this->type = fontTypeName; diff --git a/source/shared_lib/sources/graphics/font_manager.cpp b/source/shared_lib/sources/graphics/font_manager.cpp index 8d069c02c..9835f6fbb 100644 --- a/source/shared_lib/sources/graphics/font_manager.cpp +++ b/source/shared_lib/sources/graphics/font_manager.cpp @@ -15,16 +15,21 @@ #include "graphics_factory.h" #include #include "util.h" +#include "platform_util.h" #include "leak_dumper.h" +using namespace Shared::Platform; using namespace Shared::Util; + namespace Shared { namespace Graphics { // ===================================================== // class FontManager // ===================================================== FontManager::FontManager() { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } fonts.clear(); } diff --git a/source/shared_lib/sources/graphics/interpolation.cpp b/source/shared_lib/sources/graphics/interpolation.cpp index 5ca67cd86..24674be47 100644 --- a/source/shared_lib/sources/graphics/interpolation.cpp +++ b/source/shared_lib/sources/graphics/interpolation.cpp @@ -33,7 +33,9 @@ namespace Shared{ namespace Graphics{ bool InterpolationData::enableCache = false; InterpolationData::InterpolationData(const Mesh *mesh) { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } vertices= NULL; normals= NULL; diff --git a/source/shared_lib/sources/graphics/model.cpp b/source/shared_lib/sources/graphics/model.cpp index e106f4b42..2b87a6c0e 100644 --- a/source/shared_lib/sources/graphics/model.cpp +++ b/source/shared_lib/sources/graphics/model.cpp @@ -1067,7 +1067,10 @@ void Mesh::deletePixels() { // ==================== constructor & destructor ==================== Model::Model() { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + meshCount = 0; meshes = NULL; textureManager = NULL; diff --git a/source/shared_lib/sources/graphics/model_manager.cpp b/source/shared_lib/sources/graphics/model_manager.cpp index bc72d8342..4fcd59bec 100644 --- a/source/shared_lib/sources/graphics/model_manager.cpp +++ b/source/shared_lib/sources/graphics/model_manager.cpp @@ -16,10 +16,11 @@ #include #include #include "util.h" - +#include "platform_util.h" #include "leak_dumper.h" using namespace Shared::Util; +using namespace Shared::Platform; namespace Shared{ namespace Graphics{ @@ -28,7 +29,10 @@ namespace Shared{ namespace Graphics{ // ===================================================== ModelManager::ModelManager(){ - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + textureManager= NULL; } diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index 7a101612f..28431e85b 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -86,7 +86,6 @@ ParticleSystem::ParticleSystem(int particleCount) { memoryObjectList[this]++; } - //assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); textureFileLoadDeferred = ""; textureFileLoadDeferredSystemId = 0; textureFileLoadDeferredFormat = Texture::fAuto; @@ -1850,7 +1849,6 @@ void SplashParticleSystem::loadGame(const XmlNode *rootNode) { // =========================================================================== ParticleManager::ParticleManager() { - //assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); } ParticleManager::~ParticleManager() { diff --git a/source/shared_lib/sources/graphics/pixmap.cpp b/source/shared_lib/sources/graphics/pixmap.cpp index 488186050..35a4a3b42 100644 --- a/source/shared_lib/sources/graphics/pixmap.cpp +++ b/source/shared_lib/sources/graphics/pixmap.cpp @@ -759,7 +759,10 @@ void PixmapIoJpg::write(uint8 *pixels) { // ===================== PUBLIC ======================== Pixmap1D::Pixmap1D() { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + w= -1; components= -1; @@ -767,13 +770,19 @@ Pixmap1D::Pixmap1D() { } Pixmap1D::Pixmap1D(int components) { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + init(components); } Pixmap1D::Pixmap1D(int w, int components) { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + init(w, components); } @@ -885,7 +894,10 @@ void Pixmap1D::loadTga(const string &path) { // ===================== PUBLIC ======================== Pixmap2D::Pixmap2D() { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + h= -1; w= -1; components= -1; @@ -893,7 +905,10 @@ Pixmap2D::Pixmap2D() { } Pixmap2D::Pixmap2D(int components) { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + h= -1; w= -1; this->components= -1; @@ -903,7 +918,10 @@ Pixmap2D::Pixmap2D(int components) { } Pixmap2D::Pixmap2D(int w, int h, int components) { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + this->h= 0; this->w= -1; this->components= -1; @@ -1323,7 +1341,10 @@ bool Pixmap2D::doDimensionsAgree(const Pixmap2D *pixmap){ // ===================================================== Pixmap3D::Pixmap3D() { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + w= -1; h= -1; @@ -1334,14 +1355,20 @@ Pixmap3D::Pixmap3D() { } Pixmap3D::Pixmap3D(int w, int h, int d, int components) { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + pixels = NULL; slice=0; init(w, h, d, components); } Pixmap3D::Pixmap3D(int d, int components) { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + pixels = NULL; slice=0; init(d, components); @@ -1468,7 +1495,10 @@ void Pixmap3D::loadSliceTga(const string &path, int slice){ // class PixmapCube // ===================================================== PixmapCube::PixmapCube() { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + } PixmapCube::~PixmapCube() { diff --git a/source/shared_lib/sources/graphics/shader_manager.cpp b/source/shared_lib/sources/graphics/shader_manager.cpp index edac4463b..3c73f9d9e 100644 --- a/source/shared_lib/sources/graphics/shader_manager.cpp +++ b/source/shared_lib/sources/graphics/shader_manager.cpp @@ -26,7 +26,10 @@ namespace Shared{ namespace Graphics{ // ===================================================== ShaderManager::ShaderManager() { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + } ShaderManager::~ShaderManager(){ diff --git a/source/shared_lib/sources/graphics/texture.cpp b/source/shared_lib/sources/graphics/texture.cpp index 07d65f716..412d6bb5e 100644 --- a/source/shared_lib/sources/graphics/texture.cpp +++ b/source/shared_lib/sources/graphics/texture.cpp @@ -12,9 +12,11 @@ #include "texture.h" #include "util.h" #include +#include "platform_util.h" #include "leak_dumper.h" using namespace Shared::Util; +using namespace Shared::Platform; namespace Shared{ namespace Graphics{ @@ -39,7 +41,10 @@ static int powerOfTwo(int input) { */ Texture::Texture() { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + mipmap= true; pixmapInit= true; diff --git a/source/shared_lib/sources/graphics/texture_manager.cpp b/source/shared_lib/sources/graphics/texture_manager.cpp index 6a1f42b80..199a11be9 100644 --- a/source/shared_lib/sources/graphics/texture_manager.cpp +++ b/source/shared_lib/sources/graphics/texture_manager.cpp @@ -18,9 +18,11 @@ #include "graphics_factory.h" #include "util.h" +#include "platform_util.h" #include "leak_dumper.h" using namespace Shared::Util; +using namespace Shared::Platform; namespace Shared{ namespace Graphics{ @@ -29,7 +31,10 @@ namespace Shared{ namespace Graphics{ // ===================================================== TextureManager::TextureManager() { - assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!"); + } + textureFilter= Texture::fBilinear; maxAnisotropy= 1;