Jelajahi Sumber

Merge pull request #1529 from GarageGames/pr/1153

Asserts cleanup PR with conflicts resolved.
Anis 10 tahun lalu
induk
melakukan
9085bb2178

+ 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;
 }

+ 0 - 18
Engine/source/platform/platformAssert.cpp

@@ -69,24 +69,6 @@ bool PlatformAssert::displayMessageBox(const char *title, const char *message, b
 }
 
 static const char *typeName[] = { "Unknown", "Fatal-ISV", "Fatal", "Warning" };
-//------------------------------------------------------------------------------
-static bool askToEnterDebugger(const char* message )
-{
-   static bool haveAsked = false;
-   static bool useDebugger = true;
-   if(!haveAsked )
-   {
-      static char tempBuff[1024];
-      dSprintf( tempBuff, 1024, "Torque has encountered an assertion with message\n\n"
-         "%s\n\n"
-         "Would you like to use the debugger? If you cancel, you won't be asked"
-         " again until you restart Torque.", message);
-
-      useDebugger = Platform::AlertOKCancel("Use debugger?", tempBuff );
-      haveAsked = true;
-   }
-   return useDebugger;
-}
 
 //--------------------------------------
 

+ 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.

+ 10 - 0
Engine/source/platform/types.visualc.h

@@ -32,6 +32,16 @@
 typedef signed _int64   S64;
 typedef unsigned _int64 U64;
 
+// The types.h version of TORQUE_UNUSED no longer works for recent versions of MSVC.
+// Since it appears that MS has made this impossible to do in a zero-overhead way,
+// just turn the warning off in release builds.
+#undef TORQUE_UNUSED
+#ifdef TORQUE_DEBUG
+#define TORQUE_UNUSED(var) ((0,0) ? (void)(var) : (void)0)
+#else
+#pragma warning(disable: 4189) // local variable is initialized but not referenced
+#define TORQUE_UNUSED(var) ((void)0)
+#endif
 
 //--------------------------------------
 // Compiler Version

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

@@ -964,7 +964,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;
@@ -1015,7 +1015,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();