Quellcode durchsuchen

Tidy up and fix the various Assert macros

Rephrase the macros so that they can be used in expressions, and
properly require semicolons. And add the semicolons where missing.
Ben Payne vor 10 Jahren
Ursprung
Commit
c19a70814c

+ 3 - 3
Engine/source/T3D/fx/fxFoliageReplicator.cpp

@@ -426,7 +426,7 @@ void fxFoliageReplicator::CreateFoliage(void)
    Point3F	MaxPoint(  0.5,  0.5,  0.5 );
 
    // Check Host.
-   AssertFatal(isClientObject(), "Trying to create Foliage on Server, this is bad!")
+   AssertFatal(isClientObject(), "Trying to create Foliage on Server, this is bad!");
 
       // Cannot continue without Foliage Texture!
       if (dStrlen(mFieldData.mFoliageFile) == 0) 
@@ -1134,7 +1134,7 @@ void fxFoliageReplicator::ProcessQuadrant(fxFoliageQuadrantNode* pParentNode, fx
 void fxFoliageReplicator::SyncFoliageReplicators(void)
 {
    // Check Host.
-   AssertFatal(isServerObject(), "We *MUST* be on server when Synchronising Foliage!")
+   AssertFatal(isServerObject(), "We *MUST* be on server when Synchronising Foliage!");
 
       // Find the Replicator Set.
    SimSet *fxFoliageSet = dynamic_cast<SimSet*>(Sim::findObject("fxFoliageSet"));
@@ -1196,7 +1196,7 @@ void fxFoliageReplicator::DestroyFoliageItems()
 void fxFoliageReplicator::DestroyFoliage(void)
 {
    // Check Host.
-   AssertFatal(isClientObject(), "Trying to destroy Foliage on Server, this is bad!")
+   AssertFatal(isClientObject(), "Trying to destroy Foliage on Server, this is bad!");
 
       // Destroy Quad-tree.
       mPotentialFoliageNodes = 0;

+ 1 - 1
Engine/source/T3D/fx/fxShapeReplicator.cpp

@@ -224,7 +224,7 @@ void fxShapeReplicator::CreateShapes(void)
    }
 
    // Check Shapes.
-   AssertFatal(mCurrentShapeCount==0,"Shapes already present, this should not be possible!")
+   AssertFatal(mCurrentShapeCount==0,"Shapes already present, this should not be possible!");
 
       // Check that we have a shape...
       if (!mFieldData.mShapeFile) return;

+ 1 - 1
Engine/source/console/codeBlock.cpp

@@ -61,7 +61,7 @@ CodeBlock::CodeBlock()
 CodeBlock::~CodeBlock()
 {
    // Make sure we aren't lingering in the current code block...
-   AssertFatal(smCurrentCodeBlock != this, "CodeBlock::~CodeBlock - Caught lingering in smCurrentCodeBlock!")
+   AssertFatal(smCurrentCodeBlock != this, "CodeBlock::~CodeBlock - Caught lingering in smCurrentCodeBlock!");
 
    if(name)
       removeFromCodeList();

+ 1 - 1
Engine/source/core/idGenerator.h

@@ -74,7 +74,7 @@ public:
 
    void free(U32 id)
    {
-      AssertFatal(id >= mIdBlockBase, "IdGenerator::alloc: invalid id, id does not belong to this IdGenerator.")
+      AssertFatal(id >= mIdBlockBase, "IdGenerator::alloc: invalid id, id does not belong to this IdGenerator.");
       if(id == mNextId - 1)
       {
          mNextId--;

+ 2 - 2
Engine/source/environment/timeOfDay.cpp

@@ -402,7 +402,7 @@ void TimeOfDay::_getSunColor( ColorF *outColor ) const
    //simple check
    if ( mColorTargets[0].elevation != 0.0f )
    {
-      AssertFatal(0, "TimeOfDay::GetColor() - First elevation must be 0.0 radians")
+      AssertFatal(0, "TimeOfDay::GetColor() - First elevation must be 0.0 radians");
       outColor->set(1.0f, 1.0f, 1.0f);
       //mBandMod = 1.0f;
       //mCurrentBandColor = color;
@@ -411,7 +411,7 @@ void TimeOfDay::_getSunColor( ColorF *outColor ) const
 
    if ( mColorTargets[mColorTargets.size()-1].elevation != M_PI_F )
    {
-      AssertFatal(0, "Celestails::GetColor() - Last elevation must be PI")
+      AssertFatal(0, "Celestails::GetColor() - Last elevation must be PI");
       outColor->set(1.0f, 1.0f, 1.0f);
       //mBandMod = 1.0f;
       //mCurrentBandColor = color;

+ 1 - 1
Engine/source/gfx/bitmap/loaders/bitmapTga.cpp

@@ -483,7 +483,7 @@ static bool sReadTGA(Stream &stream, GBitmap *bitmap)
 
 static bool sWriteTGA(GBitmap *bitmap, Stream &stream, U32 compressionLevel)
 {
-   AssertISV(false, "GBitmap::writeTGA - doesn't support writing tga files!")
+   AssertISV(false, "GBitmap::writeTGA - doesn't support writing tga files!");
 
    return false;
 }

+ 2 - 1
Engine/source/gui/core/guiCanvas.cpp

@@ -712,7 +712,8 @@ bool GuiCanvas::processMouseEvent(InputEventInfo &inputEvent)
    // Need to query platform for specific things
    AssertISV(mPlatformWindow, "GuiCanvas::processMouseEvent - no window present!");
    PlatformCursorController *pController = mPlatformWindow->getCursorController();
-   AssertFatal(pController != NULL, "GuiCanvas::processInputEvent - No Platform Controller Found")
+   AssertFatal(pController != NULL, "GuiCanvas::processInputEvent - No Platform Controller Found");
+
 
       //copy the modifier into the new event
       mLastEvent.modifier = inputEvent.modifier;

+ 24 - 29
Engine/source/platform/platformAssert.h

@@ -64,19 +64,17 @@ public:
 
 
 #ifdef TORQUE_ENABLE_ASSERTS
-   /*!
-      Assert that the statement x is true, and continue processing.
+/*!
+   Assert that the statement x is true, and continue processing.
 
-      If the statment x is true, continue processing.
+   If the statment x is true, continue processing.
 
-      If the statement x is false, log the file and line where the assert occured,
-      the message y and continue processing.
+   If the statement x is false, log the file and line where the assert occured,
+   the message y and continue processing.
 
-      These asserts are only present in DEBUG builds.
-    */
-   #define AssertWarn(x, y)      \
-         { if ((x)==0) \
-            ::PlatformAssert::processAssert(::PlatformAssert::Warning, __FILE__, __LINE__,  y); }
+   These asserts are only present in DEBUG builds.
+   */
+#define AssertWarn(x, y) (void)(!!(x) || ::PlatformAssert::processAssert(::PlatformAssert::Warning, __FILE__, __LINE__,  y))
 
    /*!
       Helper macro called when AssertFatal failed.
@@ -86,27 +84,27 @@ public:
       #define ON_FAIL_ASSERTFATAL
    #endif
 
-   /*!
-      Assert that the statement x is true, otherwise halt.
+/*!
+   Assert that the statement x is true, otherwise halt.
 
-      If the statement x is true, continue processing.
+   If the statement x is true, continue processing.
 
-      If the statement x is false, log the file and line where the assert occured,
-      the message y and displaying a dialog containing the message y. The user then
-      has the option to halt or continue causing the debugger to break.
+   If the statement x is false, log the file and line where the assert occured,
+   the message y and displaying a dialog containing the message y. The user then
+   has the option to halt or continue causing the debugger to break.
 
-      These asserts are only present in DEBUG builds.
+   These asserts are only present in DEBUG builds.
 
-      This assert is very useful for verifying data as well as function entry and
-      exit conditions.
-    */
-   #define AssertFatal(x, y)         \
-      { if (((bool)(x))==false) \
-         { if ( ::PlatformAssert::processAssert(::PlatformAssert::Fatal, __FILE__, __LINE__,  y) ) { ::Platform::debugBreak(); } } } 
+   This assert is very useful for verifying data as well as function entry and
+   exit conditions.
+   */
+#define AssertFatal(x, y) ((!(x) && ::PlatformAssert::processAssert(::PlatformAssert::Fatal, __FILE__, __LINE__,  y)) ? ::Platform::debugBreak() : (void)0)                                                                  \
 
 #else
-   #define AssertFatal(x, y)   { TORQUE_UNUSED(x); TORQUE_UNUSED(y); }
-   #define AssertWarn(x, y)    { TORQUE_UNUSED(x); TORQUE_UNUSED(y); }
+
+#define AssertFatal(x, y) TORQUE_UNUSED(x)
+#define AssertWarn(x, y)  TORQUE_UNUSED(x)
+
 #endif
 
 /*!
@@ -121,10 +119,7 @@ public:
    This assert should only be used for rare conditions where the application cannot continue
    execution without seg-faulting and you want to display a nice exit message.
  */
-#define AssertISV(x, y)  \
-   { if ((x)==0)         \
-{ if ( ::PlatformAssert::processAssert(::PlatformAssert::Fatal_ISV, __FILE__, __LINE__,  y) ) { ::Platform::debugBreak(); } } }
-
+#define AssertISV(x, y) ((!(x) && ::PlatformAssert::processAssert(::PlatformAssert::Fatal_ISV, __FILE__, __LINE__,  y)) ? ::Platform::debugBreak() : (void)0)                                                                  \
 
 /*!
    Sprintf style string formating into a fixed temporary buffer.

+ 2 - 2
Engine/source/sim/netGhost.cpp

@@ -958,7 +958,7 @@ void NetConnection::activateGhosting()
         // Iterate through the scope always objects...
         for (j = mGhostZeroUpdateIndex - 1; j >= 0; j--)
         {
-            AssertFatal((mGhostArray[j]->flags & GhostInfo::ScopeAlways) != 0, "NetConnection::activateGhosting:  Non-scope always in the scope always list.")
+            AssertFatal((mGhostArray[j]->flags & GhostInfo::ScopeAlways) != 0, "NetConnection::activateGhosting:  Non-scope always in the scope always list.");
 
             // Clear the ghost update mask and flags appropriately.
             mGhostArray[j]->updateMask = 0;
@@ -1009,7 +1009,7 @@ void NetConnection::activateGhosting()
         // Iterate through the scope always objects...
         for (j = mGhostZeroUpdateIndex - 1; j >= 0; j--)
         {
-            AssertFatal((mGhostArray[j]->flags & GhostInfo::ScopeAlways) != 0, "NetConnection::activateGhosting:  Non-scope always in the scope always list.")
+            AssertFatal((mGhostArray[j]->flags & GhostInfo::ScopeAlways) != 0, "NetConnection::activateGhosting:  Non-scope always in the scope always list.");
 
             // Clear the ghost update mask and flags appropriately.
             mGhostArray[j]->updateMask = 0;

+ 1 - 1
Engine/source/util/catmullRom.cpp

@@ -48,7 +48,7 @@ CatmullRomBase::CatmullRomBase()
 void CatmullRomBase::_initialize( U32 count, const F32 *times )
 {
    //AssertFatal( times, "CatmullRomBase::_initialize() - Got null position!" )
-   AssertFatal( count > 1, "CatmullRomBase::_initialize() - Must have more than 2 points!" )
+   AssertFatal( count > 1, "CatmullRomBase::_initialize() - Must have more than 2 points!" );
 
    // set up arrays
    mTimes = new F32[count];

+ 2 - 2
Engine/source/util/catmullRom.h

@@ -142,8 +142,8 @@ inline void CatmullRom<TYPE>::clear()
 template<typename TYPE>
 inline void CatmullRom<TYPE>::initialize( U32 count, const TYPE *positions, const F32 *times )
 {
-   AssertFatal( positions, "CatmullRom::initialize - Got null position!" )
-   AssertFatal( count > 1, "CatmullRom::initialize - Must have more than 2 points!" )
+   AssertFatal( positions, "CatmullRom::initialize - Got null position!" );
+   AssertFatal( count > 1, "CatmullRom::initialize - Must have more than 2 points!" );
 
    // Clean up any previous state.
    clear();