Kaynağa Gözat

Merge pull request #1035 from bpay/memfixes

Memfixes
Luis Anton Rebollo 10 yıl önce
ebeveyn
işleme
6492028bb2

+ 2 - 0
Engine/source/T3D/gameBase/gameConnection.cpp

@@ -208,6 +208,8 @@ GameConnection::GameConnection()
 
    mAIControlled = false;
 
+   mLastPacketTime = 0;
+
    mDisconnectReason[0] = 0;
 
    //blackout vars

+ 2 - 2
Engine/source/T3D/shapeImage.cpp

@@ -3339,6 +3339,6 @@ void ShapeBase::ejectShellCasing( U32 imageSlot )
 
    if (!casing->registerObject())
       delete casing;
-
-   casing->init( shellPos, shellVel );
+   else
+      casing->init( shellPos, shellVel );
 }

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

@@ -400,7 +400,7 @@ void CodeStream::reset()
    {
       CodeData *next = itr->next;
       dFree(itr->data);
-      dFree(itr);
+      delete(itr);
       itr = next;
    }
    

+ 2 - 2
Engine/source/console/consoleInternal.cpp

@@ -882,7 +882,7 @@ void Namespace::Entry::clear()
    // Clean up usage strings generated for script functions.
    if( ( mType == Namespace::Entry::ConsoleFunctionType ) && mUsage )
    {
-      delete mUsage;
+      dFree(mUsage);
       mUsage = NULL;
    }
 }
@@ -908,7 +908,7 @@ Namespace::~Namespace()
    clearEntries();
    if( mUsage && mCleanUpUsage )
    {
-      delete mUsage;
+      dFree(mUsage);
       mUsage = NULL;
       mCleanUpUsage = false;
    }

+ 1 - 0
Engine/source/core/dnet.cpp

@@ -66,6 +66,7 @@ ConnectionProtocol::ConnectionProtocol()
    mLastSendSeq = 0; // start sending at 1
    mAckMask = 0;
    mLastRecvAckAck = 0;
+   mConnectionEstablished = false;
 }
 void ConnectionProtocol::buildSendPacketHeader(BitStream *stream, S32 packetType)
 {

+ 7 - 4
Engine/source/core/strings/unicode.cpp

@@ -601,10 +601,13 @@ bool chompUTF8BOM( const char *inString, char **outStringPtr )
 {
    *outStringPtr = const_cast<char *>( inString );
 
-   U8 bom[4];
-   dMemcpy( bom, inString, 4 );
-
-   bool valid = isValidUTF8BOM( bom );
+   bool valid = false;
+   if (inString[0] && inString[1] && inString[2])
+   {
+      U8 bom[4];
+      dMemcpy(bom, inString, 4);
+      valid = isValidUTF8BOM(bom);
+   }
 
    // This is hackey, but I am not sure the best way to do it at the present.
    // The only valid BOM is a UTF8 BOM, which is 3 bytes, even though we read

+ 2 - 2
Engine/source/core/util/str.cpp

@@ -495,7 +495,7 @@ DefineConsoleFunction( dumpStringMemStats, void, (), , "()"
 void* String::StringData::operator new( size_t size, U32 len )
 {
    AssertFatal( len != 0, "String::StringData::operator new() - string must not be empty" );
-   StringData *str = reinterpret_cast<StringData*>( dMalloc( size + len * sizeof(StringChar) ) );
+   StringData *str = static_cast<StringData*>( dMalloc( size + len * sizeof(StringChar) ) );
 
    str->mLength      = len;
 
@@ -523,7 +523,7 @@ void String::StringData::operator delete(void *ptr)
 void* String::StringData::operator new( size_t size, U32 len, DataChunker& chunker )
 {
    AssertFatal( len != 0, "String::StringData::operator new() - string must not be empty" );
-   StringData *str = reinterpret_cast<StringData*>( chunker.alloc( size + len * sizeof(StringChar) ) );
+   StringData *str = static_cast<StringData*>( chunker.alloc( size + len * sizeof(StringChar) ) );
 
    str->mLength      = len;
 

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

@@ -155,8 +155,8 @@ void DecalRoadNodeEvent::padListToSize()
       newlist->mPositions.merge(list->mPositions);
       newlist->mWidths.merge(list->mWidths);
 
-      mNodeList = newlist;
       delete list;
+      mNodeList = list = newlist;
    }
 
    // Pad our list end?
@@ -1726,4 +1726,4 @@ DefineEngineMethod( DecalRoad, postApply, void, (),,
                   )
 {
    object->inspectPostApply();
-}
+}

+ 1 - 1
Engine/source/environment/meshRoad.cpp

@@ -203,8 +203,8 @@ void MeshRoadNodeEvent::padListToSize()
       newlist->mDepths.merge(list->mDepths);
       newlist->mNormals.merge(list->mNormals);
 
-      mNodeList = newlist;
       delete list;
+      mNodeList = list = newlist;
    }
 
    // Pad our list end?

+ 1 - 1
Engine/source/environment/river.cpp

@@ -227,8 +227,8 @@ void RiverNodeEvent::padListToSize()
       newlist->mDepths.merge(list->mDepths);
       newlist->mNormals.merge(list->mNormals);
 
-      mNodeList = newlist;
       delete list;
+      mNodeList = list = newlist;
    }
 
    // Pad our list end?

+ 1 - 0
Engine/source/gfx/gfxDevice.cpp

@@ -279,6 +279,7 @@ GFXDevice::~GFXDevice()
 #endif
 
    SAFE_DELETE( mTextureManager );
+   SAFE_DELETE( mFrameTime );
 
    // Clear out our state block references
    mCurrentStateBlocks.clear();

+ 5 - 0
Engine/source/gui/containers/guiRolloutCtrl.cpp

@@ -56,6 +56,10 @@ IMPLEMENT_CALLBACK( GuiRolloutCtrl, onCollapsed, void, (), (),
 //-----------------------------------------------------------------------------
 
 GuiRolloutCtrl::GuiRolloutCtrl()
+ : mHeader(0,0,0,0),
+   mExpanded(0,0,0,0),
+   mChildRect(0,0,0,0),
+   mMargin(0,0,0,0)
 {
    mExpanded.set(0,0,200,60);
    mCaption             = StringTable->EmptyString();
@@ -70,6 +74,7 @@ GuiRolloutCtrl::GuiRolloutCtrl()
    mIsContainer = true;
    mCanCollapse = true;
    mAutoCollapseSiblings = false;
+   mHasTexture = false;
    // Make sure we receive our ticks.
    setProcessTicks();
 }

+ 3 - 2
Engine/source/gui/containers/guiScrollCtrl.cpp

@@ -72,8 +72,9 @@ GuiScrollCtrl::GuiScrollCtrl()
    mAnimating( false ),
    mScrollAnimSpeed( -1 ),
    mScrollTargetPos( -1, -1 ),
-	mChildExt(0, 0),
-	mChildPos(0, 0)
+   mChildExt(0, 0),
+   mChildPos(0, 0),
+   mBaseThumbSize(0)
 {
    mIsContainer = true;
    setExtent(200,200);

+ 1 - 1
Engine/source/gui/containers/guiWindowCtrl.cpp

@@ -98,10 +98,10 @@ GuiWindowCtrl::GuiWindowCtrl()
    mMouseMovingWin = false;
    mMouseResizeWidth = false;
    mMouseResizeHeight = false;
-   setExtent(100, 200);
    mMinimizeIndex = -1;
    mTabIndex = -1;
    mBitmapBounds = NULL;
+   setExtent(100, 200);
 
    RectI closeRect(80, 2, 16, 16);
    mCloseButton = closeRect;

+ 3 - 0
Engine/source/gui/core/guiCanvas.cpp

@@ -95,9 +95,11 @@ extern InputModifiers convertModifierBits(const U32 in);
 //-----------------------------------------------------------------------------
 
 GuiCanvas::GuiCanvas(): GuiControl(),
+                        mCurUpdateRect(0, 0, 0, 0),
                         mCursorEnabled(true),
                         mForceMouseToGUI(false),
                         mAlwaysHandleMouseButtons(false),
+                        mCursorChanged(0),
                         mClampTorqueCursor(true),
                         mShowCursor(true),
                         mLastCursorEnabled(false),
@@ -121,6 +123,7 @@ GuiCanvas::GuiCanvas(): GuiControl(),
                         mLeftMouseLast(false),
                         mMiddleMouseLast(false),
                         mRightMouseLast(false),
+                        mMouseDownPoint(0.0f,0.0f),
                         mPlatformWindow(NULL),
                         mLastRenderMs(0),
                         mDisplayWindow(true)

+ 6 - 5
Engine/source/main/main.cpp

@@ -49,7 +49,7 @@ bool getDllName(std::wstring& dllName, const std::wstring suffix)
    return true;
 }
 
-int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCommandShow)
+int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCommandShow)
 {
    // Try to find the game DLL, which may have one of several file names.
    HMODULE hGame = NULL;
@@ -75,10 +75,11 @@ int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdL
       return -1;
    }
 
+   enum { errorSize = 4096 };
    if (!hGame)
    {
-      wchar_t error[4096];
-      _swprintf_l(error, sizeof(error), L"Unable to load game library: %s.  Please make sure it exists and the latest DirectX is installed.", _get_current_locale(), dllName.c_str());
+      wchar_t error[errorSize];
+      _swprintf_l(error, errorSize, L"Unable to load game library: %s.  Please make sure it exists and the latest DirectX is installed.", _get_current_locale(), dllName.c_str());
       MessageBoxW(NULL, error, L"Error",  MB_OK|MB_ICONWARNING);
       return -1;
    }
@@ -86,8 +87,8 @@ int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdL
    torque_winmain = (int (*)(HINSTANCE hInstance, HINSTANCE h, LPSTR lpszCmdLine, int nShow))GetProcAddress(hGame, "torque_winmain");
    if (!torque_winmain)
    {
-      wchar_t error[4096];
-      _swprintf_l(error, sizeof(error), L"Missing torque_winmain export in game library: %s.  Please make sure that it exists and the latest DirectX is installed.", _get_current_locale(), dllName.c_str());
+      wchar_t error[errorSize];
+      _swprintf_l(error, errorSize, L"Missing torque_winmain export in game library: %s.  Please make sure that it exists and the latest DirectX is installed.", _get_current_locale(), dllName.c_str());
       MessageBoxW(NULL, error, L"Error",  MB_OK|MB_ICONWARNING);
       return -1;
    }

+ 3 - 2
Engine/source/materials/materialList.cpp

@@ -263,8 +263,6 @@ void MaterialList::clearMatInstList()
       if (mMatInstList[i])
       {
          BaseMatInstance* current = mMatInstList[i];
-         delete current;
-         mMatInstList[i] = NULL;
 
          // ok, since ts material lists can remap difference indexes to the same object 
          // we need to make sure that we don't delete the same memory twice.  walk the 
@@ -272,6 +270,9 @@ void MaterialList::clearMatInstList()
          for (U32 j=0; j<mMatInstList.size(); j++)
             if (mMatInstList[j] == current)
                mMatInstList[j] = NULL;
+
+         mMatInstList[i] = NULL;
+         delete current;
       }
    }
 }

+ 2 - 2
Engine/source/platformWin32/menus/popupMenuWin32.cpp

@@ -160,7 +160,7 @@ void PopupMenu::createPlatformMenu()
    mData->mMenu = mIsPopup ? CreatePopupMenu() : CreateMenu();
    AssertFatal(mData->mMenu, "Unable to create menu");
 
-   MENUINFO mi;
+   MENUINFO mi = { 0 };
    mi.cbSize = sizeof(mi);
    mi.fMask = MIM_MENUDATA;
    mi.dwMenuData = (ULONG_PTR)this;
@@ -178,7 +178,7 @@ S32 PopupMenu::insertItem(S32 pos, const char *title, const char* accelerator, c
    if(isAttached && pWindow == NULL)
       return -1;
 
-   MENUITEMINFOA mi;
+   MENUITEMINFOA mi = { 0 };
    mi.cbSize = sizeof(mi);
    mi.fMask = MIIM_ID|MIIM_TYPE;
    mi.wID = (mData->mMenuID * PlatformPopupMenuData::PopupMenuIDRange) + mData->mLastID + 1;

+ 16 - 14
Engine/source/platformWin32/winWindow.cpp

@@ -352,19 +352,20 @@ S32 main(S32 argc, const char **argv)
 
 #include "app/mainLoop.h"
 
-S32 PASCAL WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, S32)
+S32 WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, S32)
 {
    Vector<char *> argv( __FILE__, __LINE__ );
 
-   char moduleName[256];
+   enum { moduleNameSize = 256 };
+   char moduleName[moduleNameSize];
 #ifdef TORQUE_UNICODE
    {
-      TCHAR buf[ 256 ];
-      GetModuleFileNameW( NULL, buf, sizeof( buf ) );
-      convertUTF16toUTF8( buf, moduleName, sizeof( moduleName ) );
+      TCHAR buf[ moduleNameSize ];
+      GetModuleFileNameW( NULL, buf, moduleNameSize );
+      convertUTF16toUTF8( buf, moduleName, moduleNameSize );
    }
 #else
-   GetModuleFileNameA(NULL, moduleName, sizeof(moduleName));
+   GetModuleFileNameA(NULL, moduleName, moduleNameSize);
 #endif
    argv.push_back(moduleName);
 
@@ -433,15 +434,16 @@ S32 torque_winmain( HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, S32)
 {
 	Vector<char *> argv( __FILE__, __LINE__ );
 
-	char moduleName[256];
+   enum { moduleNameSize = 256 };
+   char moduleName[moduleNameSize];
 #ifdef TORQUE_UNICODE
-	{
-		TCHAR buf[ 256 ];
-		GetModuleFileNameW( NULL, buf, sizeof( buf ) );
-		convertUTF16toUTF8( buf, moduleName, sizeof( moduleName ) );
-}
+   {
+      TCHAR buf[ moduleNameSize ];
+      GetModuleFileNameW( NULL, buf, moduleNameSize );
+      convertUTF16toUTF8( buf, moduleName, moduleNameSize );
+   }
 #else
-	GetModuleFileNameA(NULL, moduleName, sizeof(moduleName));
+   GetModuleFileNameA(NULL, moduleName, moduleNameSize);
 #endif
 	argv.push_back(moduleName);
 
@@ -657,4 +659,4 @@ DefineConsoleFunction( isKoreanBuild, bool, ( ), , "isKoreanBuild()")
    }
 
    return( result );
-}
+}

+ 2 - 1
Engine/source/scene/reflectionManager.cpp

@@ -83,7 +83,8 @@ F32 ReflectionManager::smRefractTexScale = 0.5f;
 
 ReflectionManager::ReflectionManager() 
  : mUpdateRefract( true ),
-   mReflectFormat( GFXFormatR8G8B8A8 )
+   mReflectFormat( GFXFormatR8G8B8A8 ),
+   mLastUpdateMs( 0 )
 {
    mTimer = PlatformTimer::create();
 

+ 2 - 0
Engine/source/scene/reflector.cpp

@@ -179,6 +179,8 @@ ReflectorBase::ReflectorBase()
    mObject = NULL;
    mOcclusionQuery = GFX->createOcclusionQuery();
    mQueryPending = false;
+   score = 0.0f;
+   lastUpdateMs = 0;
 }
 
 ReflectorBase::~ReflectorBase()

+ 2 - 1
Engine/source/sfx/openal/sfxALDevice.cpp

@@ -35,7 +35,8 @@ SFXALDevice::SFXALDevice(  SFXProvider *provider,
    :  Parent( name, provider, useHardware, maxBuffers ),
       mOpenAL( openal ), 
       mDevice( NULL ), 
-      mContext( NULL )
+      mContext( NULL ),
+      mRolloffFactor( 1.0f )
 {
    mMaxBuffers = getMax( maxBuffers, 8 );
 

+ 1 - 0
Engine/source/sim/netConnection.cpp

@@ -351,6 +351,7 @@ void NetConnection::setNetClassGroup(U32 grp)
 }
 
 NetConnection::NetConnection()
+ : mNetAddress()
 {
    mTranslateStrings = false;
    mConnectSequence = 0;

+ 1 - 2
Engine/source/ts/collada/colladaLights.cpp

@@ -129,8 +129,7 @@ static void processNodeLights(AppNode* appNode, const MatrixF& offset, SimGroup*
          Con::errorf(ConsoleLogEntry::General, "Failed to register light for \"%s\"", lightName.c_str());
          delete pLight;
       }
-
-      if (group)
+      else if (group)
          group->addObject(pLight);
    }
 

+ 4 - 1
Engine/source/util/settings.h

@@ -78,7 +78,10 @@ public:
    String mValue;
    bool mIsGroup;
 
-   SettingSaveNode(){};
+   SettingSaveNode()
+   {
+      mIsGroup = false;
+   }
    SettingSaveNode(const String &name, bool isGroup = false)
    {
       mName = name;

+ 6 - 6
Engine/source/windowManager/platformWindow.h

@@ -98,17 +98,17 @@ protected:
    {
       mIsBackground = false; // This could be toggled to true to prefer performance.
       mMinimumSize.set(0,0);
-		mLockedSize.set(0,0);
-		mResizeLocked = false;
+      mLockedSize.set(0,0);
+      mResizeLocked = false;
       mEnableKeyboardTranslation = false;
       mEnableAccelerators = true;
       mCursorController = NULL;
-      // This controller maps window input (Mouse/Keyboard) to a generic input consumer
-      mWindowInputGenerator = new WindowInputGenerator( this );
       mSuppressReset = false;
-
       mOffscreenRender = false;
       mDisplayWindow = false;
+
+      // This controller maps window input (Mouse/Keyboard) to a generic input consumer
+      mWindowInputGenerator = new WindowInputGenerator( this );
    }
 
 public:
@@ -509,4 +509,4 @@ protected:
    virtual void _setFullscreen(const bool fullScreen) {};
 };
 
-#endif
+#endif