diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e8dcf39..217c6382 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,13 @@ if(PLASMA_TARGETS STREQUAL "Ethereal") add_definitions(-DSTREAM_LOGGER) endif(PLASMA_TARGETS STREQUAL "Ethereal") +option(USE_VLD "Build and link with Visual Leak Detector (MSVC only)" OFF) +if(USE_VLD) + add_definitions(-DUSE_VLD) + find_package(VLD REQUIRED) + include_directories(${VLD_INCLUDE_DIR}) +endif(USE_VLD) + include(TestBigEndian) test_big_endian(BIG_ENDIAN) if(BIG_ENDIAN) diff --git a/Sources/Plasma/Apps/plClient/CMakeLists.txt b/Sources/Plasma/Apps/plClient/CMakeLists.txt index 7dc62b88..b4a4b21f 100644 --- a/Sources/Plasma/Apps/plClient/CMakeLists.txt +++ b/Sources/Plasma/Apps/plClient/CMakeLists.txt @@ -178,6 +178,10 @@ if(Bink_SDK_AVAILABLE) target_link_libraries(plClient ${Bink_LIBRARIES}) endif() +if(USE_VLD) + target_link_libraries(plClient ${VLD_LIBRARY}) +endif() + if (WIN32) target_link_libraries(plClient Rpcrt4) target_link_libraries(plClient Version) diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index f1f29084..8ade8131 100644 --- a/Sources/Plasma/Apps/plClient/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/winmain.cpp @@ -945,6 +945,10 @@ static size_t CurlCallback(void *buffer, size_t size, size_t nmemb, void *param) void StatusCallback(void *param) { +#ifdef USE_VLD + VLDEnable(); +#endif + HWND hwnd = (HWND)param; const char *statusUrl = GetServerStatusUrl(); diff --git a/Sources/Plasma/Apps/plClientPatcher/CMakeLists.txt b/Sources/Plasma/Apps/plClientPatcher/CMakeLists.txt index 64c76ba0..10046d95 100644 --- a/Sources/Plasma/Apps/plClientPatcher/CMakeLists.txt +++ b/Sources/Plasma/Apps/plClientPatcher/CMakeLists.txt @@ -20,5 +20,9 @@ set(plClientPatcher_SOURCES add_library(plClientPatcher STATIC ${plClientPatcher_HEADERS} ${plClientPatcher_SOURCES}) target_link_libraries(plClientPatcher CoreLib plAudioCore plStatusLog) +if(USE_VLD) + target_link_libraries(plClientPatcher ${VLD_LIBRARY}) +endif() + source_group("Header Files" FILES ${plClientPatcher_HEADERS}) source_group("Source Files" FILES ${plClientPatcher_SOURCES}) diff --git a/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp b/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp index 5baa7017..5a80f1a8 100644 --- a/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp +++ b/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp @@ -264,6 +264,10 @@ static void NetErrorHandler (ENetProtocol protocol, ENetError error) { /* //============================================================================ static void WaitUruExitProc (void * param) { +#ifdef USE_VLD + VLDEnable(); +#endif + plLauncherInfo *info = (plLauncherInfo *) param; WaitForSingleObject(s_pi.hProcess, INFINITE); DWORD exitcode; @@ -539,6 +543,10 @@ static void ProcessManifestEntry (void * param, ENetError error) { //============================================================================ static void ProcessManifest (void * param) { +#ifdef USE_VLD + VLDEnable(); +#endif + wchar_t basePath[MAX_PATH]; char path[MAX_PATH]; AtomicAdd(&s_perf[kPerfThreadTaskCount], 1); @@ -885,6 +893,10 @@ void ShutdownAsyncCore () { //============================================================================ // param = URU_PreparationRequest void UruPrepProc (void * param) { +#ifdef USE_VLD + VLDEnable(); +#endif + s_running = true; plLauncherInfo *info = (plLauncherInfo *) param; @@ -952,6 +964,10 @@ void UruPrepProc (void * param) { //============================================================================ void PlayerStopProc (void * param) { +#ifdef USE_VLD + VLDEnable(); +#endif + s_running = false; plLauncherInfo *info = (plLauncherInfo *) param; //TerminateProcess(s_pi.hProcess, kExitCodeTerminated); @@ -960,6 +976,10 @@ void PlayerStopProc (void * param) { //============================================================================ void PlayerTerminateProc (void * param) { +#ifdef USE_VLD + VLDEnable(); +#endif + s_running = false; plLauncherInfo *info = (plLauncherInfo *) param; ShutdownAsyncCore(); @@ -968,6 +988,10 @@ void PlayerTerminateProc (void * param) { //============================================================================ void UruStartProc (void * param) { +#ifdef USE_VLD + VLDEnable(); +#endif + if(!s_running) return; diff --git a/Sources/Plasma/Apps/plCrashHandler/CMakeLists.txt b/Sources/Plasma/Apps/plCrashHandler/CMakeLists.txt index 541c72a3..06317621 100644 --- a/Sources/Plasma/Apps/plCrashHandler/CMakeLists.txt +++ b/Sources/Plasma/Apps/plCrashHandler/CMakeLists.txt @@ -15,7 +15,11 @@ target_link_libraries(plCrashHandler pfCrashHandler) target_link_libraries(plCrashHandler plFile) target_link_libraries(plCrashHandler pnProduct) +if(USE_VLD) + target_link_libraries(plCrashHandler ${VLD_LIBRARY}) +endif() + # Platform specific libs if(WIN32) - target_link_libraries(plCrashHandler Dbghelp) + target_link_libraries(plCrashHandler Dbghelp) endif(WIN32) diff --git a/Sources/Plasma/Apps/plFileEncrypt/CMakeLists.txt b/Sources/Plasma/Apps/plFileEncrypt/CMakeLists.txt index f19e9b79..792913c1 100644 --- a/Sources/Plasma/Apps/plFileEncrypt/CMakeLists.txt +++ b/Sources/Plasma/Apps/plFileEncrypt/CMakeLists.txt @@ -14,4 +14,8 @@ set(plFileEncrypt_SOURCES add_executable(plFileEncrypt ${plFileEncrypt_SOURCES}) target_link_libraries(plFileEncrypt CoreLib pnProduct plFile) +if(USE_VLD) + target_link_libraries(plFileEncrypt ${VLD_LIBRARY}) +endif() + source_group("Source Files" FILES ${plFileEncrypt_SOURCES}) diff --git a/Sources/Plasma/Apps/plFileSecure/CMakeLists.txt b/Sources/Plasma/Apps/plFileSecure/CMakeLists.txt index 23f278aa..ff319dd6 100644 --- a/Sources/Plasma/Apps/plFileSecure/CMakeLists.txt +++ b/Sources/Plasma/Apps/plFileSecure/CMakeLists.txt @@ -14,4 +14,8 @@ set(plFileSecure_SOURCES add_executable(plFileSecure ${plFileSecure_SOURCES}) target_link_libraries(plFileSecure CoreLib pnProduct plFile) +if(USE_VLD) + target_link_libraries(plFileSecure ${VLD_LIBRARY}) +endif() + source_group("Source Files" FILES ${plFileSecure_SOURCES}) diff --git a/Sources/Plasma/Apps/plMD5/CMakeLists.txt b/Sources/Plasma/Apps/plMD5/CMakeLists.txt index d83f7c46..68acab10 100644 --- a/Sources/Plasma/Apps/plMD5/CMakeLists.txt +++ b/Sources/Plasma/Apps/plMD5/CMakeLists.txt @@ -16,4 +16,8 @@ add_executable(plMD5 ${plMD5_SOURCES}) target_link_libraries(plMD5 CoreLib pnUtils pnProduct pnEncryption) target_link_libraries(plMD5 ${OPENSSL_LIBRARIES}) +if(USE_VLD) + target_link_libraries(plMD5 ${VLD_LIBRARY}) +endif() + source_group("Source Files" FILES ${plMD5_SOURCES}) diff --git a/Sources/Plasma/Apps/plPageInfo/CMakeLists.txt b/Sources/Plasma/Apps/plPageInfo/CMakeLists.txt index 0ff9e0ba..db469254 100644 --- a/Sources/Plasma/Apps/plPageInfo/CMakeLists.txt +++ b/Sources/Plasma/Apps/plPageInfo/CMakeLists.txt @@ -15,4 +15,8 @@ set(plPageInfo_SOURCES add_executable(plPageInfo ${plPageInfo_SOURCES}) target_link_libraries(plPageInfo CoreLib pnProduct plResMgr plAudioCore) +if(USE_VLD) + target_link_libraries(plPageInfo ${VLD_LIBRARY}) +endif() + source_group("Source Files" FILES ${plPageInfo_SOURCES}) diff --git a/Sources/Plasma/Apps/plPythonPack/CMakeLists.txt b/Sources/Plasma/Apps/plPythonPack/CMakeLists.txt index 6c170425..13b196ab 100644 --- a/Sources/Plasma/Apps/plPythonPack/CMakeLists.txt +++ b/Sources/Plasma/Apps/plPythonPack/CMakeLists.txt @@ -22,5 +22,9 @@ else() target_link_libraries(plPythonPack ${PYTHON_LIBRARY}) endif() +if(USE_VLD) + target_link_libraries(plPythonPack ${VLD_LIBRARY}) +endif() + source_group("Source Files" FILES ${plPythonPack_SOURCES}) source_group("Header Files" FILES ${plPythonPack_HEADERS}) diff --git a/Sources/Plasma/Apps/plSHA/CMakeLists.txt b/Sources/Plasma/Apps/plSHA/CMakeLists.txt index 54cce9fc..b1f37124 100644 --- a/Sources/Plasma/Apps/plSHA/CMakeLists.txt +++ b/Sources/Plasma/Apps/plSHA/CMakeLists.txt @@ -16,4 +16,8 @@ add_executable(plSHA ${plSHA_SOURCES}) target_link_libraries(plSHA CoreLib pnUtils pnProduct pnEncryption) target_link_libraries(plSHA ${OPENSSL_LIBRARIES}) +if(USE_VLD) + target_link_libraries(plSHA ${VLD_LIBRARY}) +endif() + source_group("Source Files" FILES ${plSHA_SOURCES}) diff --git a/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt b/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt index 4c8a955e..dfd2904e 100644 --- a/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt +++ b/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt @@ -65,6 +65,10 @@ target_link_libraries(plUruLauncher ws2_32) target_link_libraries(plUruLauncher rpcrt4) target_link_libraries(plUruLauncher comctl32) +if(USE_VLD) + target_link_libraries(plUruLauncher ${VLD_LIBRARY}) +endif() + source_group("Source Files" FILES ${plUruLauncher_SOURCES}) source_group("Header Files" FILES ${plUruLauncher_HEADERS}) source_group("Resource Files" FILES ${plUruLauncher_RESOURCES}) diff --git a/Sources/Plasma/Apps/plUruLauncher/Main.cpp b/Sources/Plasma/Apps/plUruLauncher/Main.cpp index 654031fc..9095794d 100644 --- a/Sources/Plasma/Apps/plUruLauncher/Main.cpp +++ b/Sources/Plasma/Apps/plUruLauncher/Main.cpp @@ -431,6 +431,9 @@ BOOL CALLBACK SplashDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l //============================================================================ static void WindowThreadProc(void *) { +#ifdef USE_VLD + VLDEnable(); +#endif InitCommonControls(); s_event = CreateEvent( @@ -476,6 +479,10 @@ static size_t CurlCallback(void *buffer, size_t size, size_t nmemb, void *) //============================================================================ static void StatusCallback(void *) { +#ifdef USE_VLD + VLDEnable(); +#endif + const char *serverUrl = GetServerStatusUrl(); CURL * hCurl = curl_easy_init(); diff --git a/Sources/Plasma/CoreLib/HeadSpin.h b/Sources/Plasma/CoreLib/HeadSpin.h index 08dc423e..6a0a40df 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.h +++ b/Sources/Plasma/CoreLib/HeadSpin.h @@ -81,6 +81,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com # endif # include + // This needs to be after #include , since it also includes windows.h +# ifdef USE_VLD +# include +# endif + // Just some fun typedefs... typedef HWND hsWindowHndl; typedef HINSTANCE hsWindowInst; diff --git a/Sources/Plasma/CoreLib/hsThread_Win.cpp b/Sources/Plasma/CoreLib/hsThread_Win.cpp index 388022f7..bbb27eca 100644 --- a/Sources/Plasma/CoreLib/hsThread_Win.cpp +++ b/Sources/Plasma/CoreLib/hsThread_Win.cpp @@ -58,6 +58,11 @@ struct WinThreadParam static unsigned int __stdcall gEntryPointBT(void* param) { +#ifdef USE_VLD + // Needs to be enabled for each thread except the WinMain + VLDEnable(); +#endif + WinThreadParam* wtp = (WinThreadParam*)param; unsigned int result = wtp->fThread->Run(); ::ReleaseSemaphore(wtp->fQuitSemaH, 1, nil); // signal that we've quit diff --git a/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCmd.cpp b/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCmd.cpp index ae72bcf0..d7949a9a 100644 --- a/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCmd.cpp +++ b/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCmd.cpp @@ -395,8 +395,7 @@ pfConsoleCmd::~pfConsoleCmd() for( i = 0; i < fSigLabels.GetCount(); i++ ) { - if( fSigLabels[ i ] != nil ) - delete [] fSigLabels[ i ]; + delete [] fSigLabels[ i ]; } Unregister(); diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceThread.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceThread.cpp index f32ff6ed..bcf97cb8 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceThread.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceThread.cpp @@ -65,6 +65,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com //=========================================================================== static unsigned CALLBACK CreateThreadProc (LPVOID param) { + +#ifdef USE_VLD + VLDEnable(); +#endif + PerfAddCounter(kAsyncPerfThreadsTotal, 1); PerfAddCounter(kAsyncPerfThreadsCurr, 1); diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp index 184b1392..af55ba28 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp @@ -598,11 +598,10 @@ static void INetCliAuthAgeRequestCallback ( s_age.ageVaultId = ageVaultId; wchar_t ageInstIdStr[64]; - plString gameAddrStr = gameAddr.GetHostString(); LogMsg( kLogPerf, L"Connecting to game server %s, ageInstId %s", - gameAddrStr.c_str(), + gameAddr.GetHostString().ToWchar().GetData(), GuidToString(ageInstId, ageInstIdStr, arrsize(ageInstIdStr)) ); NetCliGameDisconnect(); diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index 0806a0cc..4a28fddb 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -2196,9 +2196,7 @@ static bool Recv_ServerAddr ( s_active->token = msg.token; s_active->addr.SetHost(msg.srvAddr); - plString logmsg = "SrvAuth addr: "; - logmsg += s_active->addr.GetHostString(); - LogMsg(kLogPerf, L"SrvAuth addr: %s", logmsg.c_str()); + LogMsg(kLogPerf, "SrvAuth addr: %s", s_active->addr.GetHostString().c_str()); } } s_critsect.Leave(); diff --git a/Sources/Tools/MaxMain/CMakeLists.txt b/Sources/Tools/MaxMain/CMakeLists.txt index 717a3122..2e53ed29 100644 --- a/Sources/Tools/MaxMain/CMakeLists.txt +++ b/Sources/Tools/MaxMain/CMakeLists.txt @@ -202,6 +202,10 @@ if (WIN32) target_link_libraries(MaxMain winmm) endif(WIN32) +if(USE_VLD) + target_link_libraries(MaxMain ${VLD_LIBRARY}) +endif() + source_group("Header Files" FILES ${MaxMain_HEADERS}) source_group("Resource Files" FILES ${MaxMain_RESOURCES}) source_group("Source Files" FILES ${MaxMain_SOURCES}) diff --git a/Sources/Tools/MaxPlasmaLights/CMakeLists.txt b/Sources/Tools/MaxPlasmaLights/CMakeLists.txt index 61a1e57e..bc2c5a08 100644 --- a/Sources/Tools/MaxPlasmaLights/CMakeLists.txt +++ b/Sources/Tools/MaxPlasmaLights/CMakeLists.txt @@ -130,6 +130,10 @@ if (WIN32) target_link_libraries(MaxPlasmaLights Ws2_32) endif(WIN32) +if(USE_VLD) + target_link_libraries(MaxPlasmaLights ${VLD_LIBRARY}) +endif() + source_group("Header Files" FILES ${MaxPlasmaLights_HEADERS}) source_group("Resource Files" FILES ${MaxPlasmaLights_RESOURCES}) source_group("Source Files" FILES ${MaxPlasmaLights_SOURCES}) diff --git a/Sources/Tools/plFontConverter/CMakeLists.txt b/Sources/Tools/plFontConverter/CMakeLists.txt index 5878f81b..b8a2d98f 100644 --- a/Sources/Tools/plFontConverter/CMakeLists.txt +++ b/Sources/Tools/plFontConverter/CMakeLists.txt @@ -45,6 +45,10 @@ if (WIN32) target_link_libraries(plFontConverter shlwapi) endif(WIN32) +if(USE_VLD) + target_link_libraries(plFontConverter ${VLD_LIBRARY}) +endif() + source_group("Source Files" FILES ${plFontConverter_SOURCES}) source_group("Header Files" FILES ${plFontConverter_HEADERS}) source_group("Resource Files" FILES ${plFontConverter_RESOURCES}) diff --git a/Sources/Tools/plLocalizationEditor/CMakeLists.txt b/Sources/Tools/plLocalizationEditor/CMakeLists.txt index 88428c37..2e231fd0 100644 --- a/Sources/Tools/plLocalizationEditor/CMakeLists.txt +++ b/Sources/Tools/plLocalizationEditor/CMakeLists.txt @@ -35,6 +35,10 @@ target_link_libraries(plLocalizationEditor pfLocalizationMgr) target_link_libraries(plLocalizationEditor ${EXPAT_LIBRARY}) target_link_libraries(plLocalizationEditor comctl32) +if(USE_VLD) + target_link_libraries(plLocalizationEditor ${VLD_LIBRARY}) +endif() + source_group("Source Files" FILES ${plLocalizationEditor_SOURCES}) source_group("Header Files" FILES ${plLocalizationEditor_HEADERS}) source_group("Resource Files" FILES ${plLocalizationEditor_RESOURCES}) diff --git a/Sources/Tools/plResBrowser/CMakeLists.txt b/Sources/Tools/plResBrowser/CMakeLists.txt index 2e7d4f23..252175a8 100644 --- a/Sources/Tools/plResBrowser/CMakeLists.txt +++ b/Sources/Tools/plResBrowser/CMakeLists.txt @@ -58,10 +58,14 @@ if (WIN32) target_link_libraries(plResBrowser Ws2_32) target_link_libraries(plResBrowser winmm) target_link_libraries(plResBrowser strmiids) - target_link_libraries(plResBrowser comctl32) - target_link_libraries(plResBrowser shlwapi) + target_link_libraries(plResBrowser comctl32) + target_link_libraries(plResBrowser shlwapi) endif(WIN32) +if(USE_VLD) + target_link_libraries(plResBrowser ${VLD_LIBRARY}) +endif() + source_group("Source Files" FILES ${plResBrowser_SOURCES}) source_group("Header Files" FILES ${plResBrowser_HEADERS}) source_group("Resource Files" FILES ${plResBrowser_RESOURCES}) diff --git a/cmake/FindVLD.cmake b/cmake/FindVLD.cmake new file mode 100644 index 00000000..5012e472 --- /dev/null +++ b/cmake/FindVLD.cmake @@ -0,0 +1,23 @@ +if(VLD_INCLUDE_DIR AND VLD_LIBRARY) + set(VLD_FIND_QUIETLY TRUE) +endif() + + +find_path(VLD_INCLUDE_DIR vld.h) +find_library(VLD_LIBRARY NAMES vld) +set(VLD_LIBRARIES ${VLD_LIBRARY}) + + +if(VLD_INCLUDE_DIR AND VLD_LIBRARY) + set(VLD_FOUND TRUE) +endif() + +if (VLD_FOUND) + if(NOT VLD_FIND_QUIETLY) + message(STATUS "Found Visual Leak Detector: ${VLD_INCLUDE_DIR}") + endif() +else() + if(VLD_FIND_REQUIRED) + message(FATAL_ERROR "Could not find Visual Leak Detector") + endif() +endif()