Skip to content

Commit

Permalink
For usages of assert() that are meant to persist in Release builds (w…
Browse files Browse the repository at this point in the history
…hen NDEBUG is defined), replace those usages with persistent alternatives
  • Loading branch information
Zeno- committed Mar 7, 2015
1 parent a603a76 commit ced6d20
Show file tree
Hide file tree
Showing 62 changed files with 299 additions and 294 deletions.
5 changes: 3 additions & 2 deletions src/chat.cpp
Expand Up @@ -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];
}

Expand All @@ -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)
Expand Down
40 changes: 22 additions & 18 deletions src/client.cpp
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1295,7 +1298,7 @@ Inventory* Client::getInventory(const InventoryLocation &loc)
}
break;
default:
assert(0);
FATAL_ERROR("Invalid inventory location type.");
}
return NULL;
}
Expand Down Expand Up @@ -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...");

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/client/clientlauncher.cpp
Expand Up @@ -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
Expand Down
36 changes: 18 additions & 18 deletions src/client/tile.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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] != '[')
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

/*
Expand Down
9 changes: 6 additions & 3 deletions src/clientiface.h
Expand Up @@ -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);

Expand Down
28 changes: 0 additions & 28 deletions src/clientmap.cpp
Expand Up @@ -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)
Expand Down

0 comments on commit ced6d20

Please sign in to comment.