From ced6d20295a8263757d57c02a07ffcb66688a163 Mon Sep 17 00:00:00 2001 From: Craig Robbins Date: Fri, 6 Mar 2015 20:21:51 +1000 Subject: [PATCH] For usages of assert() that are meant to persist in Release builds (when NDEBUG is defined), replace those usages with persistent alternatives --- src/chat.cpp | 5 +- src/client.cpp | 40 ++++++++------- src/client/clientlauncher.cpp | 2 +- src/client/tile.cpp | 36 ++++++------- src/clientiface.h | 9 ++-- src/clientmap.cpp | 28 ---------- src/clientmedia.cpp | 15 +++--- src/collision.cpp | 14 ++--- src/content_cao.cpp | 4 +- src/content_mapblock.cpp | 10 ++-- src/content_sao.cpp | 6 +-- src/database-sqlite3.cpp | 3 +- src/debug.cpp | 20 +++++++- src/debug.h | 37 +++++++++----- src/environment.cpp | 15 +++--- src/fontengine.cpp | 16 +++--- src/game.cpp | 2 +- src/guiEngine.cpp | 4 +- src/guiFormSpecMenu.cpp | 16 +++--- src/guiKeyChangeMenu.cpp | 6 +-- src/httpfetch.cpp | 6 +-- src/inventory.cpp | 6 +-- src/inventory.h | 2 +- src/inventorymanager.cpp | 2 +- src/itemdef.cpp | 4 +- src/keycode.cpp | 8 +-- src/localplayer.cpp | 2 +- src/localplayer.h | 2 +- src/main.cpp | 8 +-- src/map.cpp | 19 ++++--- src/map.h | 10 ++-- src/mapblock.cpp | 2 +- src/mapblock.h | 2 +- src/mapgen_singlenode.cpp | 1 + src/mapgen_v5.cpp | 1 + src/mapgen_v6.cpp | 1 + src/mapgen_v7.cpp | 1 + src/mapnode.cpp | 13 ++--- src/mapsector.cpp | 2 +- src/mg_schematic.cpp | 2 +- src/network/connection.cpp | 74 ++++++++++++--------------- src/network/connection.h | 6 +-- src/network/packethandlers/client.cpp | 8 +-- src/nodedef.cpp | 7 ++- src/noise.h | 6 +-- src/player.h | 2 +- src/porting.cpp | 12 ++--- src/script/common/c_internal.cpp | 6 +-- src/script/cpp_api/s_async.cpp | 4 +- src/script/cpp_api/s_base.cpp | 2 +- src/script/lua_api/l_env.cpp | 6 +-- src/script/lua_api/l_mainmenu.cpp | 28 +++++----- src/server.cpp | 12 ++--- src/settings.cpp | 2 +- src/shader.cpp | 10 ++-- src/sound_openal.cpp | 2 +- src/staticobject.h | 5 +- src/test.cpp | 2 - src/util/serialize.cpp | 2 - src/util/string.cpp | 9 ++-- src/voxel.h | 2 +- src/wieldmesh.cpp | 4 +- 62 files changed, 299 insertions(+), 294 deletions(-) diff --git a/src/chat.cpp b/src/chat.cpp index 1fb872b85..2d29d39da 100644 --- a/src/chat.cpp +++ b/src/chat.cpp @@ -83,7 +83,7 @@ u32 ChatBuffer::getScrollback() const const ChatLine& ChatBuffer::getLine(u32 index) const { - assert(index < getLineCount()); + assert(index < getLineCount()); // pre-condition return m_unformatted[index]; } @@ -107,7 +107,8 @@ void ChatBuffer::deleteOldest(u32 count) // keep m_formatted in sync if (del_formatted < m_formatted.size()) { - assert(m_formatted[del_formatted].first); + + sanity_check(m_formatted[del_formatted].first); ++del_formatted; while (del_formatted < m_formatted.size() && !m_formatted[del_formatted].first) diff --git a/src/client.cpp b/src/client.cpp index 00b79e92e..edf244452 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -97,7 +97,7 @@ void MeshUpdateQueue::addBlock(v3s16 p, MeshMakeData *data, bool ack_block_to_se { DSTACK(__FUNCTION_NAME); - assert(data); + assert(data); // pre-condition JMutexAutoLock lock(m_mutex); @@ -388,8 +388,9 @@ void Client::step(float dtime) if(counter <= 0.0) { counter = 2.0; - Player *myplayer = m_env.getLocalPlayer(); - assert(myplayer != NULL); + Player *myplayer = m_env.getLocalPlayer(); + FATAL_ERROR_IF(myplayer == NULL, "Local player not found in environment."); + // Send TOSERVER_INIT // [0] u16 TOSERVER_INIT // [2] u8 SER_FMT_VER_HIGHEST_READ @@ -707,7 +708,9 @@ bool Client::loadMedia(const std::string &data, const std::string &filename) // Create an irrlicht memory file io::IReadFile *rfile = irrfs->createMemoryReadFile( *data_rw, data_rw.getSize(), "_tempreadfile"); - assert(rfile); + + FATAL_ERROR_IF(!rfile, "Could not create irrlicht memory file."); + // Read image video::IImage *img = vdrv->createImageFromFile(rfile); if(!img){ @@ -785,7 +788,8 @@ void Client::request_media(const std::vector &file_requests) std::ostringstream os(std::ios_base::binary); writeU16(os, TOSERVER_REQUEST_MEDIA); size_t file_requests_size = file_requests.size(); - assert(file_requests_size <= 0xFFFF); + + FATAL_ERROR_IF(file_requests_size > 0xFFFF, "Unsupported number of file requests"); // Packet dynamicly resized NetworkPacket* pkt = new NetworkPacket(TOSERVER_REQUEST_MEDIA, 2 + 0); @@ -986,7 +990,8 @@ void Client::sendNodemetaFields(v3s16 p, const std::string &formname, const std::map &fields) { size_t fields_size = fields.size(); - assert(fields_size <= 0xFFFF); + + FATAL_ERROR_IF(fields_size > 0xFFFF, "Unsupported number of nodemeta fields"); NetworkPacket* pkt = new NetworkPacket(TOSERVER_NODEMETA_FIELDS, 0); @@ -1007,7 +1012,7 @@ void Client::sendInventoryFields(const std::string &formname, const std::map &fields) { size_t fields_size = fields.size(); - assert(fields_size <= 0xFFFF); + FATAL_ERROR_IF(fields_size > 0xFFFF, "Unsupported number of inventory fields"); NetworkPacket* pkt = new NetworkPacket(TOSERVER_INVENTORY_FIELDS, 0); *pkt << formname << (u16) (fields_size & 0xFFFF); @@ -1141,7 +1146,7 @@ void Client::sendPlayerPos() // Set peer id if not set already if(myplayer->peer_id == PEER_ID_INEXISTENT) myplayer->peer_id = our_peer_id; - // Check that an existing peer_id is the same as the connection's + assert(myplayer->peer_id == our_peer_id); v3f pf = myplayer->getPosition(); @@ -1179,8 +1184,6 @@ void Client::sendPlayerItem(u16 item) // Set peer id if not set already if(myplayer->peer_id == PEER_ID_INEXISTENT) myplayer->peer_id = our_peer_id; - - // Check that an existing peer_id is the same as the connection's assert(myplayer->peer_id == our_peer_id); NetworkPacket* pkt = new NetworkPacket(TOSERVER_PLAYERITEM, 2); @@ -1295,7 +1298,7 @@ Inventory* Client::getInventory(const InventoryLocation &loc) } break; default: - assert(0); + FATAL_ERROR("Invalid inventory location type."); } return NULL; } @@ -1555,9 +1558,9 @@ float Client::mediaReceiveProgress() void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font) { infostream<<"Client::afterContentReceived() started"<getFileSystem(); io::IReadFile *rfile = irrfs->createMemoryReadFile( *data_rw, data_rw.getSize(), filename.c_str()); - assert(rfile); + FATAL_ERROR_IF(!rfile, "Could not create/open RAM file"); scene::IAnimatedMesh *mesh = smgr->getMesh(rfile); rfile->drop(); diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 0f60dcd63..7bf849624 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -128,7 +128,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255, 255, 255, 255)); g_fontengine = new FontEngine(g_settings, guienv); - assert(g_fontengine != NULL); + FATAL_ERROR_IF(g_fontengine == NULL, "Font engine creation failed."); #if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2 // Irrlicht 1.8 input colours diff --git a/src/client/tile.cpp b/src/client/tile.cpp index e5d02de7c..541247fa8 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -199,7 +199,7 @@ public: void insert(const std::string &name, video::IImage *img, bool prefer_local, video::IVideoDriver *driver) { - assert(img); + assert(img); // Pre-condition // Remove old image std::map::iterator n; n = m_images.find(name); @@ -423,7 +423,7 @@ IWritableTextureSource* createTextureSource(IrrlichtDevice *device) TextureSource::TextureSource(IrrlichtDevice *device): m_device(device) { - assert(m_device); + assert(m_device); // Pre-condition m_main_thread = get_current_thread_id(); @@ -597,7 +597,7 @@ u32 TextureSource::generateTexture(const std::string &name) } video::IVideoDriver *driver = m_device->getVideoDriver(); - assert(driver); + sanity_check(driver); video::IImage *img = generateImage(name); @@ -684,7 +684,7 @@ void TextureSource::insertSourceImage(const std::string &name, video::IImage *im { //infostream<<"TextureSource::insertSourceImage(): name="<getVideoDriver()); m_source_image_existence.set(name, true); @@ -695,7 +695,7 @@ void TextureSource::rebuildImagesAndTextures() JMutexAutoLock lock(m_textureinfo_cache_mutex); video::IVideoDriver* driver = m_device->getVideoDriver(); - assert(driver != 0); + sanity_check(driver); // Recreate textures for (u32 i=0; iname); #ifdef __ANDROID__ img = Align2Npot2(img, driver); - assert(img->getDimension().Height == npot2(img->getDimension().Height)); - assert(img->getDimension().Width == npot2(img->getDimension().Width)); + sanity_check(img->getDimension().Height == npot2(img->getDimension().Height)); + sanity_check(img->getDimension().Width == npot2(img->getDimension().Width)); #endif // Create texture from resulting image video::ITexture *t = NULL; @@ -725,7 +725,7 @@ video::ITexture* TextureSource::generateTextureFromMesh( const TextureFromMeshParams ¶ms) { video::IVideoDriver *driver = m_device->getVideoDriver(); - assert(driver); + sanity_check(driver); #ifdef __ANDROID__ const GLubyte* renderstr = glGetString(GL_RENDERER); @@ -741,9 +741,9 @@ video::ITexture* TextureSource::generateTextureFromMesh( ) { // Get a scene manager scene::ISceneManager *smgr_main = m_device->getSceneManager(); - assert(smgr_main); + sanity_check(smgr_main); scene::ISceneManager *smgr = smgr_main->createNewSceneManager(); - assert(smgr); + sanity_check(smgr); const float scaling = 0.2; @@ -978,7 +978,7 @@ video::IImage* TextureSource::generateImage(const std::string &name) video::IVideoDriver* driver = m_device->getVideoDriver(); - assert(driver); + sanity_check(driver); /* Parse out the last part of the name of the image and act @@ -1078,7 +1078,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, video::IImage *& baseimg) { video::IVideoDriver* driver = m_device->getVideoDriver(); - assert(driver); + sanity_check(driver); // Stuff starting with [ are special commands if (part_of_name.size() == 0 || part_of_name[0] != '[') @@ -1106,7 +1106,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, //core::dimension2d dim(2,2); core::dimension2d dim(1,1); image = driver->createImage(video::ECF_A8R8G8B8, dim); - assert(image); + sanity_check(image != NULL); /*image->setPixel(0,0, video::SColor(255,255,0,0)); image->setPixel(1,0, video::SColor(255,0,255,0)); image->setPixel(0,1, video::SColor(255,0,0,255)); @@ -1362,7 +1362,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, transform, baseimg->getDimension()); video::IImage *image = driver->createImage( baseimg->getColorFormat(), dim); - assert(image); + sanity_check(image != NULL); imageTransform(transform, baseimg, image); baseimg->drop(); baseimg = image; @@ -1422,7 +1422,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, (imagename_left + "__temp__").c_str(), img_left); video::ITexture *texture_right = driver->addTexture( (imagename_right + "__temp__").c_str(), img_right); - assert(texture_top && texture_left && texture_right); + FATAL_ERROR_IF(!(texture_top && texture_left && texture_right), ""); // Drop images img_top->drop(); @@ -1476,7 +1476,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, // Create image of render target video::IImage *image = driver->createImage(rtt, v2s32(0, 0), params.dim); - assert(image); + FATAL_ERROR_IF(!image, "Could not create image of render target"); // Cleanup texture driver->removeTexture(rtt); @@ -1892,10 +1892,10 @@ void imageTransform(u32 transform, video::IImage *src, video::IImage *dst) if (src == NULL || dst == NULL) return; - core::dimension2d srcdim = src->getDimension(); core::dimension2d dstdim = dst->getDimension(); - assert(dstdim == imageTransformDimension(transform, srcdim)); + // Pre-conditions + assert(dstdim == imageTransformDimension(transform, src->getDimension())); assert(transform <= 7); /* diff --git a/src/clientiface.h b/src/clientiface.h index 2f265b128..cc303734a 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -426,9 +426,12 @@ public: /* event to update client state */ void event(u16 peer_id, ClientStateEvent event); - /* set environment */ - void setEnv(ServerEnvironment* env) - { assert(m_env == 0); m_env = env; } + /* Set environment. Do not call this function if environment is already set */ + void setEnv(ServerEnvironment *env) + { + assert(m_env == NULL); // pre-condition + m_env = env; + } static std::string state2Name(ClientState state); diff --git a/src/clientmap.cpp b/src/clientmap.cpp index 1c420b5f9..907df7128 100644 --- a/src/clientmap.cpp +++ b/src/clientmap.cpp @@ -102,34 +102,6 @@ MapSector * ClientMap::emergeSector(v2s16 p2d) return sector; } -#if 0 -void ClientMap::deSerializeSector(v2s16 p2d, std::istream &is) -{ - DSTACK(__FUNCTION_NAME); - ClientMapSector *sector = NULL; - - //JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out - - core::map::Node *n = m_sectors.find(p2d); - - if(n != NULL) - { - sector = (ClientMapSector*)n->getValue(); - assert(sector->getId() == MAPSECTOR_CLIENT); - } - else - { - sector = new ClientMapSector(this, p2d); - { - //JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out - m_sectors.insert(p2d, sector); - } - } - - sector->deSerialize(is); -} -#endif - void ClientMap::OnRegisterSceneNode() { if(IsVisible) diff --git a/src/clientmedia.cpp b/src/clientmedia.cpp index 1d825c143..0918e8a37 100644 --- a/src/clientmedia.cpp +++ b/src/clientmedia.cpp @@ -72,7 +72,7 @@ ClientMediaDownloader::~ClientMediaDownloader() void ClientMediaDownloader::addFile(std::string name, std::string sha1) { - assert(!m_initial_step_done); + assert(!m_initial_step_done); // pre-condition // if name was already announced, ignore the new announcement if (m_files.count(name) != 0) { @@ -107,7 +107,7 @@ void ClientMediaDownloader::addFile(std::string name, std::string sha1) void ClientMediaDownloader::addRemoteServer(std::string baseurl) { - assert(!m_initial_step_done); + assert(!m_initial_step_done); // pre-condition #ifdef USE_CURL @@ -356,11 +356,11 @@ void ClientMediaDownloader::remoteMediaReceived( m_remote_file_transfers.erase(it); } - assert(m_files.count(name) != 0); + sanity_check(m_files.count(name) != 0); FileStatus *filestatus = m_files[name]; - assert(!filestatus->received); - assert(filestatus->current_remote >= 0); + sanity_check(!filestatus->received); + sanity_check(filestatus->current_remote >= 0); RemoteServerStatus *remote = m_remotes[filestatus->current_remote]; @@ -382,6 +382,7 @@ void ClientMediaDownloader::remoteMediaReceived( s32 ClientMediaDownloader::selectRemoteServer(FileStatus *filestatus) { + // Pre-conditions assert(filestatus != NULL); assert(!filestatus->received); assert(filestatus->current_remote < 0); @@ -483,7 +484,7 @@ void ClientMediaDownloader::startRemoteMediaTransfers() void ClientMediaDownloader::startConventionalTransfers(Client *client) { - assert(m_httpfetch_active == 0); + assert(m_httpfetch_active == 0); // pre-condition if (m_uncached_received_count != m_uncached_count) { // Some media files have not been received yet, use the @@ -616,7 +617,7 @@ std::string ClientMediaDownloader::serializeRequiredHashSet() it = m_files.begin(); it != m_files.end(); ++it) { if (!it->second->received) { - assert(it->second->sha1.size() == 20); + FATAL_ERROR_IF(it->second->sha1.size() != 20, "Invalid SHA1 size"); os << it->second->sha1; } } diff --git a/src/collision.cpp b/src/collision.cpp index b1b1e23bd..12eabff09 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -173,7 +173,7 @@ bool wouldCollideWithCeiling( { //TimeTaker tt("wouldCollideWithCeiling"); - assert(y_increase >= 0); + assert(y_increase >= 0); // pre-condition for(std::vector::const_iterator i = staticboxes.begin(); @@ -348,11 +348,11 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, } } //tt3 - assert(cboxes.size() == is_unloaded.size()); - assert(cboxes.size() == is_step_up.size()); - assert(cboxes.size() == bouncy_values.size()); - assert(cboxes.size() == node_positions.size()); - assert(cboxes.size() == is_object.size()); + assert(cboxes.size() == is_unloaded.size()); // post-condition + assert(cboxes.size() == is_step_up.size()); // post-condition + assert(cboxes.size() == bouncy_values.size()); // post-condition + assert(cboxes.size() == node_positions.size()); // post-condition + assert(cboxes.size() == is_object.size()); // post-condition /* Collision detection @@ -367,7 +367,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, //f32 d = 0.15*BS; // This should always apply, otherwise there are glitches - assert(d > pos_max_d); + assert(d > pos_max_d); // invariant int loopcount = 0; diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 5c3c7b54c..4c8962edb 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -1718,10 +1718,12 @@ void GenericCAO::processMessage(const std::string &data) } } +/* \pre punchitem != NULL + */ bool GenericCAO::directReportPunch(v3f dir, const ItemStack *punchitem, float time_from_last_punch) { - assert(punchitem); + assert(punchitem); // pre-condition const ToolCapabilities *toolcap = &punchitem->getToolCapabilities(m_gamedef->idef()); PunchDamageResult result = getPunchDamage( diff --git a/src/content_mapblock.cpp b/src/content_mapblock.cpp index 3428f85f9..2f1368765 100644 --- a/src/content_mapblock.cpp +++ b/src/content_mapblock.cpp @@ -47,7 +47,7 @@ with this program; if not, write to the Free Software Foundation, Inc., void makeCuboid(MeshCollector *collector, const aabb3f &box, TileSpec *tiles, int tilecount, video::SColor &c, const f32* txc) { - assert(tilecount >= 1 && tilecount <= 6); + assert(tilecount >= 1 && tilecount <= 6); // pre-condition v3f min = box.MinEdge; v3f max = box.MaxEdge; @@ -206,8 +206,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data, switch(f.drawtype){ default: - infostream<<"Got "<getPosition()); m_inventory = &m_player->inventory; m_armor_groups["fleshy"] = 100; @@ -833,7 +833,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version) std::string PlayerSAO::getStaticData() { - assert(0); + FATAL_ERROR("Deprecated function (?)"); return ""; } diff --git a/src/database-sqlite3.cpp b/src/database-sqlite3.cpp index 3480894c9..c937cae31 100644 --- a/src/database-sqlite3.cpp +++ b/src/database-sqlite3.cpp @@ -210,14 +210,13 @@ std::string Database_SQLite3::loadBlock(const v3s16 &pos) void Database_SQLite3::createDatabase() { - assert(m_database); + assert(m_database); // Pre-condition SQLOK(sqlite3_exec(m_database, "CREATE TABLE IF NOT EXISTS `blocks` (\n" " `pos` INT PRIMARY KEY,\n" " `data` BLOB\n" ");\n", NULL, NULL, NULL)); - } void Database_SQLite3::listAllLoadableBlocks(std::vector &dst) diff --git a/src/debug.cpp b/src/debug.cpp index bd970a8e4..521891bbd 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -133,11 +133,11 @@ Nullstream dummyout; Assert */ -void assert_fail(const char *assertion, const char *file, +void sanity_check_fn(const char *assertion, const char *file, unsigned int line, const char *function) { DEBUGPRINT("\nIn thread %lx:\n" - "%s:%u: %s: Assertion '%s' failed.\n", + "%s:%u: %s: An engine assumption '%s' failed.\n", (unsigned long)get_current_thread_id(), file, line, function, assertion); @@ -149,6 +149,22 @@ void assert_fail(const char *assertion, const char *file, abort(); } +void fatal_error_fn(const char *msg, const char *file, + unsigned int line, const char *function) +{ + DEBUGPRINT("\nIn thread %lx:\n" + "%s:%u: %s: A fatal error occurred: %s\n", + (unsigned long)get_current_thread_id(), + file, line, function, msg); + + debug_stacks_print(); + + if(g_debugstreams[1]) + fclose(g_debugstreams[1]); + + abort(); +} + /* DebugStack */ diff --git a/src/debug.h b/src/debug.h index 1027fde69..9684aa2df 100644 --- a/src/debug.h +++ b/src/debug.h @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include +#include #include "gettime.h" #if (defined(WIN32) || defined(_WIN32_WCE)) @@ -72,28 +73,38 @@ extern std::ostream dstream; extern std::ostream dstream_no_stderr; extern Nullstream dummyout; -/* - Include assert.h and immediately undef assert so that it can't override - our assert later on. leveldb/slice.h is a notable offender. -*/ -#include -#undef assert +/* Abort program execution immediately + */ +__NORETURN extern void fatal_error_fn( + const char *msg, const char *file, + unsigned int line, const char *function); + +#define FATAL_ERROR(msg) \ + fatal_error_fn((msg), __FILE__, __LINE__, __FUNCTION_NAME) + +#define FATAL_ERROR_IF(expr, msg) \ + ((expr) \ + ? fatal_error_fn((msg), __FILE__, __LINE__, __FUNCTION_NAME) \ + : (void)(0)) /* - Assert + sanity_check() + Equivalent to assert() but persists in Release builds (i.e. when NDEBUG is + defined) */ -__NORETURN extern void assert_fail( +__NORETURN extern void sanity_check_fn( const char *assertion, const char *file, unsigned int line, const char *function); -#define ASSERT(expr)\ - ((expr)\ - ? (void)(0)\ - : assert_fail(#expr, __FILE__, __LINE__, __FUNCTION_NAME)) +#define SANITY_CHECK(expr) \ + ((expr) \ + ? (void)(0) \ + : sanity_check_fn(#expr, __FILE__, __LINE__, __FUNCTION_NAME)) + +#define sanity_check(expr) SANITY_CHECK(expr) -#define assert(expr) ASSERT(expr) void debug_set_exception_handler(); diff --git a/src/environment.cpp b/src/environment.cpp index 60a26e65f..f75e7a0b7 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -77,9 +77,9 @@ void Environment::addPlayer(Player *player) */ // If peer id is non-zero, it has to be unique. if(player->peer_id != 0) - assert(getPlayer(player->peer_id) == NULL); + FATAL_ERROR_IF(getPlayer(player->peer_id) != NULL, "Peer id not unique"); // Name has to be unique. - assert(getPlayer(player->getName()) == NULL); + FATAL_ERROR_IF(getPlayer(player->getName()) != NULL, "Player name not unique"); // Add. m_players.push_back(player); } @@ -926,7 +926,7 @@ void ServerEnvironment::clearAllObjects() i != loaded_blocks.end(); ++i) { v3s16 p = *i; MapBlock *block = m_map->getBlockNoCreateNoEx(p); - assert(block); + assert(block != NULL); block->refGrab(); } @@ -1295,7 +1295,7 @@ u16 getFreeServerActiveObjectId( u16 ServerEnvironment::addActiveObject(ServerActiveObject *object) { - assert(object); + assert(object); // Pre-condition m_added_objects++; u16 id = addActiveObjectRaw(object, true, 0); return id; @@ -1473,7 +1473,7 @@ ActiveObjectMessage ServerEnvironment::getActiveObjectMessage() u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, bool set_changed, u32 dtime_s) { - assert(object); + assert(object); // Pre-condition if(object->getId() == 0){ u16 new_id = getFreeServerActiveObjectId(m_active_objects); if(new_id == 0) @@ -2051,7 +2051,8 @@ void ClientEnvironment::addPlayer(Player *player) It is a failure if player is local and there already is a local player */ - assert(!(player->isLocal() == true && getLocalPlayer() != NULL)); + FATAL_ERROR_IF(player->isLocal() == true && getLocalPlayer() != NULL, + "Player is local but there is already a local player"); Environment::addPlayer(player); } @@ -2439,7 +2440,7 @@ u16 getFreeClientActiveObjectId( u16 ClientEnvironment::addActiveObject(ClientActiveObject *object) { - assert(object); + assert(object); // Pre-condition if(object->getId() == 0) { u16 new_id = getFreeClientActiveObjectId(m_active_objects); diff --git a/src/fontengine.cpp b/src/fontengine.cpp index 3b82a3c47..fa30b4038 100644 --- a/src/fontengine.cpp +++ b/src/fontengine.cpp @@ -55,9 +55,9 @@ FontEngine::FontEngine(Settings* main_settings, gui::IGUIEnvironment* env) : m_default_size[i] = (FontMode) FONT_SIZE_UNSPECIFIED; } - assert(m_settings != NULL); - assert(m_env != NULL); - assert(m_env->getSkin() != NULL); + assert(m_settings != NULL); // pre-condition + assert(m_env != NULL); // pre-condition + assert(m_env->getSkin() != NULL); // pre-condition m_currentMode = FM_Simple; @@ -172,7 +172,7 @@ unsigned int FontEngine::getTextHeight(unsigned int font_size, FontMode mode) if (font == NULL) { font = m_env->getSkin()->getFont(); } - assert(font != NULL); + FATAL_ERROR_IF(font == NULL, "Could not get skin font"); return font->getDimension(L"Some unimportant example String").Height; } @@ -187,7 +187,7 @@ unsigned int FontEngine::getTextWidth(const std::wstring& text, if (font == NULL) { font = m_env->getSkin()->getFont(); } - assert(font != NULL); + FATAL_ERROR_IF(font == NULL, "Could not get font"); return font->getDimension(text.c_str()).Width; } @@ -202,7 +202,7 @@ unsigned int FontEngine::getLineHeight(unsigned int font_size, FontMode mode) if (font == NULL) { font = m_env->getSkin()->getFont(); } - assert(font != NULL); + FATAL_ERROR_IF(font == NULL, "Could not get font"); return font->getDimension(L"Some unimportant example String").Height + font->getKerningHeight(); @@ -255,7 +255,7 @@ void FontEngine::updateSkin() // If we did fail to create a font our own make irrlicht find a default one font = m_env->getSkin()->getFont(); - assert(font); + FATAL_ERROR_IF(font == NULL, "Could not create/get font"); u32 text_height = font->getDimension(L"Hello, world!").Height; infostream << "text_height=" << text_height << std::endl; @@ -355,7 +355,7 @@ void FontEngine::initFont(unsigned int basesize, FontMode mode) /** initialize a font without freetype */ void FontEngine::initSimpleFont(unsigned int basesize, FontMode mode) { - assert((mode == FM_Simple) || (mode == FM_SimpleMono)); + assert(mode == FM_Simple || mode == FM_SimpleMono); // pre-condition std::string font_path = ""; if (mode == FM_Simple) { diff --git a/src/game.cpp b/src/game.cpp index be8d4e679..7b6d2a3c1 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3112,7 +3112,7 @@ void Game::processClientEvents(CameraOrientation *cam, float *damage_flash) u32 new_id = player->addHud(e); //if this isn't true our huds aren't consistent - assert(new_id == id); + sanity_check(new_id == id); delete event.hudadd.pos; delete event.hudadd.name; diff --git a/src/guiEngine.cpp b/src/guiEngine.cpp index b45011c2c..dbb6fdf92 100644 --- a/src/guiEngine.cpp +++ b/src/guiEngine.cpp @@ -304,7 +304,7 @@ void GUIEngine::run() GUIEngine::~GUIEngine() { video::IVideoDriver* driver = m_device->getVideoDriver(); - assert(driver != 0); + FATAL_ERROR_IF(driver == 0, "Could not get video driver"); if(m_sound_manager != &dummySoundManager){ delete m_sound_manager; @@ -514,7 +514,7 @@ bool GUIEngine::setTexture(texture_layer layer, std::string texturepath, bool tile_image, unsigned int minsize) { video::IVideoDriver* driver = m_device->getVideoDriver(); - assert(driver != 0); + FATAL_ERROR_IF(driver == 0, "Could not get video driver"); if (m_textures[layer].texture != NULL) { diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp index 581da894b..300eaf80c 100644 --- a/src/guiFormSpecMenu.cpp +++ b/src/guiFormSpecMenu.cpp @@ -1973,7 +1973,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) m_tooltip_element->setOverrideFont(m_font); gui::IGUISkin* skin = Environment->getSkin(); - assert(skin != NULL); + sanity_check(skin != NULL); gui::IGUIFont *old_font = skin->getFont(); skin->setFont(m_font); @@ -2217,9 +2217,9 @@ void GUIFormSpecMenu::drawSelectedItem() video::IVideoDriver* driver = Environment->getVideoDriver(); Inventory *inv = m_invmgr->getInventory(m_selected_item->inventoryloc); - assert(inv); + sanity_check(inv); InventoryList *list = inv->getList(m_selected_item->listname); - assert(list); + sanity_check(list); ItemStack stack = list->getItem(m_selected_item->i); stack.count = m_selected_amount; @@ -2239,7 +2239,7 @@ void GUIFormSpecMenu::drawMenu() } gui::IGUISkin* skin = Environment->getSkin(); - assert(skin != NULL); + sanity_check(skin != NULL); gui::IGUIFont *old_font = skin->getFont(); skin->setFont(m_font); @@ -2725,7 +2725,7 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event) if (hovered && isMyChild(hovered) && hovered->getType() == gui::EGUIET_TAB_CONTROL) { gui::IGUISkin* skin = Environment->getSkin(); - assert(skin != NULL); + sanity_check(skin != NULL); gui::IGUIFont *old_font = skin->getFont(); skin->setFont(m_font); bool retval = hovered->OnEvent(event); @@ -3013,7 +3013,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) break; default: //can't happen at all! - assert("reached a source line that can't ever been reached" == 0); + FATAL_ERROR("Reached a source line that can't ever been reached"); break; } if (current_keys_pending.key_enter && m_allowclose) { @@ -3047,8 +3047,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) if(m_selected_item) { inv_selected = m_invmgr->getInventory(m_selected_item->inventoryloc); - assert(inv_selected); - assert(inv_selected->getList(m_selected_item->listname) != NULL); + sanity_check(inv_selected); + sanity_check(inv_selected->getList(m_selected_item->listname) != NULL); } u32 s_count = 0; diff --git a/src/guiKeyChangeMenu.cpp b/src/guiKeyChangeMenu.cpp index 9b5a31d26..3ddb3f5d9 100644 --- a/src/guiKeyChangeMenu.cpp +++ b/src/guiKeyChangeMenu.cpp @@ -303,7 +303,7 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event) // But go on { - key_setting *k=NULL; + key_setting *k = NULL; for(size_t i = 0; i < key_settings.size(); i++) { if(key_settings.at(i)->id == activeKey) @@ -312,7 +312,7 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event) break; } } - assert(k); + FATAL_ERROR_IF(k == NULL, "Key setting not found"); k->key = kp; const wchar_t *text = wgettext(k->key.name()); k->button->setText(text); @@ -364,7 +364,7 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event) break; } } - assert(k); + FATAL_ERROR_IF(k == NULL, "Key setting not found"); resetMenu(); shift_down = false; diff --git a/src/httpfetch.cpp b/src/httpfetch.cpp index e6886f652..40ad92da3 100644 --- a/src/httpfetch.cpp +++ b/src/httpfetch.cpp @@ -81,7 +81,7 @@ unsigned long httpfetch_caller_alloc() } } - assert("httpfetch_caller_alloc: ran out of caller IDs" == 0); + FATAL_ERROR("httpfetch_caller_alloc: ran out of caller IDs"); return discard; } @@ -633,7 +633,7 @@ protected: return NULL; } - assert(m_all_ongoing.empty()); + FATAL_ERROR_IF(!m_all_ongoing.empty(), "Expected empty"); while (!StopRequested()) { BEGIN_DEBUG_EXCEPTION_HANDLER @@ -714,7 +714,7 @@ void httpfetch_init(int parallel_limit) <= n); + assert(count >= n); // Pre-condition count -= n; if(count == 0) clear(); // reset name, wear and metadata too diff --git a/src/inventorymanager.cpp b/src/inventorymanager.cpp index ed18126d0..26cabc25f 100644 --- a/src/inventorymanager.cpp +++ b/src/inventorymanager.cpp @@ -62,7 +62,7 @@ void InventoryLocation::serialize(std::ostream &os) const os<<"detached:"< 8 && strncmp(name, "KEY_KEY_", 8) == 0) { int chars_read = mbtowc(&Char, name + 8, 1); - assert (chars_read == 1 && "unexpected multibyte character"); + + FATAL_ERROR_IF(chars_read != 1, "Unexpected multibyte character"); } else Char = L'\0'; return; @@ -275,7 +276,8 @@ KeyPress::KeyPress(const char *name) try { Key = keyname_to_keycode(m_name.c_str()); int chars_read = mbtowc(&Char, name, 1); - assert (chars_read == 1 && "unexpected multibyte character"); + + FATAL_ERROR_IF(chars_read != 1, "Unexpected multibyte character"); return; } catch (UnknownKeycode &e) {}; } @@ -285,7 +287,7 @@ KeyPress::KeyPress(const char *name) Key = irr::KEY_KEY_CODES_COUNT; int mbtowc_ret = mbtowc(&Char, name, 1); - assert (mbtowc_ret == 1 && "unexpected multibyte character"); + FATAL_ERROR_IF(mbtowc_ret != 1, "Unexpected multibyte character"); m_name = name[0]; } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index cb183947a..55578422e 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -172,7 +172,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, f32 d = 0.15*BS; // This should always apply, otherwise there are glitches - assert(d > pos_max_d); + sanity_check(d > pos_max_d); // Maximum distance over border for sneaking f32 sneak_max = BS*0.4; diff --git a/src/localplayer.h b/src/localplayer.h index 2a4a9dfc7..b60e156be 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -78,7 +78,7 @@ public: } void setCAO(GenericCAO* toset) { - assert( m_cao == NULL ); + assert( m_cao == NULL ); // Pre-condition m_cao = toset; } diff --git a/src/main.cpp b/src/main.cpp index a01ddec93..d84a09f76 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -273,7 +273,7 @@ int main(int argc, char *argv[]) if (!game_configure(&game_params, cmd_args)) return 1; - assert(game_params.world_path != ""); + sanity_check(game_params.world_path != ""); infostream << "Using commanded world path [" << game_params.world_path << "]" << std::endl; @@ -549,7 +549,7 @@ static void startup_message() static bool read_config_file(const Settings &cmd_args) { // Path of configuration file in use - assert(g_settings_path == ""); // Sanity check + sanity_check(g_settings_path == ""); // Sanity check if (cmd_args.exists("config")) { bool r = g_settings->readConfigFile(cmd_args.get("config").c_str()); @@ -748,7 +748,7 @@ static bool auto_select_world(GameParams *game_params) << world_path << "]" << std::endl; } - assert(world_path != ""); + assert(world_path != ""); // Post-condition game_params->world_path = world_path; return true; } @@ -804,7 +804,7 @@ static bool determine_subgame(GameParams *game_params) { SubgameSpec gamespec; - assert(game_params->world_path != ""); // pre-condition + assert(game_params->world_path != ""); // Pre-condition verbosestream << _("Determining gameid/gamespec") << std::endl; // If world doesn't exist diff --git a/src/map.cpp b/src/map.cpp index e80c82522..14a237c0a 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -767,8 +767,7 @@ void Map::updateLighting(enum LightBank bank, } else { - // Invalid lighting bank - assert(0); + assert("Invalid lighting bank" == NULL); } /*infostream<<"Bottom for sunlight-propagated block (" @@ -783,7 +782,7 @@ void Map::updateLighting(enum LightBank bank, } catch(InvalidPositionException &e) { - assert(0); + FATAL_ERROR("Invalid position"); } } @@ -1220,7 +1219,7 @@ void Map::removeNodeAndUpdate(v3s16 p, n.setLight(LIGHTBANK_DAY, 0, ndef); setNode(p, n); } else { - assert(0); + FATAL_ERROR("Invalid position"); } } @@ -2180,7 +2179,7 @@ bool ServerMap::initBlockMake(BlockMakeData *data, v3s16 blockpos) v2s16 sectorpos(x, z); // Sector metadata is loaded from disk if not already loaded. ServerMapSector *sector = createSector(sectorpos); - assert(sector); + FATAL_ERROR_IF(sector == NULL, "createSector() failed"); (void) sector; for(s16 y=blockpos_min.Y-extra_borders.Y; @@ -2628,7 +2627,7 @@ MapBlock * ServerMap::createBlock(v3s16 p) lighting on blocks for them. */ ServerMapSector *sector; - try{ + try { sector = (ServerMapSector*)createSector(p2d); assert(sector->getId() == MAPSECTOR_SERVER); } @@ -2861,9 +2860,10 @@ v2s16 ServerMap::getSectorPos(std::string dirname) } else { - assert(false); + r = -1; } - assert(r == 2); + + FATAL_ERROR_IF(r != 2, "getSectorPos()"); v2s16 pos((s16)x, (s16)y); return pos; } @@ -3368,7 +3368,7 @@ void ServerMap::loadBlock(std::string sectordir, std::string blockfile, <<"what()="<= SER_FMT_CLIENT_VER_LOWEST); + FATAL_ERROR_IF(version < SER_FMT_CLIENT_VER_LOWEST, "Serialize version error"); // First byte u8 flags = 0; diff --git a/src/mapblock.h b/src/mapblock.h index 76ba94c34..3c0ae9cd7 100644 --- a/src/mapblock.h +++ b/src/mapblock.h @@ -140,7 +140,7 @@ public: } void unDummify() { - assert(isDummy()); + assert(isDummy()); // Pre-condition reallocate(); } diff --git a/src/mapgen_singlenode.cpp b/src/mapgen_singlenode.cpp index 5f81aba98..acf811dea 100644 --- a/src/mapgen_singlenode.cpp +++ b/src/mapgen_singlenode.cpp @@ -62,6 +62,7 @@ MapgenSinglenode::~MapgenSinglenode() void MapgenSinglenode::makeChunk(BlockMakeData *data) { + // Pre-conditions assert(data->vmanip); assert(data->nodedef); assert(data->blockpos_requested.X >= data->blockpos_min.X && diff --git a/src/mapgen_v5.cpp b/src/mapgen_v5.cpp index 34484c7e5..ffd164774 100644 --- a/src/mapgen_v5.cpp +++ b/src/mapgen_v5.cpp @@ -201,6 +201,7 @@ int MapgenV5::getGroundLevelAtPoint(v2s16 p) void MapgenV5::makeChunk(BlockMakeData *data) { + // Pre-conditions assert(data->vmanip); assert(data->nodedef); assert(data->blockpos_requested.X >= data->blockpos_min.X && diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp index 8ea4cd21d..b7bfaef0c 100644 --- a/src/mapgen_v6.cpp +++ b/src/mapgen_v6.cpp @@ -430,6 +430,7 @@ u32 MapgenV6::get_blockseed(u64 seed, v3s16 p) void MapgenV6::makeChunk(BlockMakeData *data) { + // Pre-conditions assert(data->vmanip); assert(data->nodedef); assert(data->blockpos_requested.X >= data->blockpos_min.X && diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp index 21ee967c6..923f85a0f 100644 --- a/src/mapgen_v7.cpp +++ b/src/mapgen_v7.cpp @@ -212,6 +212,7 @@ int MapgenV7::getGroundLevelAtPoint(v2s16 p) void MapgenV7::makeChunk(BlockMakeData *data) { + // Pre-conditions assert(data->vmanip); assert(data->nodedef); assert(data->blockpos_requested.X >= data->blockpos_min.X && diff --git a/src/mapnode.cpp b/src/mapnode.cpp index 44525b644..0335755e9 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -71,7 +71,7 @@ void MapNode::setLight(enum LightBank bank, u8 a_light, INodeDefManager *nodemgr param1 |= (a_light & 0x0f)<<4; } else - assert(0); + assert("Invalid light bank" == NULL); } bool MapNode::isLightDayNightEq(INodeDefManager *nodemgr) const @@ -516,8 +516,8 @@ void MapNode::serializeBulk(std::ostream &os, int version, if(!ser_ver_supported(version)) throw VersionMismatchException("ERROR: MapNode format not supported"); - assert(content_width == 2); - assert(params_width == 2); + sanity_check(content_width == 2); + sanity_check(params_width == 2); // Can't do this anymore; we have 16-bit dynamically allocated node IDs // in memory; conversion just won't work in this direction. @@ -563,9 +563,10 @@ void MapNode::deSerializeBulk(std::istream &is, int version, if(!ser_ver_supported(version)) throw VersionMismatchException("ERROR: MapNode format not supported"); - assert(version >= 22); - assert(content_width == 1 || content_width == 2); - assert(params_width == 2); + if (version < 22 + || (content_width != 1 && content_width != 2) + || params_width != 2) + FATAL_ERROR("Deserialize bulk node data error"); // Uncompress or read data u32 len = nodecount * (content_width + params_width); diff --git a/src/mapsector.cpp b/src/mapsector.cpp index 7bc4bd3a3..3fe81dc90 100644 --- a/src/mapsector.cpp +++ b/src/mapsector.cpp @@ -85,7 +85,7 @@ MapBlock * MapSector::getBlockNoCreateNoEx(s16 y) MapBlock * MapSector::createBlankBlockNoInsert(s16 y) { - assert(getBlockBuffered(y) == NULL); + assert(getBlockBuffered(y) == NULL); // Pre-condition v3s16 blockpos_map(m_pos.X, y, m_pos.Y); diff --git a/src/mg_schematic.cpp b/src/mg_schematic.cpp index a3404e2dc..a05e372e5 100644 --- a/src/mg_schematic.cpp +++ b/src/mg_schematic.cpp @@ -159,7 +159,7 @@ void Schematic::blitToVManip(v3s16 p, MMVManip *vm, Rotation rot, void Schematic::placeStructure(Map *map, v3s16 p, u32 flags, Rotation rot, bool force_placement, INodeDefManager *ndef) { - assert(schemdata != NULL); + assert(schemdata != NULL); // Pre-condition MMVManip *vm = new MMVManip(map); if (rot == ROTATE_RAND) diff --git a/src/network/connection.cpp b/src/network/connection.cpp index b73981ccc..fb31a07f0 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -312,16 +312,16 @@ BufferedPacket ReliablePacketBuffer::popSeqnum(u16 seqnum) void ReliablePacketBuffer::insert(BufferedPacket &p,u16 next_expected) { JMutexAutoLock listlock(m_list_mutex); - assert(p.data.getSize() >= BASE_HEADER_SIZE+3); + FATAL_ERROR_IF(p.data.getSize() < BASE_HEADER_SIZE+3, "Invalid data size"); u8 type = readU8(&p.data[BASE_HEADER_SIZE+0]); - assert(type == TYPE_RELIABLE); + sanity_check(type == TYPE_RELIABLE); u16 seqnum = readU16(&p.data[BASE_HEADER_SIZE+1]); - assert(seqnum_in_window(seqnum,next_expected,MAX_RELIABLE_WINDOW_SIZE)); - assert(seqnum != next_expected); + sanity_check(seqnum_in_window(seqnum, next_expected, MAX_RELIABLE_WINDOW_SIZE)); + sanity_check(seqnum != next_expected); ++m_list_size; - assert(m_list_size <= SEQNUM_MAX+1); + sanity_check(m_list_size <= SEQNUM_MAX+1); // FIXME: Handle the error? // Find the right place for the packet and insert it there // If list is empty, just add it @@ -377,9 +377,9 @@ void ReliablePacketBuffer::insert(BufferedPacket &p,u16 next_expected) throw IncomingDataCorruption("duplicated packet isn't same as original one"); } - assert(readU16(&(i->data[BASE_HEADER_SIZE+1])) == seqnum); - assert(i->data.getSize() == p.data.getSize()); - assert(i->address == p.address); + sanity_check(readU16(&(i->data[BASE_HEADER_SIZE+1])) == seqnum); + sanity_check(i->data.getSize() == p.data.getSize()); + sanity_check(i->address == p.address); /* nothing to do this seems to be a resent packet */ /* for paranoia reason data should be compared */ @@ -449,9 +449,9 @@ SharedBuffer IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable) { JMutexAutoLock listlock(m_map_mutex); u32 headersize = BASE_HEADER_SIZE + 7; - assert(p.data.getSize() >= headersize); + FATAL_ERROR_IF(p.data.getSize() < headersize, "Invalid data size"); u8 type = readU8(&p.data[BASE_HEADER_SIZE+0]); - assert(type == TYPE_SPLIT); + sanity_check(type == TYPE_SPLIT); u16 seqnum = readU16(&p.data[BASE_HEADER_SIZE+1]); u16 chunk_count = readU16(&p.data[BASE_HEADER_SIZE+3]); u16 chunk_num = readU16(&p.data[BASE_HEADER_SIZE+5]); @@ -898,7 +898,7 @@ void Peer::DecUseCount() { { JMutexAutoLock lock(m_exclusive_access_mutex); - assert(m_usage > 0); + sanity_check(m_usage > 0); m_usage--; if (!((m_pending_deletion) && (m_usage == 0))) @@ -1085,7 +1085,7 @@ bool UDPPeer::processReliableSendCommand( - BASE_HEADER_SIZE - RELIABLE_HEADER_SIZE; - assert(c.data.getSize() < MAX_RELIABLE_WINDOW_SIZE*512); + sanity_check(c.data.getSize() < MAX_RELIABLE_WINDOW_SIZE*512); std::list > originals; u16 split_sequence_number = channels[c.channelnum].readNextSplitSeqNum(); @@ -1142,7 +1142,7 @@ bool UDPPeer::processReliableSendCommand( channels[c.channelnum].queued_reliables.push(p); pcount++; } - assert(channels[c.channelnum].queued_reliables.size() < 0xFFFF); + sanity_check(channels[c.channelnum].queued_reliables.size() < 0xFFFF); return true; } else { @@ -1160,7 +1160,7 @@ bool UDPPeer::processReliableSendCommand( = channels[c.channelnum].putBackSequenceNumber( (initial_sequence_number+toadd.size() % (SEQNUM_MAX+1))); - assert(successfully_put_back_sequence_number); + FATAL_ERROR_IF(!successfully_put_back_sequence_number, "error"); } LOG(dout_con<getDesc() << " Windowsize exceeded on reliable sending " @@ -1212,13 +1212,13 @@ void UDPPeer::RunCommandQueues( u16 UDPPeer::getNextSplitSequenceNumber(u8 channel) { - assert(channel < CHANNEL_COUNT); + assert(channel < CHANNEL_COUNT); // Pre-condition return channels[channel].readNextIncomingSeqNum(); } void UDPPeer::setNextSplitSequenceNumber(u8 channel, u16 seqnum) { - assert(channel < CHANNEL_COUNT); + assert(channel < CHANNEL_COUNT); // Pre-condition channels[channel].setNextSplitSeqNum(seqnum); } @@ -1226,7 +1226,7 @@ SharedBuffer UDPPeer::addSpiltPacket(u8 channel, BufferedPacket toadd, bool reliable) { - assert(channel < CHANNEL_COUNT); + assert(channel < CHANNEL_COUNT); // Pre-condition return channels[channel].incoming_splits.insert(toadd,reliable); } @@ -1496,7 +1496,6 @@ void ConnectionSendThread::sendAsPacketReliable(BufferedPacket& p, Channel* chan LOG(derr_con<getDesc() <<"WARNING: Going to send a reliable packet" <<" in outgoing buffer" <getDesc() <<" INFO: dropped packet for non existent peer_id: " << peer_id << std::endl); - assert(reliable && "trying to send raw packet reliable but no peer found!"); + FATAL_ERROR_IF(!reliable, "Trying to send raw packet reliable but no peer found!"); return false; } Channel *channel = &(dynamic_cast(&peer)->channels[channelnum]); @@ -1582,7 +1581,7 @@ bool ConnectionSendThread::rawSendAsPacket(u16 peer_id, u8 channelnum, void ConnectionSendThread::processReliableCommand(ConnectionCommand &c) { - assert(c.reliable); + assert(c.reliable); // Pre-condition switch(c.type) { case CONNCMD_NONE: @@ -1626,7 +1625,7 @@ void ConnectionSendThread::processReliableCommand(ConnectionCommand &c) case CONNCMD_CONNECT: case CONNCMD_DISCONNECT: case CONCMD_ACK: - assert("Got command that shouldn't be reliable as reliable command" == 0); + FATAL_ERROR("Got command that shouldn't be reliable as reliable command"); default: LOG(dout_con<getDesc() <<" Invalid reliable command type: " << c.type <getDesc() <<" Invalid command type: " << c.type < data) { - assert(channelnum < CHANNEL_COUNT); + assert(channelnum < CHANNEL_COUNT); // Pre-condition PeerHelper peer = m_connection->getPeerNoEx(peer_id); if (!peer) @@ -2331,7 +2330,7 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, if (MAX_UDP_PEERS <= 65535 && peer_id >= MAX_UDP_PEERS) { errorstream << "Something is wrong with peer_id" << std::endl; - assert(0); + FATAL_ERROR(""); } if (type == TYPE_CONTROL) @@ -2343,7 +2342,7 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, if (controltype == CONTROLTYPE_ACK) { - assert(channel != 0); + FATAL_ERROR_IF(channel == 0, "Invalid channel (0)"); if (packetdata.getSize() < 4) throw InvalidIncomingDataException ("packetdata.getSize() < 4 (ACK header size)"); @@ -2511,7 +2510,7 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, } else if (type == TYPE_RELIABLE) { - assert(channel != 0); + FATAL_ERROR_IF(channel == 0, "Invalid channel (0)"); // Recursive reliable packets not allowed if (reliable) throw InvalidIncomingDataException("Found nested reliable packets"); @@ -2635,10 +2634,7 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, } // We should never get here. - // If you get here, add an exception or a return to some of the - // above conditionals. - assert(0); - throw BaseException("Error in Channel::ProcessPacket()"); + FATAL_ERROR("Invalid execution point"); } /* @@ -2724,7 +2720,7 @@ Connection::~Connection() /* Internal stuff */ void Connection::putEvent(ConnectionEvent &e) { - assert(e.type != CONNEVENT_NONE); + assert(e.type != CONNEVENT_NONE); // Pre-condition m_event_queue.push_back(e); } @@ -2738,7 +2734,7 @@ PeerHelper Connection::getPeer(u16 peer_id) } // Error checking - assert(node->second->id == peer_id); + FATAL_ERROR_IF(node->second->id != peer_id, "Invalid peer id"); return PeerHelper(node->second); } @@ -2753,7 +2749,7 @@ PeerHelper Connection::getPeerNoEx(u16 peer_id) } // Error checking - assert(node->second->id == peer_id); + FATAL_ERROR_IF(node->second->id != peer_id, "Invalid peer id"); return PeerHelper(node->second); } @@ -2925,7 +2921,7 @@ u32 Connection::Receive(u16 &peer_id, SharedBuffer &data) void Connection::Send(u16 peer_id, u8 channelnum, NetworkPacket* pkt, bool reliable) { - assert(channelnum < CHANNEL_COUNT); + assert(channelnum < CHANNEL_COUNT); // Pre-condition ConnectionCommand c; @@ -2955,9 +2951,7 @@ float Connection::getLocalStat(rate_stat_type type) { PeerHelper peer = getPeerNoEx(PEER_ID_SERVER); - if (!peer) { - assert("Connection::getLocalStat we couldn't get our own peer? are you serious???" == 0); - } + FATAL_ERROR_IF(!peer, "Connection::getLocalStat we couldn't get our own peer? are you serious???"); float retval = 0.0; @@ -2982,7 +2976,7 @@ float Connection::getLocalStat(rate_stat_type type) retval += dynamic_cast(&peer)->channels[j].getCurrentLossRateKB(); break; default: - assert("Connection::getLocalStat Invalid stat type" == 0); + FATAL_ERROR("Connection::getLocalStat Invalid stat type"); } } return retval; @@ -3075,7 +3069,7 @@ void Connection::DisconnectPeer(u16 peer_id) void Connection::sendAck(u16 peer_id, u8 channelnum, u16 seqnum) { - assert(channelnum < CHANNEL_COUNT); + assert(channelnum < CHANNEL_COUNT); // Pre-condition LOG(dout_con<getString(0), pkt->getSize()); @@ -602,7 +602,7 @@ void Client::handleCommand_ItemDef(NetworkPacket* pkt) // Mesh update thread must be stopped while // updating content definitions - assert(!m_mesh_update_thread.IsRunning()); + sanity_check(!m_mesh_update_thread.IsRunning()); // Decompress item definitions std::string datastring(pkt->getString(0), pkt->getSize()); diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 6cf456e4d..a0dcf6b71 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -641,6 +641,7 @@ content_t CNodeDefManager::allocateId() // IWritableNodeDefManager content_t CNodeDefManager::set(const std::string &name, const ContentFeatures &def) { + // Pre-conditions assert(name != ""); assert(name == def.name); @@ -690,7 +691,7 @@ content_t CNodeDefManager::set(const std::string &name, const ContentFeatures &d content_t CNodeDefManager::allocateDummy(const std::string &name) { - assert(name != ""); + assert(name != ""); // Pre-condition ContentFeatures f; f.name = name; return set(name, f); @@ -993,7 +994,9 @@ void CNodeDefManager::serialize(std::ostream &os, u16 protocol_version) f->serialize(wrapper_os, protocol_version); os2< count); // must not overflow + // must not overflow + u16 next = count + 1; + FATAL_ERROR_IF(next < count, "Overflow"); count++; } writeU16(os, count); diff --git a/src/noise.h b/src/noise.h index 05c877b32..e59e73b23 100644 --- a/src/noise.h +++ b/src/noise.h @@ -58,12 +58,12 @@ public: if (max-min > (PSEUDORANDOM_MAX + 1) / 10) { //dstream<<"WARNING: PseudoRandom::range: max > 32767"< max) { - assert(0); - return max; + assert("Something wrong with random number" == NULL); + //return max; } return (next()%(max-min+1))+min; } diff --git a/src/player.h b/src/player.h index 435875233..4459b421a 100644 --- a/src/player.h +++ b/src/player.h @@ -216,7 +216,7 @@ public: virtual PlayerSAO *getPlayerSAO() { return NULL; } virtual void setPlayerSAO(PlayerSAO *sao) - { assert(0); } + { FATAL_ERROR("FIXME"); } /* serialize() writes a bunch of text that can contain diff --git a/src/porting.cpp b/src/porting.cpp index 8a685539b..6d0ab78c4 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -391,7 +391,7 @@ void initializePaths() //TODO: Test this code char buf[BUFSIZ]; uint32_t len = sizeof(buf); - assert(_NSGetExecutablePath(buf, &len) != -1); + FATAL_ERROR_IF(_NSGetExecutablePath(buf, &len) == -1, ""); pathRemoveFile(buf, '/'); @@ -411,7 +411,7 @@ void initializePaths() mib[1] = KERN_PROC; mib[2] = KERN_PROC_PATHNAME; mib[3] = -1; - assert(sysctl(mib, 4, buf, &len, NULL, 0) != -1); + FATAL_ERROR_IF(sysctl(mib, 4, buf, &len, NULL, 0) == -1, ""); pathRemoveFile(buf, '/'); @@ -446,13 +446,13 @@ void initializePaths() */ #if defined(_WIN32) - const DWORD buflen = 1000; + const DWORD buflen = 1000; // FIXME: Surely there is a better way to do this char buf[buflen]; DWORD len; // Find path of executable and set path_share relative to it len = GetModuleFileName(GetModuleHandle(NULL), buf, buflen); - assert(len < buflen); + FATAL_ERROR_IF(len >= buflen, "Overlow"); pathRemoveFile(buf, '\\'); // Use ".\bin\.." @@ -460,7 +460,7 @@ void initializePaths() // Use "C:\Documents and Settings\user\Application Data\" len = GetEnvironmentVariable("APPDATA", buf, buflen); - assert(len < buflen); + FATAL_ERROR_IF(len >= buflen, "Overlow"); path_user = std::string(buf) + DIR_DELIM + PROJECT_NAME; /* @@ -476,7 +476,7 @@ void initializePaths() if (readlink("/proc/self/exe", buf, BUFSIZ-1) == -1) { errorstream << "Unable to read bindir "<< std::endl; #ifndef __ANDROID__ - assert("Unable to read bindir" == 0); + FATAL_ERROR("Unable to read bindir"); #endif } else { pathRemoveFile(buf, '/'); diff --git a/src/script/common/c_internal.cpp b/src/script/common/c_internal.cpp index f811dd5d3..61248534c 100644 --- a/src/script/common/c_internal.cpp +++ b/src/script/common/c_internal.cpp @@ -87,7 +87,7 @@ void script_error(lua_State *L) // computed depending on mode void script_run_callbacks(lua_State *L, int nargs, RunCallbacksMode mode) { - assert(lua_gettop(L) >= nargs + 1); + FATAL_ERROR_IF(lua_gettop(L) < nargs + 1, "Not enough arguments"); // Insert error handler lua_pushcfunction(L, script_error_handler); @@ -136,9 +136,7 @@ void log_deprecated(lua_State *L, std::string message) if (L != NULL) { script_error(L); } else { - /* As of april 2014 assert is not optimized to nop in release builds - * therefore this is correct. */ - assert("Can't do a scripterror for this deprecated message, so exit completely!"); + FATAL_ERROR("Can't do a scripterror for this deprecated message, so exit completely!"); } } diff --git a/src/script/cpp_api/s_async.cpp b/src/script/cpp_api/s_async.cpp index de1ebc07b..eb1a2923a 100644 --- a/src/script/cpp_api/s_async.cpp +++ b/src/script/cpp_api/s_async.cpp @@ -155,7 +155,7 @@ void AsyncEngine::step(lua_State *L, int errorhandler) lua_getfield(L, -1, "async_event_handler"); if (lua_isnil(L, -1)) { - assert("Async event handler does not exist!" == 0); + FATAL_ERROR("Async event handler does not exist!"); } luaL_checktype(L, -1, LUA_TFUNCTION); @@ -237,7 +237,7 @@ AsyncWorkerThread::AsyncWorkerThread(AsyncEngine* jobDispatcher, /******************************************************************************/ AsyncWorkerThread::~AsyncWorkerThread() { - assert(IsRunning() == false); + sanity_check(IsRunning() == false); } /******************************************************************************/ diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index 1f96373dc..71473d215 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -72,7 +72,7 @@ ScriptApiBase::ScriptApiBase() #endif m_luastack = luaL_newstate(); - assert(m_luastack); + FATAL_ERROR_IF(!m_luastack, "luaL_newstate() failed"); luaL_openlibs(m_luastack); diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 1f1d8bffa..840c34595 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -49,7 +49,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n, scriptIface->realityCheck(); lua_State *L = scriptIface->getStack(); - assert(lua_checkstack(L, 20)); + sanity_check(lua_checkstack(L, 20)); StackUnroller stack_unroller(L); lua_pushcfunction(L, script_error_handler); @@ -65,7 +65,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n, lua_pushnumber(L, m_id); lua_gettable(L, -2); if(lua_isnil(L, -1)) - assert(0); + FATAL_ERROR(""); lua_remove(L, -2); // Remove registered_abms // Call action @@ -459,7 +459,7 @@ int ModApiEnvMod::l_set_timeofday(lua_State *L) // Do it float timeofday_f = luaL_checknumber(L, 1); - assert(timeofday_f >= 0.0 && timeofday_f <= 1.0); + sanity_check(timeofday_f >= 0.0 && timeofday_f <= 1.0); int timeofday_mh = (int)(timeofday_f * 24000.0); // This should be set directly in the environment but currently // such changes aren't immediately sent to the clients, so call diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 2bed2a255..e6fcdcf83 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -90,7 +90,7 @@ int ModApiMainMenu::getBoolData(lua_State *L, std::string name,bool& valid) int ModApiMainMenu::l_update_formspec(lua_State *L) { GUIEngine* engine = getGuiEngine(L); - assert(engine != 0); + sanity_check(engine != NULL); if (engine->m_startgame) return 0; @@ -109,7 +109,7 @@ int ModApiMainMenu::l_update_formspec(lua_State *L) int ModApiMainMenu::l_start(lua_State *L) { GUIEngine* engine = getGuiEngine(L); - assert(engine != 0); + sanity_check(engine != NULL); //update c++ gamedata from lua table @@ -134,7 +134,7 @@ int ModApiMainMenu::l_start(lua_State *L) int ModApiMainMenu::l_close(lua_State *L) { GUIEngine* engine = getGuiEngine(L); - assert(engine != 0); + sanity_check(engine != NULL); engine->m_kill = true; return 0; @@ -144,7 +144,7 @@ int ModApiMainMenu::l_close(lua_State *L) int ModApiMainMenu::l_set_background(lua_State *L) { GUIEngine* engine = getGuiEngine(L); - assert(engine != 0); + sanity_check(engine != NULL); std::string backgroundlevel(luaL_checkstring(L, 1)); std::string texturename(luaL_checkstring(L, 2)); @@ -189,7 +189,7 @@ int ModApiMainMenu::l_set_background(lua_State *L) int ModApiMainMenu::l_set_clouds(lua_State *L) { GUIEngine* engine = getGuiEngine(L); - assert(engine != 0); + sanity_check(engine != NULL); bool value = lua_toboolean(L,1); @@ -209,7 +209,7 @@ int ModApiMainMenu::l_get_textlist_index(lua_State *L) int ModApiMainMenu::l_get_table_index(lua_State *L) { GUIEngine* engine = getGuiEngine(L); - assert(engine != 0); + sanity_check(engine != NULL); std::wstring tablename(narrow_to_wide(luaL_checkstring(L, 1))); GUITable *table = engine->m_menu->getTable(tablename); @@ -617,7 +617,7 @@ int ModApiMainMenu::l_delete_favorite(lua_State *L) int ModApiMainMenu::l_show_keys_menu(lua_State *L) { GUIEngine* engine = getGuiEngine(L); - assert(engine != 0); + sanity_check(engine != NULL); GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu( engine->m_device->getGUIEnvironment(), @@ -692,7 +692,7 @@ int ModApiMainMenu::l_delete_world(lua_State *L) int ModApiMainMenu::l_set_topleft_text(lua_State *L) { GUIEngine* engine = getGuiEngine(L); - assert(engine != 0); + sanity_check(engine != NULL); std::string text = ""; @@ -843,7 +843,7 @@ int ModApiMainMenu::l_copy_dir(lua_State *L) int ModApiMainMenu::l_extract_zip(lua_State *L) { GUIEngine* engine = getGuiEngine(L); - assert(engine != 0); + sanity_check(engine != NULL);(engine != 0); const char *zipfile = luaL_checkstring(L, 1); const char *destination = luaL_checkstring(L, 2); @@ -860,7 +860,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L) return 1; } - assert(fs->getFileArchiveCount() > 0); + sanity_check(fs->getFileArchiveCount() > 0); /**********************************************************************/ /* WARNING this is not threadsafe!! */ @@ -931,7 +931,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L) int ModApiMainMenu::l_get_mainmenu_path(lua_State *L) { GUIEngine* engine = getGuiEngine(L); - assert(engine != 0); + sanity_check(engine != NULL); lua_pushstring(L,engine->getScriptDir().c_str()); return 1; @@ -963,7 +963,7 @@ bool ModApiMainMenu::isMinetestPath(std::string path) int ModApiMainMenu::l_show_file_open_dialog(lua_State *L) { GUIEngine* engine = getGuiEngine(L); - assert(engine != 0); + sanity_check(engine != NULL); const char *formname= luaL_checkstring(L, 1); const char *title = luaL_checkstring(L, 2); @@ -1118,8 +1118,8 @@ int ModApiMainMenu::l_do_async_callback(lua_State *L) const char* serialized_param_raw = luaL_checklstring(L, 2, ¶m_length); - assert(serialized_func_raw != NULL); - assert(serialized_param_raw != NULL); + sanity_check(serialized_func_raw != NULL); + sanity_check(serialized_param_raw != NULL); std::string serialized_func = std::string(serialized_func_raw, func_length); std::string serialized_param = std::string(serialized_param_raw, param_length); diff --git a/src/server.cpp b/src/server.cpp index 09884f1bc..de23820dd 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1306,7 +1306,7 @@ Inventory* Server::getInventory(const InventoryLocation &loc) } break; default: - assert(0); + sanity_check(false); // abort break; } return NULL; @@ -1345,7 +1345,7 @@ void Server::setInventoryModified(const InventoryLocation &loc) } break; default: - assert(0); + sanity_check(false); // abort break; } } @@ -1454,7 +1454,7 @@ void Server::handlePeerChanges() break; default: - assert("Invalid peer change event received!" == 0); + FATAL_ERROR("Invalid peer change event received!"); break; } } @@ -2637,8 +2637,8 @@ void Server::UpdateCrafting(Player* player) // Put the new preview in InventoryList *plist = player->inventory.getList("craftpreview"); - assert(plist); - assert(plist->getSize() >= 1); + sanity_check(plist); + sanity_check(plist->getSize() >= 1); plist->changeItem(0, preview); } @@ -3026,7 +3026,7 @@ Inventory* Server::createDetachedInventory(const std::string &name) infostream<<"Server creating detached inventory \""<second.is_group) { os << line << "\n"; - assert(it->second.group != NULL); + sanity_check(it->second.group != NULL); was_modified |= it->second.group->updateConfigObject(is, os, "}", tab_depth + 1); } else { diff --git a/src/shader.cpp b/src/shader.cpp index 8c572ed49..8a5fd417b 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -196,7 +196,7 @@ public: virtual void OnSetConstants(video::IMaterialRendererServices *services, s32 userData) { video::IVideoDriver *driver = services->getVideoDriver(); - assert(driver); + sanity_check(driver != NULL); bool is_highlevel = userData; @@ -219,7 +219,7 @@ public: bool is_highlevel) { video::IVideoDriver *driver = services->getVideoDriver(); - assert(driver); + sanity_check(driver); // set inverted world matrix core::matrix4 invWorld = driver->getTransform(video::ETS_WORLD); @@ -364,7 +364,7 @@ void load_shaders(std::string name, SourceShaderCache *sourcecache, ShaderSource::ShaderSource(IrrlichtDevice *device): m_device(device) { - assert(m_device); + assert(m_device); // Pre-condition m_shader_callback = new ShaderCallback(this, "default"); @@ -505,7 +505,7 @@ void ShaderSource::insertSourceShader(const std::string &name_of_shader, "name_of_shader=\""<getVideoDriver(); - assert(driver); + sanity_check(driver); video::IGPUProgrammingServices *gpu = driver->getGPUProgrammingServices(); if(!gpu){ diff --git a/src/sound_openal.cpp b/src/sound_openal.cpp index b2b424a19..cb4c7b581 100644 --- a/src/sound_openal.cpp +++ b/src/sound_openal.cpp @@ -37,10 +37,10 @@ with this program; ifnot, write to the Free Software Foundation, Inc., #include #endif #include +#include #include "log.h" #include "filesys.h" #include "util/numeric.h" // myrand() -#include "debug.h" // assert() #include "porting.h" #include #include diff --git a/src/staticobject.h b/src/staticobject.h index 4918a1466..95a1b945e 100644 --- a/src/staticobject.h +++ b/src/staticobject.h @@ -68,8 +68,7 @@ public: { dstream<<"ERROR: StaticObjectList::insert(): " <<"id already exists"< 65535) throw SerializationError("String too long for serializeString"); char buf[2]; diff --git a/src/util/string.cpp b/src/util/string.cpp index 651293bfe..02a0586e7 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -320,7 +320,7 @@ char *mystrtok_r(char *s, const char *sep, char **lasts) } t++; } - + *lasts = t; return s; } @@ -329,15 +329,15 @@ u64 read_seed(const char *str) { char *endptr; u64 num; - + if (str[0] == '0' && str[1] == 'x') num = strtoull(str, &endptr, 16); else num = strtoull(str, &endptr, 10); - + if (*endptr) num = murmur_hash_64_ua(str, (int)strlen(str), 0x1337); - + return num; } @@ -614,4 +614,3 @@ void str_replace(std::string &str, char from, char to) { std::replace(str.begin(), str.end(), from, to); } - diff --git a/src/voxel.h b/src/voxel.h index 054644889..58ad39be4 100644 --- a/src/voxel.h +++ b/src/voxel.h @@ -213,7 +213,7 @@ public: return; } - assert(contains(a)); + assert(contains(a)); // pre-condition // Take back area, XY inclusive { diff --git a/src/wieldmesh.cpp b/src/wieldmesh.cpp index a2be55544..c1a898c1b 100644 --- a/src/wieldmesh.cpp +++ b/src/wieldmesh.cpp @@ -170,7 +170,7 @@ public: if (it == m_extrusion_meshes.end()) { // no viable resolution found; use largest one it = m_extrusion_meshes.find(MAX_EXTRUSION_MESH_RESOLUTION); - assert(it != m_extrusion_meshes.end()); + sanity_check(it != m_extrusion_meshes.end()); } scene::IMesh *mesh = it->second; @@ -231,7 +231,7 @@ WieldMeshSceneNode::WieldMeshSceneNode( WieldMeshSceneNode::~WieldMeshSceneNode() { - assert(g_extrusion_mesh_cache); + sanity_check(g_extrusion_mesh_cache); if (g_extrusion_mesh_cache->drop()) g_extrusion_mesh_cache = NULL; }