Skip to content

Commit ced6d20

Browse files
committedMar 7, 2015
For usages of assert() that are meant to persist in Release builds (when NDEBUG is defined), replace those usages with persistent alternatives
1 parent a603a76 commit ced6d20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+299
-294
lines changed
 

‎src/chat.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ u32 ChatBuffer::getScrollback() const
8383

8484
const ChatLine& ChatBuffer::getLine(u32 index) const
8585
{
86-
assert(index < getLineCount());
86+
assert(index < getLineCount()); // pre-condition
8787
return m_unformatted[index];
8888
}
8989

@@ -107,7 +107,8 @@ void ChatBuffer::deleteOldest(u32 count)
107107
// keep m_formatted in sync
108108
if (del_formatted < m_formatted.size())
109109
{
110-
assert(m_formatted[del_formatted].first);
110+
111+
sanity_check(m_formatted[del_formatted].first);
111112
++del_formatted;
112113
while (del_formatted < m_formatted.size() &&
113114
!m_formatted[del_formatted].first)

‎src/client.cpp

+22-18
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void MeshUpdateQueue::addBlock(v3s16 p, MeshMakeData *data, bool ack_block_to_se
9797
{
9898
DSTACK(__FUNCTION_NAME);
9999

100-
assert(data);
100+
assert(data); // pre-condition
101101

102102
JMutexAutoLock lock(m_mutex);
103103

@@ -388,8 +388,9 @@ void Client::step(float dtime)
388388
if(counter <= 0.0) {
389389
counter = 2.0;
390390

391-
Player *myplayer = m_env.getLocalPlayer();
392-
assert(myplayer != NULL);
391+
Player *myplayer = m_env.getLocalPlayer();
392+
FATAL_ERROR_IF(myplayer == NULL, "Local player not found in environment.");
393+
393394
// Send TOSERVER_INIT
394395
// [0] u16 TOSERVER_INIT
395396
// [2] u8 SER_FMT_VER_HIGHEST_READ
@@ -707,7 +708,9 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
707708
// Create an irrlicht memory file
708709
io::IReadFile *rfile = irrfs->createMemoryReadFile(
709710
*data_rw, data_rw.getSize(), "_tempreadfile");
710-
assert(rfile);
711+
712+
FATAL_ERROR_IF(!rfile, "Could not create irrlicht memory file.");
713+
711714
// Read image
712715
video::IImage *img = vdrv->createImageFromFile(rfile);
713716
if(!img){
@@ -785,7 +788,8 @@ void Client::request_media(const std::vector<std::string> &file_requests)
785788
std::ostringstream os(std::ios_base::binary);
786789
writeU16(os, TOSERVER_REQUEST_MEDIA);
787790
size_t file_requests_size = file_requests.size();
788-
assert(file_requests_size <= 0xFFFF);
791+
792+
FATAL_ERROR_IF(file_requests_size > 0xFFFF, "Unsupported number of file requests");
789793

790794
// Packet dynamicly resized
791795
NetworkPacket* pkt = new NetworkPacket(TOSERVER_REQUEST_MEDIA, 2 + 0);
@@ -986,7 +990,8 @@ void Client::sendNodemetaFields(v3s16 p, const std::string &formname,
986990
const std::map<std::string, std::string> &fields)
987991
{
988992
size_t fields_size = fields.size();
989-
assert(fields_size <= 0xFFFF);
993+
994+
FATAL_ERROR_IF(fields_size > 0xFFFF, "Unsupported number of nodemeta fields");
990995

991996
NetworkPacket* pkt = new NetworkPacket(TOSERVER_NODEMETA_FIELDS, 0);
992997

@@ -1007,7 +1012,7 @@ void Client::sendInventoryFields(const std::string &formname,
10071012
const std::map<std::string, std::string> &fields)
10081013
{
10091014
size_t fields_size = fields.size();
1010-
assert(fields_size <= 0xFFFF);
1015+
FATAL_ERROR_IF(fields_size > 0xFFFF, "Unsupported number of inventory fields");
10111016

10121017
NetworkPacket* pkt = new NetworkPacket(TOSERVER_INVENTORY_FIELDS, 0);
10131018
*pkt << formname << (u16) (fields_size & 0xFFFF);
@@ -1141,7 +1146,7 @@ void Client::sendPlayerPos()
11411146
// Set peer id if not set already
11421147
if(myplayer->peer_id == PEER_ID_INEXISTENT)
11431148
myplayer->peer_id = our_peer_id;
1144-
// Check that an existing peer_id is the same as the connection's
1149+
11451150
assert(myplayer->peer_id == our_peer_id);
11461151

11471152
v3f pf = myplayer->getPosition();
@@ -1179,8 +1184,6 @@ void Client::sendPlayerItem(u16 item)
11791184
// Set peer id if not set already
11801185
if(myplayer->peer_id == PEER_ID_INEXISTENT)
11811186
myplayer->peer_id = our_peer_id;
1182-
1183-
// Check that an existing peer_id is the same as the connection's
11841187
assert(myplayer->peer_id == our_peer_id);
11851188

11861189
NetworkPacket* pkt = new NetworkPacket(TOSERVER_PLAYERITEM, 2);
@@ -1295,7 +1298,7 @@ Inventory* Client::getInventory(const InventoryLocation &loc)
12951298
}
12961299
break;
12971300
default:
1298-
assert(0);
1301+
FATAL_ERROR("Invalid inventory location type.");
12991302
}
13001303
return NULL;
13011304
}
@@ -1555,9 +1558,9 @@ float Client::mediaReceiveProgress()
15551558
void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font)
15561559
{
15571560
infostream<<"Client::afterContentReceived() started"<<std::endl;
1558-
assert(m_itemdef_received);
1559-
assert(m_nodedef_received);
1560-
assert(mediaReceived());
1561+
assert(m_itemdef_received); // pre-condition
1562+
assert(m_nodedef_received); // pre-condition
1563+
assert(mediaReceived()); // pre-condition
15611564

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

@@ -1697,9 +1700,10 @@ scene::ISceneManager* Client::getSceneManager()
16971700
}
16981701
u16 Client::allocateUnknownNodeId(const std::string &name)
16991702
{
1700-
errorstream<<"Client::allocateUnknownNodeId(): "
1701-
<<"Client cannot allocate node IDs"<<std::endl;
1702-
assert(0);
1703+
errorstream << "Client::allocateUnknownNodeId(): "
1704+
<< "Client cannot allocate node IDs" << std::endl;
1705+
FATAL_ERROR("Client allocated unknown node");
1706+
17031707
return CONTENT_IGNORE;
17041708
}
17051709
ISoundManager* Client::getSoundManager()
@@ -1734,7 +1738,7 @@ scene::IAnimatedMesh* Client::getMesh(const std::string &filename)
17341738
io::IFileSystem *irrfs = m_device->getFileSystem();
17351739
io::IReadFile *rfile = irrfs->createMemoryReadFile(
17361740
*data_rw, data_rw.getSize(), filename.c_str());
1737-
assert(rfile);
1741+
FATAL_ERROR_IF(!rfile, "Could not create/open RAM file");
17381742

17391743
scene::IAnimatedMesh *mesh = smgr->getMesh(rfile);
17401744
rfile->drop();

0 commit comments

Comments
 (0)
Please sign in to comment.