From 266a32ea1908644151658eec34f56db04cff3bf6 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 2 Jan 2016 19:14:13 +0100 Subject: [PATCH 1/5] Fixed: Implements launchProgramAndWaitForResult to launch a command synchronously --HG-- branch : develop --- code/nel/include/nel/misc/common.h | 4 ++ code/nel/src/misc/common.cpp | 84 ++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/code/nel/include/nel/misc/common.h b/code/nel/include/nel/misc/common.h index 10f6a97e6..028fc0b0d 100644 --- a/code/nel/include/nel/misc/common.h +++ b/code/nel/include/nel/misc/common.h @@ -349,6 +349,10 @@ std::string formatThousands(const std::string& s); /// The program will be launched in the current directory bool launchProgram (const std::string &programName, const std::string &arguments, bool log = true); +/// This function executes a program and wait for result (used for example for crash report). +/// The program will be launched in the current directory +sint launchProgramAndWaitForResult (const std::string &programName, const std::string &arguments, bool log = true); + /// This function executes a program and returns output as a string std::string getCommandOutput(const std::string &command); diff --git a/code/nel/src/misc/common.cpp b/code/nel/src/misc/common.cpp index 698f9d9ee..3f6a5c7b6 100644 --- a/code/nel/src/misc/common.cpp +++ b/code/nel/src/misc/common.cpp @@ -826,6 +826,90 @@ bool launchProgram(const std::string &programName, const std::string &arguments, return false; +sint launchProgramAndWaitForResult(const std::string &programName, const std::string &arguments, bool log) +{ + sint res = 0; + +#ifdef NL_OS_WINDOWS + STARTUPINFOA si; + PROCESS_INFORMATION pi; + + memset(&si, 0, sizeof(si)); + memset(&pi, 0, sizeof(pi)); + + si.cb = sizeof(si); + + // Enable nlassert/nlstop to display the error reason & callstack + const TCHAR *SE_TRANSLATOR_IN_MAIN_MODULE = _T("NEL_SE_TRANS"); + TCHAR envBuf [2]; + if ( GetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, envBuf, 2 ) != 0) + { + SetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, NULL ); + } + + string arg = " " + arguments; + BOOL ok = CreateProcessA(programName.c_str(), (char*)arg.c_str(), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW, NULL, NULL, &si, &pi); + + if (ok) + { + // Successfully created the process. Wait for it to finish. + WaitForSingleObject(pi.hProcess, INFINITE); + + // Get the exit code. + DWORD exitCode = 0; + ok = GetExitCodeProcess(pi.hProcess, &exitCode); + + //nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str()); + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + + if (ok) + { + res = (sint)exitCode; + } + else + { + if (log) + nlwarning("LAUNCH: Failed launched '%s' with arg '%s'", programName.c_str(), arguments.c_str()); + } + } + else + { + LPVOID lpMsgBuf; + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); + + if (log) + nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), GetLastError(), lpMsgBuf); + + LocalFree(lpMsgBuf); + + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + } +#else + // save LD_LIBRARY_PATH + const char *previousEnv = getenv("LD_LIBRARY_PATH"); + + // clear LD_LIBRARY_PATH to avoid problems with Steam Runtime + setenv("LD_LIBRARY_PATH", "", 1); + + // program name is the only required string + std::string command = programName; + + // only appends arguments if any + if (!arguments.empty()) command += " " + arguments; + + // execute the command + res = system(command.c_str()); + + // restore previous LD_LIBRARY_PATH + setenv("LD_LIBRARY_PATH", previousEnv, 1); + + if (res && log) + nlwarning ("LAUNCH: Failed launched '%s' with arg '%s' return code %d", programName.c_str(), arguments.c_str(), res); +#endif + + return res; } std::string getCommandOutput(const std::string &command) From 046c69066d6a21c7ccd37bb925880a3b3c72751d Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 2 Jan 2016 19:15:21 +0100 Subject: [PATCH 2/5] Fixed: Don't use system() under Windows, because it'll open a console window, use launchProgramAndWaitForResult instead --HG-- branch : develop --- code/nel/src/misc/report.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/nel/src/misc/report.cpp b/code/nel/src/misc/report.cpp index bad97c845..261ef4d5d 100644 --- a/code/nel/src/misc/report.cpp +++ b/code/nel/src/misc/report.cpp @@ -105,7 +105,6 @@ TReportResult report(const std::string &title, const std::string &subject, const && CFile::isExists(NL_CRASH_REPORT_TOOL)) { std::string params; - params += NL_CRASH_REPORT_TOOL; if (!reportPath.empty()) params += NLMISC::toString(" -log \"%s\"", reportPath.c_str()); @@ -131,7 +130,8 @@ TReportResult report(const std::string &title, const std::string &subject, const if (synchronous) { - TReportResult result = (TReportResult)::system(params.c_str()); + TReportResult result = (TReportResult)NLMISC::launchProgramAndWaitForResult(NL_CRASH_REPORT_TOOL, params); + if (result != ReportAlwaysIgnore && result != ReportIgnore && result != ReportAbort From b50ca03e92938c770cbacd44d6ad3e34fde69f95 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 2 Jan 2016 19:16:33 +0100 Subject: [PATCH 3/5] Fixed: Use --args only with open --HG-- branch : develop --- code/nel/src/misc/common.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/code/nel/src/misc/common.cpp b/code/nel/src/misc/common.cpp index 3f6a5c7b6..8ad3488f6 100644 --- a/code/nel/src/misc/common.cpp +++ b/code/nel/src/misc/common.cpp @@ -677,7 +677,6 @@ bool abortProgram(uint32 pid) bool launchProgram(const std::string &programName, const std::string &arguments, bool log) { - #ifdef NL_OS_WINDOWS STARTUPINFOA si; PROCESS_INFORMATION pi; @@ -723,16 +722,19 @@ bool launchProgram(const std::string &programName, const std::string &arguments, { // we need to open bundles with "open" command command = NLMISC::toString("open \"%s\"", programName.c_str()); + + // append arguments if any + if (!arguments.empty()) + { + command += NLMISC::toString(" --args %s", arguments.c_str()); + } } else { command = programName; - } - // append arguments if any - if (!arguments.empty()) - { - command += NLMISC::toString(" --args %s", arguments.c_str()); + // append arguments if any + if (!arguments.empty()) command += " " + arguments; } int res = system(command.c_str()); @@ -825,6 +827,7 @@ bool launchProgram(const std::string &programName, const std::string &arguments, #endif return false; +} sint launchProgramAndWaitForResult(const std::string &programName, const std::string &arguments, bool log) { From 844b1e3d02084c5fd2ce8a9522e05ea4b6c496a0 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 2 Jan 2016 19:19:39 +0100 Subject: [PATCH 4/5] Fixed: Warnings with GCC --HG-- branch : develop --- code/nel/tools/3d/lightmap_optimizer/main.cpp | 8 +++++++ code/nel/tools/3d/tga_2_dds/tga2dds.cpp | 24 +++++++++---------- code/ryzom/common/src/game_share/crypt.cpp | 10 ++++---- .../common/src/game_share/crypt_sha512.cpp | 4 ++-- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/code/nel/tools/3d/lightmap_optimizer/main.cpp b/code/nel/tools/3d/lightmap_optimizer/main.cpp index 3323cce40..f7e999799 100644 --- a/code/nel/tools/3d/lightmap_optimizer/main.cpp +++ b/code/nel/tools/3d/lightmap_optimizer/main.cpp @@ -920,6 +920,14 @@ int main(int nNbArg, char **ppArgs) const CMeshGeom *pMG = dynamic_cast(&pMeshML->getMeshGeom(m)); pVB = const_cast(&pMG->getVertexBuffer()); } + else + { + pVB = NULL; + } + + // to avoid a possible crash + if (!pVB) continue; + CVertexBufferReadWrite vba; pVB->lock (vba); diff --git a/code/nel/tools/3d/tga_2_dds/tga2dds.cpp b/code/nel/tools/3d/tga_2_dds/tga2dds.cpp index 6e235a3f1..f51e1aa04 100644 --- a/code/nel/tools/3d/tga_2_dds/tga2dds.cpp +++ b/code/nel/tools/3d/tga_2_dds/tga2dds.cpp @@ -360,24 +360,24 @@ void dividSize (CBitmap &bitmap) } const int bayerDiv8R[4][4] = { - 7, 3, 6, 2, - 1, 5, 0, 4, - 6, 2, 7, 3, - 0, 4, 1, 5, + { 7, 3, 6, 2 }, + { 1, 5, 0, 4 }, + { 6, 2, 7, 3 }, + { 0, 4, 1, 5 } }; const int bayerDiv8G[4][4] = { - 0, 4, 1, 5, - 6, 2, 7, 3, - 1, 5, 0, 4, - 7, 3, 6, 2, + { 0, 4, 1, 5 }, + { 6, 2, 7, 3 }, + { 1, 5, 0, 4 }, + { 7, 3, 6, 2 } }; const int bayerDiv8B[4][4] = { - 5, 1, 4, 0, - 3, 7, 2, 6, - 4, 0, 5, 1, - 2, 6, 3, 7, + { 5, 1, 4, 0 }, + { 3, 7, 2, 6 }, + { 4, 0, 5, 1 }, + { 2, 6, 3, 7 } }; // *************************************************************************** diff --git a/code/ryzom/common/src/game_share/crypt.cpp b/code/ryzom/common/src/game_share/crypt.cpp index 1750d5d20..05f66d87f 100644 --- a/code/ryzom/common/src/game_share/crypt.cpp +++ b/code/ryzom/common/src/game_share/crypt.cpp @@ -18,8 +18,8 @@ #include "crypt.h" -char * rz_crypt(register const char *key, register const char *setting, char *buf); -char *__crypt_sha512(const char *key, const char *setting, char *output); +std::string rz_crypt(register const char *key, register const char *setting, char *buf); +std::string __crypt_sha512(const char *key, const char *setting, char *output); // Crypts password using salt @@ -505,7 +505,7 @@ static char cryptresult[1+4+4+11+1]; /* encrypted result */ * Return a pointer to static data consisting of the "setting" * followed by an encryption produced by the "key" and "setting". */ -char * rz_crypt(register const char *key, register const char *setting, char *buf) { +std::string rz_crypt(register const char *key, register const char *setting, char *buf) { register char *encp; register long i; register int t; @@ -580,7 +580,7 @@ char * rz_crypt(register const char *key, register const char *setting, char *bu encp += salt_size; if (rz_des_cipher((char *)&constdatablock, (char *)&rsltblock, salt, num_iter)) - return (NULL); + return ""; /* * Encode the 64 cipher bits as 11 ascii characters. @@ -602,7 +602,7 @@ char * rz_crypt(register const char *key, register const char *setting, char *bu encp[3] = 0; - return (cryptresult); + return cryptresult; } diff --git a/code/ryzom/common/src/game_share/crypt_sha512.cpp b/code/ryzom/common/src/game_share/crypt_sha512.cpp index 70a142baa..77e514a3b 100644 --- a/code/ryzom/common/src/game_share/crypt_sha512.cpp +++ b/code/ryzom/common/src/game_share/crypt_sha512.cpp @@ -294,7 +294,7 @@ static char *sha512crypt(const char *key, const char *setting, char *output) /* DS = sha(repeat-salt) */ sha512_init(&ctx); - for (i = 0; i < 16 + md[0]; i++) + for (i = 0; i < 16u + md[0]; i++) sha512_update(&ctx, salt, slen); sha512_sum(&ctx, smd); @@ -373,7 +373,7 @@ static char *sha512crypt(const char *key, const char *setting, char *output) return output; } -char *__crypt_sha512(const char *key, const char *setting, char *output) +std::string __crypt_sha512(const char *key, const char *setting, char *output) { static const char testkey[] = "Xy01@#\x01\x02\x80\x7f\xff\r\n\x81\t !"; static const char testsetting[] = "$6$rounds=1234$abc0123456789$"; From 8087b76397bffa4245fe8ea9a80450bb8f0eb419 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 2 Jan 2016 20:29:24 +0100 Subject: [PATCH 5/5] Fixed: Load 8bits textures as grayscale instead of alpha in textures_optimizer --HG-- branch : develop --- code/nel/tools/3d/textures_optimizer/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/nel/tools/3d/textures_optimizer/main.cpp b/code/nel/tools/3d/textures_optimizer/main.cpp index 8ecffedab..022709444 100644 --- a/code/nel/tools/3d/textures_optimizer/main.cpp +++ b/code/nel/tools/3d/textures_optimizer/main.cpp @@ -131,6 +131,9 @@ int main(int argc, char **argv) NLMISC::CBitmap bitmap; + // all 8 bits textures are grayscale and not alpha + bitmap.loadGrayscaleAsAlpha(false); + uint8 depth = bitmap.load(input); // don't need file so close it