Using own ASSERT() that logs to file

git-svn-id: http://mc-server.googlecode.com/svn/trunk@297 0a769ca7-a7f5-676a-18bf-c427514a06d6
master
faketruth 2012-02-19 23:00:00 +00:00
parent df39f12e30
commit 0b616909e3
22 changed files with 50 additions and 59 deletions

View File

@ -65,6 +65,7 @@
// CRT stuff:
#include <assert.h>
#include <stdio.h>
#include <stdarg.h>

View File

@ -75,13 +75,6 @@
// Compatibility:
#define ASSERT assert
// STL stuff:
#include <vector>
#include <list>
@ -127,6 +120,7 @@
/// Faster than (int)floorf((float)x / (float)div)
#define FAST_FLOOR_DIV( x, div ) ( (x) < 0 ? (((int)x / div) - 1) : ((int)x / div) )
#define ASSERT( x ) { if( !(x) ) { LOGERROR("Assertion failed: \"%s\", file %s, line %i", #x, __FILE__, __LINE__ ); assert( !#x ); } }

View File

@ -81,7 +81,7 @@ void cJsonChunkSerializer::BlockEntity(cBlockEntity * a_BlockEntity)
default:
{
assert(!"Unhandled blocktype in BlockEntities list while saving to JSON");
ASSERT(!"Unhandled blocktype in BlockEntities list while saving to JSON");
break;
}
} // switch (BlockEntity->GetBlockType())

View File

@ -125,7 +125,7 @@ void cAuthenticator::Execute(void)
{
return;
}
assert(mQueue.size() > 0);
ASSERT(mQueue.size() > 0);
AString UserName = mQueue.front().mName;
AString ActualAddress = mAddress;

View File

@ -50,7 +50,7 @@ void cBlockingTCPLink::CloseSocket()
bool cBlockingTCPLink::Connect(const char * iAddress, unsigned int iPort)
{
assert(!m_Socket.IsValid());
ASSERT(!m_Socket.IsValid());
if (m_Socket.IsValid())
{
LOGWARN("WARNING: cTCPLink Connect() called while still connected.");
@ -101,7 +101,7 @@ bool cBlockingTCPLink::Connect(const char * iAddress, unsigned int iPort)
int cBlockingTCPLink::Send(char * a_Data, unsigned int a_Size, int a_Flags /* = 0 */ )
{
assert(m_Socket.IsValid());
ASSERT(m_Socket.IsValid());
if (!m_Socket.IsValid())
{
LOGERROR("cBlockingTCPLink: Trying to send data without a valid connection!");
@ -116,7 +116,7 @@ int cBlockingTCPLink::Send(char * a_Data, unsigned int a_Size, int a_Flags /* =
int cBlockingTCPLink::SendMessage( const char* a_Message, int a_Flags /* = 0 */ )
{
assert(m_Socket.IsValid());
ASSERT(m_Socket.IsValid());
if (!m_Socket.IsValid())
{
LOGWARN("cBlockingTCPLink: Trying to send message without a valid connection!");
@ -131,7 +131,7 @@ int cBlockingTCPLink::SendMessage( const char* a_Message, int a_Flags /* = 0 */
void cBlockingTCPLink::ReceiveData(AString & oData)
{
assert(m_Socket.IsValid());
ASSERT(m_Socket.IsValid());
if (!m_Socket.IsValid())
{
return;

View File

@ -833,7 +833,7 @@ void cChunk::SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_Block
return; // Clip
}
assert(IsValid()); // Is this chunk loaded / generated?
ASSERT(IsValid()); // Is this chunk loaded / generated?
int index = a_Y + (a_Z * 128) + (a_X * 128 * 16);
char OldBlockMeta = GetLight( m_BlockMeta, index );
@ -894,9 +894,9 @@ void cChunk::SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_Block
void cChunk::FastSetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta)
{
assert(!((a_X < 0 || a_X >= 16 || a_Y < 0 || a_Y >= 128 || a_Z < 0 || a_Z >= 16)));
ASSERT(!((a_X < 0 || a_X >= 16 || a_Y < 0 || a_Y >= 128 || a_Z < 0 || a_Z >= 16)));
assert(IsValid());
ASSERT(IsValid());
const int index = a_Y + (a_Z * 128) + (a_X * 128 * 16);
const char OldBlock = m_BlockType[index];
@ -1271,7 +1271,7 @@ bool cChunk::LoadFromDisk()
default:
{
assert(!"Unhandled block entity in file");
ASSERT(!"Unhandled block entity in file");
break;
}
}
@ -1425,7 +1425,7 @@ void cChunk::SaveToJson( Json::Value & a_Value )
default:
{
assert(!"Unhandled blocktype in BlockEntities list while saving to JSON");
ASSERT(!"Unhandled blocktype in BlockEntities list while saving to JSON");
break;
}
} // switch (BlockEntity->GetBlockType())

View File

@ -466,7 +466,7 @@ cChunkPtr cChunkMap::cChunkLayer::GetChunk( int a_ChunkX, int a_ChunkY, int a_Ch
if (!((LocalX < LAYER_SIZE) && (LocalZ < LAYER_SIZE) && (LocalX > -1) && (LocalZ > -1)))
{
assert(!"Asking a cChunkLayer for a chunk that doesn't belong to it!");
ASSERT(!"Asking a cChunkLayer for a chunk that doesn't belong to it!");
return cChunkPtr();
}

View File

@ -315,7 +315,7 @@ void cClientHandle::StreamChunks(void)
return;
}
assert(m_Player != NULL);
ASSERT(m_Player != NULL);
int ChunkPosX = FAST_FLOOR_DIV(m_Player->GetPosX(), 16);
int ChunkPosZ = FAST_FLOOR_DIV(m_Player->GetPosZ(), 16);
@ -331,7 +331,7 @@ void cClientHandle::StreamChunks(void)
LOGINFO("Streaming chunks centered on [%d, %d]", ChunkPosX, ChunkPosZ);
cWorld * World = m_Player->GetWorld();
assert(World != NULL);
ASSERT(World != NULL);
// Remove all loaded chunks that are no longer in range:
{
@ -405,7 +405,7 @@ void cClientHandle::StreamChunks(void)
void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
{
cWorld * World = m_Player->GetWorld();
assert(World != NULL);
ASSERT(World != NULL);
cChunkPtr Chunk = World->GetChunk(a_ChunkX, 0, a_ChunkZ);
if (!Chunk->HasClient(this))
@ -1829,7 +1829,7 @@ void cClientHandle::SendThread(void *lpParam)
if (NrmSendPackets.size() == 0 && LowSendPackets.size() == 0)
{
assert(!self->m_bKeepThreadGoing);
ASSERT(!self->m_bKeepThreadGoing);
if (self->m_bKeepThreadGoing)
{
LOGERROR("ERROR: Semaphore was signaled while no packets to send");
@ -1939,7 +1939,7 @@ void cClientHandle::DataReceived(const char * a_Data, int a_Size)
// Packet parsed successfully, add it to internal queue:
HandlePacket(pPacket);
// Erase the packet from the buffer:
assert(m_ReceivedData.size() > (size_t)NumBytes);
ASSERT(m_ReceivedData.size() > (size_t)NumBytes);
m_ReceivedData.erase(0, NumBytes + 1);
}
} // while (!Received.empty())

View File

@ -114,7 +114,7 @@ cCSLock::~cCSLock()
void cCSLock::Lock(void)
{
assert(!m_IsLocked);
ASSERT(!m_IsLocked);
m_IsLocked = true;
m_CS->Lock();
}
@ -125,7 +125,7 @@ void cCSLock::Lock(void)
void cCSLock::Unlock(void)
{
assert(m_IsLocked);
ASSERT(m_IsLocked);
m_IsLocked = false;
m_CS->Unlock();
}

View File

@ -96,7 +96,7 @@ void cEntity::WrapRotation()
void cEntity::MoveToCorrectChunk(bool a_bIgnoreOldChunk)
{
assert(m_World != NULL); // Entity needs a world to move to a chunk
ASSERT(m_World != NULL); // Entity needs a world to move to a chunk
if( !m_World ) return;
int ChunkX = 0, ChunkY = 0, ChunkZ = 0;

View File

@ -98,7 +98,7 @@ public: //tolua_export
virtual void Tick(float a_Dt) = 0; //tolua_export
virtual cPacket * GetSpawnPacket(void) const {assert(!"GetSpawnedPacket unimplemented!"); return NULL; }; // _X: Needs to be implemented due to Lua bindings
virtual cPacket * GetSpawnPacket(void) const {ASSERT(!"GetSpawnedPacket unimplemented!"); return NULL; }; // _X: Needs to be implemented due to Lua bindings
void SpawnOn (cClientHandle * a_Client); // tolua_export
void WrapRotation();

View File

@ -29,7 +29,7 @@ cEvent::cEvent(void)
LOGWARN("WARNING cEvent: Could not create unnamed semaphore, fallback to named.");
// _X: I'm unconvinced about using sem_unlink() just after a successful sem_open(), it seems wrong - why destroy the object just after creating?
assert(!"This codepath is really weird, if it is ever used, please check that everything works.");
ASSERT(!"This codepath is really weird, if it is ever used, please check that everything works.");
delete m_Event;
m_bIsNamed = true;

View File

@ -57,7 +57,7 @@ cFile::~cFile()
bool cFile::Open(const AString & iFileName, EMode iMode)
{
assert(!IsOpen()); // You should close the file before opening another one
ASSERT(!IsOpen()); // You should close the file before opening another one
if (IsOpen())
{
@ -72,7 +72,7 @@ bool cFile::Open(const AString & iFileName, EMode iMode)
case fmReadWrite: Mode = "ab+"; break;
default:
{
assert(!"Unhandled file mode");
ASSERT(!"Unhandled file mode");
return false;
}
}
@ -86,7 +86,7 @@ bool cFile::Open(const AString & iFileName, EMode iMode)
void cFile::Close(void)
{
assert(IsOpen()); // You should not close file objects that don't have an open file.
ASSERT(IsOpen()); // You should not close file objects that don't have an open file.
if (!IsOpen())
{
@ -112,7 +112,7 @@ bool cFile::IsOpen(void) const
bool cFile::IsEOF(void) const
{
assert(IsOpen());
ASSERT(IsOpen());
if (!IsOpen())
{
@ -130,7 +130,7 @@ bool cFile::IsEOF(void) const
/// Reads up to iNumBytes bytes into iBuffer, returns the number of bytes actually read, or -1 on failure; asserts if not open
int cFile::Read (void * iBuffer, int iNumBytes)
{
assert(IsOpen());
ASSERT(IsOpen());
if (!IsOpen())
{
@ -147,7 +147,7 @@ int cFile::Read (void * iBuffer, int iNumBytes)
/// Writes up to iNumBytes bytes from iBuffer, returns the number of bytes actually written, or -1 on failure; asserts if not open
int cFile::Write(const void * iBuffer, int iNumBytes)
{
assert(IsOpen());
ASSERT(IsOpen());
if (!IsOpen())
{
@ -165,7 +165,7 @@ int cFile::Write(const void * iBuffer, int iNumBytes)
/// Seeks to iPosition bytes from file start, returns old position or -1 for failure
int cFile::Seek (int iPosition)
{
assert(IsOpen());
ASSERT(IsOpen());
if (!IsOpen())
{
@ -187,7 +187,7 @@ int cFile::Seek (int iPosition)
/// Returns the current position (bytes from file start)
int cFile::Tell (void) const
{
assert(IsOpen());
ASSERT(IsOpen());
if (!IsOpen())
{
@ -204,7 +204,7 @@ int cFile::Tell (void) const
/// Returns the size of file, in bytes, or -1 for failure; asserts if not open
int cFile::GetSize(void) const
{
assert(IsOpen());
ASSERT(IsOpen());
if (!IsOpen())
{
@ -234,7 +234,7 @@ int cFile::GetSize(void) const
int cFile::ReadRestOfFile(AString & a_Contents)
{
assert(IsOpen());
ASSERT(IsOpen());
if (!IsOpen())
{

View File

@ -78,7 +78,7 @@ cIsThread::~cIsThread()
bool cIsThread::Start(void)
{
#ifdef _WIN32
assert(mHandle == NULL); // Has already started one thread?
ASSERT(mHandle == NULL); // Has already started one thread?
// Create the thread suspended, so that the mHandle variable is valid in the thread procedure
DWORD ThreadID = 0;
@ -99,7 +99,7 @@ bool cIsThread::Start(void)
#endif // _DEBUG and _MSC_VER
#else // _WIN32
assert(!mHasStarted);
ASSERT(!mHasStarted);
if (pthread_create(&mHandle, NULL, thrExecute, this))
{

View File

@ -12,10 +12,6 @@ class cLog;
class cMCLogger //tolua_export
{ //tolua_export
private:
#ifdef _WIN32
typedef char* va_list;
#endif
public: //tolua_export
cMCLogger();
cMCLogger( char* a_File ); //tolua_export

View File

@ -337,7 +337,7 @@ int cSocket::Send(const cPacket & a_Packet)
unsigned short cSocket::GetPort(void) const
{
assert(IsValid());
ASSERT(IsValid());
sockaddr_in Addr;
socklen_t AddrSize = sizeof(Addr);

View File

@ -156,7 +156,7 @@ cSocketThreads::cSocketThread::~cSocketThread()
void cSocketThreads::cSocketThread::AddClient(cSocket * a_Socket, cCallback * a_Client)
{
assert(m_NumSlots < MAX_SLOTS); // Use HasEmptySlot() to check before adding
ASSERT(m_NumSlots < MAX_SLOTS); // Use HasEmptySlot() to check before adding
m_Slots[m_NumSlots].m_Client = a_Client;
m_Slots[m_NumSlots].m_Socket = a_Socket;
@ -164,7 +164,7 @@ void cSocketThreads::cSocketThread::AddClient(cSocket * a_Socket, cCallback * a_
m_NumSlots++;
// Notify the thread of the change:
assert(m_ControlSocket2.IsValid());
ASSERT(m_ControlSocket2.IsValid());
m_ControlSocket2.Send("a", 1);
}
@ -193,7 +193,7 @@ bool cSocketThreads::cSocketThread::RemoveClient(const cCallback * a_Client)
m_NumSlots--;
// Notify the thread of the change:
assert(m_ControlSocket2.IsValid());
ASSERT(m_ControlSocket2.IsValid());
m_ControlSocket2.Send("r", 1);
return true;
} // for i - m_Slots[]
@ -227,7 +227,7 @@ bool cSocketThreads::cSocketThread::RemoveSocket(const cSocket * a_Socket)
m_NumSlots--;
// Notify the thread of the change:
assert(m_ControlSocket2.IsValid());
ASSERT(m_ControlSocket2.IsValid());
m_ControlSocket2.Send("r", 1);
return true;
} // for i - m_Slots[]
@ -245,7 +245,7 @@ bool cSocketThreads::cSocketThread::NotifyWrite(const cCallback * a_Client)
if (HasClient(a_Client))
{
// Notify the thread that there's another packet in the queue:
assert(m_ControlSocket2.IsValid());
ASSERT(m_ControlSocket2.IsValid());
m_ControlSocket2.Send("q", 1);
return true;
}
@ -354,7 +354,7 @@ void cSocketThreads::cSocketThread::Execute(void)
Addr.Family = cSocket::ADDRESS_FAMILY_INTERNET;
Addr.Address = cSocket::INTERNET_ADDRESS_LOCALHOST();
Addr.Port = m_ControlSocket2.GetPort();
assert(Addr.Port != 0); // We checked in the Start() method, but let's be sure
ASSERT(Addr.Port != 0); // We checked in the Start() method, but let's be sure
if (m_ControlSocket1.Connect(Addr) != 0)
{
LOGERROR("Cannot connect Control sockets for a cSocketThread (\"%s\"); continuing, but the server may be unreachable from now on.", cSocket::GetLastErrorString().c_str());
@ -509,7 +509,7 @@ void cSocketThreads::cSocketThread::WriteToSockets(fd_set * a_Write)
// If there's any data left, signalize the Control socket:
if (!m_Slots[i].m_Outgoing.empty())
{
assert(m_ControlSocket2.IsValid());
ASSERT(m_ControlSocket2.IsValid());
m_ControlSocket2.Send("q", 1);
}
*/

View File

@ -154,7 +154,7 @@ static float GetOreNoise( float x, float y, float z, cNoise & a_Noise )
unsigned int cWorldGenerator::MakeIndex(int x, int y, int z )
{
assert((x < 16) && (x > -1) && (y < 128) && (y > -1) && (z < 16) && (z > -1));
ASSERT((x < 16) && (x > -1) && (y < 128) && (y > -1) && (z < 16) && (z > -1));
return y + (z * 128) + (x * 128 * 16);
}

View File

@ -42,7 +42,7 @@ public:
virtual int Parse(const char * a_Data, int a_Size)
{
LOGERROR("Undefined Parse function for packet type 0x%x\n", m_PacketID );
assert(!"Undefined Parse function");
ASSERT(!"Undefined Parse function");
return -1;
}
@ -50,7 +50,7 @@ public:
virtual void Serialize(AString & a_Data) const
{
LOGERROR("Undefined Serialize function for packet type 0x%x\n", m_PacketID );
assert(!"Undefined Serialize function");
ASSERT(!"Undefined Serialize function");
}
virtual cPacket * Clone() const = 0;

View File

@ -48,7 +48,7 @@ int cPacket_CreativeInventoryAction::Parse(const char * a_Data, int a_Size)
void cPacket_CreativeInventoryAction::Serialize(AString & a_Data) const
{
short ItemID = m_ItemID;
assert(ItemID >= -1); // Check validity of packets in debug runtime
ASSERT(ItemID >= -1); // Check validity of packets in debug runtime
if (ItemID <= 0)
{
ItemID = -1;

View File

@ -21,7 +21,7 @@ cPacket_MapChunk::~cPacket_MapChunk()
cPacket_MapChunk::cPacket_MapChunk(cChunk * a_Chunk)
{
assert(a_Chunk->IsValid());
ASSERT(a_Chunk->IsValid());
m_PacketID = E_MAP_CHUNK;
m_PosX = a_Chunk->GetPosX() * 16; // It has to be block coordinates

View File

@ -10,7 +10,7 @@
void cPacket_NamedEntitySpawn::Serialize(AString & a_Data) const
{
short CurrentItem = m_CurrentItem;
assert(CurrentItem >= 0);
ASSERT(CurrentItem >= 0);
if (CurrentItem <= 0)
{
CurrentItem = 0;