Merge pull request #1035 from bpay/memfixes

Memfixes
This commit is contained in:
Luis Anton Rebollo 2015-01-25 13:42:32 +01:00
commit 6492028bb2
26 changed files with 79 additions and 52 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -601,10 +601,13 @@ bool chompUTF8BOM( const char *inString, char **outStringPtr )
{ {
*outStringPtr = const_cast<char *>( inString ); *outStringPtr = const_cast<char *>( inString );
U8 bom[4]; bool valid = false;
dMemcpy( bom, inString, 4 ); if (inString[0] && inString[1] && inString[2])
{
bool valid = isValidUTF8BOM( bom ); 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. // 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 // The only valid BOM is a UTF8 BOM, which is 3 bytes, even though we read

View file

@ -495,7 +495,7 @@ DefineConsoleFunction( dumpStringMemStats, void, (), , "()"
void* String::StringData::operator new( size_t size, U32 len ) void* String::StringData::operator new( size_t size, U32 len )
{ {
AssertFatal( len != 0, "String::StringData::operator new() - string must not be empty" ); 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; 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 ) void* String::StringData::operator new( size_t size, U32 len, DataChunker& chunker )
{ {
AssertFatal( len != 0, "String::StringData::operator new() - string must not be empty" ); 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; str->mLength = len;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -49,7 +49,7 @@ bool getDllName(std::wstring& dllName, const std::wstring suffix)
return true; 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. // Try to find the game DLL, which may have one of several file names.
HMODULE hGame = NULL; HMODULE hGame = NULL;
@ -75,10 +75,11 @@ int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdL
return -1; return -1;
} }
enum { errorSize = 4096 };
if (!hGame) if (!hGame)
{ {
wchar_t error[4096]; wchar_t error[errorSize];
_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()); _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); MessageBoxW(NULL, error, L"Error", MB_OK|MB_ICONWARNING);
return -1; 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"); torque_winmain = (int (*)(HINSTANCE hInstance, HINSTANCE h, LPSTR lpszCmdLine, int nShow))GetProcAddress(hGame, "torque_winmain");
if (!torque_winmain) if (!torque_winmain)
{ {
wchar_t error[4096]; wchar_t error[errorSize];
_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()); _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); MessageBoxW(NULL, error, L"Error", MB_OK|MB_ICONWARNING);
return -1; return -1;
} }

View file

@ -263,8 +263,6 @@ void MaterialList::clearMatInstList()
if (mMatInstList[i]) if (mMatInstList[i])
{ {
BaseMatInstance* current = mMatInstList[i]; BaseMatInstance* current = mMatInstList[i];
delete current;
mMatInstList[i] = NULL;
// ok, since ts material lists can remap difference indexes to the same object // 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 // 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++) for (U32 j=0; j<mMatInstList.size(); j++)
if (mMatInstList[j] == current) if (mMatInstList[j] == current)
mMatInstList[j] = NULL; mMatInstList[j] = NULL;
mMatInstList[i] = NULL;
delete current;
} }
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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()); Con::errorf(ConsoleLogEntry::General, "Failed to register light for \"%s\"", lightName.c_str());
delete pLight; delete pLight;
} }
else if (group)
if (group)
group->addObject(pLight); group->addObject(pLight);
} }

View file

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

View file

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