Skip to content
Permalink
Browse files

For usages of assert() that are meant to persist in Release builds (w…

…hen NDEBUG is defined), replace those usages with persistent alternatives
  • Loading branch information...
Zeno- committed Mar 6, 2015
1 parent a603a76 commit ced6d20295a8263757d57c02a07ffcb66688a163
Showing with 299 additions and 294 deletions.
  1. +3 −2 src/chat.cpp
  2. +22 −18 src/client.cpp
  3. +1 −1 src/client/clientlauncher.cpp
  4. +18 −18 src/client/tile.cpp
  5. +6 −3 src/clientiface.h
  6. +0 −28 src/clientmap.cpp
  7. +8 −7 src/clientmedia.cpp
  8. +7 −7 src/collision.cpp
  9. +3 −1 src/content_cao.cpp
  10. +5 −5 src/content_mapblock.cpp
  11. +3 −3 src/content_sao.cpp
  12. +1 −2 src/database-sqlite3.cpp
  13. +18 −2 src/debug.cpp
  14. +24 −13 src/debug.h
  15. +8 −7 src/environment.cpp
  16. +8 −8 src/fontengine.cpp
  17. +1 −1 src/game.cpp
  18. +2 −2 src/guiEngine.cpp
  19. +8 −8 src/guiFormSpecMenu.cpp
  20. +3 −3 src/guiKeyChangeMenu.cpp
  21. +3 −3 src/httpfetch.cpp
  22. +3 −3 src/inventory.cpp
  23. +1 −1 src/inventory.h
  24. +1 −1 src/inventorymanager.cpp
  25. +2 −2 src/itemdef.cpp
  26. +5 −3 src/keycode.cpp
  27. +1 −1 src/localplayer.cpp
  28. +1 −1 src/localplayer.h
  29. +4 −4 src/main.cpp
  30. +9 −10 src/map.cpp
  31. +5 −5 src/map.h
  32. +1 −1 src/mapblock.cpp
  33. +1 −1 src/mapblock.h
  34. +1 −0 src/mapgen_singlenode.cpp
  35. +1 −0 src/mapgen_v5.cpp
  36. +1 −0 src/mapgen_v6.cpp
  37. +1 −0 src/mapgen_v7.cpp
  38. +7 −6 src/mapnode.cpp
  39. +1 −1 src/mapsector.cpp
  40. +1 −1 src/mg_schematic.cpp
  41. +34 −40 src/network/connection.cpp
  42. +3 −3 src/network/connection.h
  43. +4 −4 src/network/packethandlers/client.cpp
  44. +5 −2 src/nodedef.cpp
  45. +3 −3 src/noise.h
  46. +1 −1 src/player.h
  47. +6 −6 src/porting.cpp
  48. +2 −4 src/script/common/c_internal.cpp
  49. +2 −2 src/script/cpp_api/s_async.cpp
  50. +1 −1 src/script/cpp_api/s_base.cpp
  51. +3 −3 src/script/lua_api/l_env.cpp
  52. +14 −14 src/script/lua_api/l_mainmenu.cpp
  53. +6 −6 src/server.cpp
  54. +1 −1 src/settings.cpp
  55. +5 −5 src/shader.cpp
  56. +1 −1 src/sound_openal.cpp
  57. +2 −3 src/staticobject.h
  58. +0 −2 src/test.cpp
  59. +0 −2 src/util/serialize.cpp
  60. +4 −5 src/util/string.cpp
  61. +1 −1 src/voxel.h
  62. +2 −2 src/wieldmesh.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)
@@ -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<std::string> &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<std::string, std::string> &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<std::string, std::string> &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"<<std::endl;
assert(m_itemdef_received);
assert(m_nodedef_received);
assert(mediaReceived());
assert(m_itemdef_received); // pre-condition
assert(m_nodedef_received); // pre-condition
assert(mediaReceived()); // pre-condition

const wchar_t* text = wgettext("Loading textures...");

@@ -1697,9 +1700,10 @@ scene::ISceneManager* Client::getSceneManager()
}
u16 Client::allocateUnknownNodeId(const std::string &name)
{
errorstream<<"Client::allocateUnknownNodeId(): "
<<"Client cannot allocate node IDs"<<std::endl;
assert(0);
errorstream << "Client::allocateUnknownNodeId(): "
<< "Client cannot allocate node IDs" << std::endl;
FATAL_ERROR("Client allocated unknown node");

return CONTENT_IGNORE;
}
ISoundManager* Client::getSoundManager()
@@ -1734,7 +1738,7 @@ scene::IAnimatedMesh* Client::getMesh(const std::string &filename)
io::IFileSystem *irrfs = m_device->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();
@@ -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
@@ -199,7 +199,7 @@ class SourceImageCache
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<std::string, video::IImage*>::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="<<name<<std::endl;

assert(get_current_thread_id() == m_main_thread);
sanity_check(get_current_thread_id() == m_main_thread);

m_sourcecache.insert(name, img, true, m_device->getVideoDriver());
m_source_image_existence.set(name, true);
@@ -695,16 +695,16 @@ 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; i<m_textureinfo_cache.size(); i++){
TextureInfo *ti = &m_textureinfo_cache[i];
video::IImage *img = generateImage(ti->name);
#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 &params)
{
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<u32> dim(2,2);
core::dimension2d<u32> 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<u32> srcdim = src->getDimension();
core::dimension2d<u32> dstdim = dst->getDimension();

assert(dstdim == imageTransformDimension(transform, srcdim));
// Pre-conditions
assert(dstdim == imageTransformDimension(transform, src->getDimension()));
assert(transform <= 7);

/*
@@ -426,9 +426,12 @@ class ClientInterface {
/* 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);

@@ -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<v2s16, MapSector*>::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)
Oops, something went wrong.

0 comments on commit ced6d20

Please sign in to comment.
You can’t perform that action at this time.