From 3dddc5ab4062b89c55cfbf6c35eb456a7fc54ff6 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 24 Oct 2020 03:57:15 +0800 Subject: [PATCH 1/7] Move ucstring utf8 implementation to header --- nel/include/nel/misc/ucstring.h | 132 +-------------------------- nel/src/misc/ucstring.cpp | 152 ++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+), 129 deletions(-) create mode 100644 nel/src/misc/ucstring.cpp diff --git a/nel/include/nel/misc/ucstring.h b/nel/include/nel/misc/ucstring.h index b3dc1294f..8cedb04ec 100644 --- a/nel/include/nel/misc/ucstring.h +++ b/nel/include/nel/misc/ucstring.h @@ -149,43 +149,7 @@ public: } /// Convert this ucstring (16bits char) into a utf8 string - std::string toUtf8() const - { - std::string res; - ucstring::const_iterator first(begin()), last(end()); - for (; first != last; ++first) - { - //ucchar c = *first; - uint nbLoop = 0; - if (*first < 0x80) - res += char(*first); - else if (*first < 0x800) - { - ucchar c = *first; - c = c >> 6; - c = c & 0x1F; - res += char(c) | 0xC0; - nbLoop = 1; - } - else /*if (*first < 0x10000)*/ - { - ucchar c = *first; - c = c >> 12; - c = c & 0x0F; - res += char(c) | 0xE0; - nbLoop = 2; - } - - for (uint i=0; i> ((nbLoop - i - 1) * 6); - c = c & 0x3F; - res += char(c) | 0x80; - } - } - return res; - } + std::string toUtf8() const; ucstring substr(size_type pos = 0, size_type n = npos) const { @@ -199,86 +163,7 @@ public: } /// Convert the utf8 string into this ucstring (16 bits char) - void fromUtf8(const std::string &stringUtf8) - { - // clear the string - erase(); - - uint8 c; - ucchar code; - sint iterations = 0; - - std::string::const_iterator first(stringUtf8.begin()), last(stringUtf8.end()); - for (; first != last; ) - { - c = *first++; - code = c; - - if ((code & 0xFE) == 0xFC) - { - code &= 0x01; - iterations = 5; - } - else if ((code & 0xFC) == 0xF8) - { - code &= 0x03; - iterations = 4; - } - else if ((code & 0xF8) == 0xF0) - { - code &= 0x07; - iterations = 3; - } - else if ((code & 0xF0) == 0xE0) - { - code &= 0x0F; - iterations = 2; - } - else if ((code & 0xE0) == 0xC0) - { - code &= 0x1F; - iterations = 1; - } - else if ((code & 0x80) == 0x80) - { - // If it's not a valid UTF8 string, just copy the line without utf8 conversion - rawCopy(stringUtf8); - return; - } - else - { - push_back(code); - iterations = 0; - } - - if (iterations) - { - for (sint i = 0; i < iterations; i++) - { - if (first == last) - { - // If it's not a valid UTF8 string, just copy the line without utf8 conversion - rawCopy(stringUtf8); - return; - } - - uint8 ch; - ch = *first ++; - - if ((ch & 0xC0) != 0x80) - { - // If it's not a valid UTF8 string, just copy the line without utf8 conversion - rawCopy(stringUtf8); - return; - } - - code <<= 6; - code |= (ucchar)(ch & 0x3F); - } - push_back(code); - } - } - } + void fromUtf8(const std::string &stringUtf8); static ucstring makeFromUtf8(const std::string &stringUtf8) { @@ -289,19 +174,8 @@ public: } private: + void rawCopy(const std::string &str); - void rawCopy(const std::string &str) - { - // We need to convert the char into 8bits unsigned int before promotion to 16 bits - // otherwise, as char are signed on some compiler (MSCV for ex), the sign bit is extended to 16 bits. - resize(str.size()); - std::string::const_iterator first(str.begin()), last(str.end()); - iterator dest(begin()); - for (;first != last; ++first, ++dest) - { - *dest = uint8(*first); - } - } }; inline ucstring operator+(const ucstringbase &ucstr, ucchar c) diff --git a/nel/src/misc/ucstring.cpp b/nel/src/misc/ucstring.cpp new file mode 100644 index 000000000..5d7112114 --- /dev/null +++ b/nel/src/misc/ucstring.cpp @@ -0,0 +1,152 @@ +// NeL - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "stdmisc.h" +#include "nel/misc/ucstring.h" + +std::string ucstring::toUtf8() const +{ + std::string res; + ucstring::const_iterator first(begin()), last(end()); + for (; first != last; ++first) + { + //ucchar c = *first; + uint nbLoop = 0; + if (*first < 0x80) + res += char(*first); + else if (*first < 0x800) + { + ucchar c = *first; + c = c >> 6; + c = c & 0x1F; + res += char(c) | 0xC0; + nbLoop = 1; + } + else /*if (*first < 0x10000)*/ + { + ucchar c = *first; + c = c >> 12; + c = c & 0x0F; + res += char(c) | 0xE0; + nbLoop = 2; + } + + for (uint i=0; i> ((nbLoop - i - 1) * 6); + c = c & 0x3F; + res += char(c) | 0x80; + } + } + return res; +} + +void ucstring::fromUtf8(const std::string &stringUtf8) +{ + // clear the string + erase(); + + uint8 c; + ucchar code; + sint iterations = 0; + + std::string::const_iterator first(stringUtf8.begin()), last(stringUtf8.end()); + for (; first != last; ) + { + c = *first++; + code = c; + + if ((code & 0xFE) == 0xFC) + { + code &= 0x01; + iterations = 5; + } + else if ((code & 0xFC) == 0xF8) + { + code &= 0x03; + iterations = 4; + } + else if ((code & 0xF8) == 0xF0) + { + code &= 0x07; + iterations = 3; + } + else if ((code & 0xF0) == 0xE0) + { + code &= 0x0F; + iterations = 2; + } + else if ((code & 0xE0) == 0xC0) + { + code &= 0x1F; + iterations = 1; + } + else if ((code & 0x80) == 0x80) + { + // If it's not a valid UTF8 string, just copy the line without utf8 conversion + rawCopy(stringUtf8); + return; + } + else + { + push_back(code); + iterations = 0; + } + + if (iterations) + { + for (sint i = 0; i < iterations; i++) + { + if (first == last) + { + // If it's not a valid UTF8 string, just copy the line without utf8 conversion + rawCopy(stringUtf8); + return; + } + + uint8 ch; + ch = *first ++; + + if ((ch & 0xC0) != 0x80) + { + // If it's not a valid UTF8 string, just copy the line without utf8 conversion + rawCopy(stringUtf8); + return; + } + + code <<= 6; + code |= (ucchar)(ch & 0x3F); + } + push_back(code); + } + } +} + +void ucstring::rawCopy(const std::string &str) +{ + // We need to convert the char into 8bits unsigned int before promotion to 16 bits + // otherwise, as char are signed on some compiler (MSCV for ex), the sign bit is extended to 16 bits. + resize(str.size()); + std::string::const_iterator first(str.begin()), last(str.end()); + iterator dest(begin()); + for (;first != last; ++first, ++dest) + { + *dest = uint8(*first); + } +} + +/* end of file */ From 1300d5d4d4efd188ebfca26fb9cc31b8d6a388ce Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 24 Oct 2020 04:02:02 +0800 Subject: [PATCH 2/7] Move ucstring utf8 implementation to header --- nel/include/nel/misc/ucstring.h | 12 +----------- nel/src/misc/ucstring.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/nel/include/nel/misc/ucstring.h b/nel/include/nel/misc/ucstring.h index 8cedb04ec..5f0616d8f 100644 --- a/nel/include/nel/misc/ucstring.h +++ b/nel/include/nel/misc/ucstring.h @@ -128,17 +128,7 @@ public: } /// Converts the controlled ucstring to a string str - void toString (std::string &str) const - { - str.resize (size ()); - for (uint i = 0; i < str.size (); i++) - { - if (operator[](i) > 255) - str[i] = '?'; - else - str[i] = (char) operator[](i); - } - } + void toString(std::string &str) const; /// Converts the controlled ucstring and returns the resulting string std::string toString () const diff --git a/nel/src/misc/ucstring.cpp b/nel/src/misc/ucstring.cpp index 5d7112114..df8f52406 100644 --- a/nel/src/misc/ucstring.cpp +++ b/nel/src/misc/ucstring.cpp @@ -17,6 +17,18 @@ #include "stdmisc.h" #include "nel/misc/ucstring.h" +void ucstring::toString(std::string &str) const +{ + str.resize(size()); + for (uint i = 0; i < str.size (); i++) + { + if (operator[](i) > 255) + str[i] = '?'; + else + str[i] = (char) operator[](i); + } +} + std::string ucstring::toUtf8() const { std::string res; From dd281306178fa10451569341b60e6e62d1c9bbeb Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 24 Oct 2020 04:17:36 +0800 Subject: [PATCH 3/7] Format ucstring source --- nel/include/nel/misc/ucstring.h | 119 +++++++++++++++++--------------- nel/src/misc/ucstring.cpp | 16 ++--- 2 files changed, 70 insertions(+), 65 deletions(-) diff --git a/nel/include/nel/misc/ucstring.h b/nel/include/nel/misc/ucstring.h index 5f0616d8f..28afcdb9a 100644 --- a/nel/include/nel/misc/ucstring.h +++ b/nel/include/nel/misc/ucstring.h @@ -35,95 +35,98 @@ typedef std::basic_string ucstringbase; class ucstring : public ucstringbase { public: + ucstring() { } - ucstring () {} - - ucstring (const ucstringbase &str) : ucstringbase (str) {} + ucstring(const ucstringbase &str) + : ucstringbase(str) + { + } - ucstring (const std::string &str) : ucstringbase () + ucstring(const std::string &str) + : ucstringbase() { rawCopy(str); } - ~ucstring () {} + ~ucstring() { } - ucstring &operator= (ucchar c) + ucstring &operator=(ucchar c) { - resize (1); + resize(1); operator[](0) = c; return *this; } - ucstring &operator= (const char *str) + ucstring &operator=(const char *str) { - resize (strlen (str)); - for (uint i = 0; i < strlen (str); i++) + resize(strlen(str)); + for (uint i = 0; i < strlen(str); i++) { operator[](i) = uint8(str[i]); } return *this; } - ucstring &operator= (const std::string &str) + ucstring &operator=(const std::string &str) { - resize (str.size ()); - for (uint i = 0; i < str.size (); i++) + resize(str.size()); + for (uint i = 0; i < str.size(); i++) { operator[](i) = uint8(str[i]); } return *this; } - ucstring &operator= (const ucstringbase &str) + ucstring &operator=(const ucstringbase &str) { - ucstringbase::operator =(str); + ucstringbase::operator=(str); return *this; } - ucstring& operator= (const ucchar *str) + ucstring &operator=(const ucchar *str) { - ucstringbase::operator =(str); + ucstringbase::operator=(str); return *this; } - ucstring &operator+= (ucchar c) + ucstring &operator+=(ucchar c) { - resize (size() + 1); - operator[](size()-1) = c; + resize(size() + 1); + operator[](size() - 1) = c; return *this; } - ucstring &operator+= (const char *str) + ucstring &operator+=(const char *str) { size_t s = size(); - resize (s + strlen(str)); + resize(s + strlen(str)); for (uint i = 0; i < strlen(str); i++) { - operator[](s+i) = uint8(str[i]); + operator[](s + i) = uint8(str[i]); } return *this; } - ucstring &operator+= (const std::string &str) + ucstring &operator+=(const std::string &str) { size_t s = size(); - resize (s + str.size()); + resize(s + str.size()); for (uint i = 0; i < str.size(); i++) { - operator[](s+i) = uint8(str[i]); + operator[](s + i) = uint8(str[i]); } return *this; } - ucstring &operator+= (const ucstringbase &str) + ucstring &operator+=(const ucstringbase &str) { - ucstringbase::operator +=(str); + ucstringbase::operator+=(str); return *this; } const ucchar *c_str() const { const ucchar *tmp = ucstringbase::c_str(); - const_cast(tmp)[size()] = 0; + const_cast(tmp)[size()] = 0; return tmp; } @@ -131,7 +134,7 @@ public: void toString(std::string &str) const; /// Converts the controlled ucstring and returns the resulting string - std::string toString () const + std::string toString() const { std::string str; toString(str); @@ -165,70 +168,72 @@ public: private: void rawCopy(const std::string &str); - }; inline ucstring operator+(const ucstringbase &ucstr, ucchar c) { - ucstring ret; - ret= ucstr; - ret+= c; + ucstring ret; + ret = ucstr; + ret += c; return ret; } inline ucstring operator+(const ucstringbase &ucstr, const char *c) { - ucstring ret; - ret= ucstr; - ret+= c; + ucstring ret; + ret = ucstr; + ret += c; return ret; } inline ucstring operator+(const ucstringbase &ucstr, const std::string &c) { - ucstring ret; - ret= ucstr; - ret+= c; + ucstring ret; + ret = ucstr; + ret += c; return ret; } inline ucstring operator+(ucchar c, const ucstringbase &ucstr) { - ucstring ret; - ret= c; + ucstring ret; + ret = c; ret += ucstr; return ret; } inline ucstring operator+(const char *c, const ucstringbase &ucstr) { - ucstring ret; - ret= c; + ucstring ret; + ret = c; ret += ucstr; return ret; } inline ucstring operator+(const std::string &c, const ucstringbase &ucstr) { - ucstring ret; - ret= c; + ucstring ret; + ret = c; ret += ucstr; return ret; } -namespace NLMISC -{ +namespace NLMISC { // Traits for hash_map using CEntityId struct CUCStringHashMapTraits { - enum { bucket_size = 4, min_buckets = 8 }; + enum + { + bucket_size = 4, + min_buckets = 8 + }; CUCStringHashMapTraits() { } - size_t operator() (const ucstring &id ) const + size_t operator()(const ucstring &id) const { return id.size(); } - bool operator() (const ucstring &id1, const ucstring &id2) const + bool operator()(const ucstring &id1, const ucstring &id2) const { return id1 < id2; } @@ -239,18 +244,18 @@ struct CUCStringHashMapTraits * \param a string or a char to transform to lower case */ -ucstring toLower (const ucstring &str); -void toLower (ucchar *str); -ucchar toLower (ucchar c); +ucstring toLower(const ucstring &str); +void toLower(ucchar *str); +ucchar toLower(ucchar c); /** Convert an unicode string in upper case. * Characters with accent are converted in a uppercase character without accent * \param a string or a char to transform to upper case */ -ucstring toUpper (const ucstring &str); -void toUpper (ucchar *str); -ucchar toUpper (ucchar c); +ucstring toUpper(const ucstring &str); +void toUpper(ucchar *str); +ucchar toUpper(ucchar c); }; diff --git a/nel/src/misc/ucstring.cpp b/nel/src/misc/ucstring.cpp index df8f52406..8f81cbea1 100644 --- a/nel/src/misc/ucstring.cpp +++ b/nel/src/misc/ucstring.cpp @@ -20,18 +20,18 @@ void ucstring::toString(std::string &str) const { str.resize(size()); - for (uint i = 0; i < str.size (); i++) + for (uint i = 0; i < str.size(); i++) { if (operator[](i) > 255) str[i] = '?'; else - str[i] = (char) operator[](i); + str[i] = (char)operator[](i); } } std::string ucstring::toUtf8() const { - std::string res; + std::string res; ucstring::const_iterator first(begin()), last(end()); for (; first != last; ++first) { @@ -56,9 +56,9 @@ std::string ucstring::toUtf8() const nbLoop = 2; } - for (uint i=0; i> ((nbLoop - i - 1) * 6); c = c & 0x3F; res += char(c) | 0x80; @@ -77,7 +77,7 @@ void ucstring::fromUtf8(const std::string &stringUtf8) sint iterations = 0; std::string::const_iterator first(stringUtf8.begin()), last(stringUtf8.end()); - for (; first != last; ) + for (; first != last;) { c = *first++; code = c; @@ -131,7 +131,7 @@ void ucstring::fromUtf8(const std::string &stringUtf8) } uint8 ch; - ch = *first ++; + ch = *first++; if ((ch & 0xC0) != 0x80) { @@ -155,7 +155,7 @@ void ucstring::rawCopy(const std::string &str) resize(str.size()); std::string::const_iterator first(str.begin()), last(str.end()); iterator dest(begin()); - for (;first != last; ++first, ++dest) + for (; first != last; ++first, ++dest) { *dest = uint8(*first); } From 771248fcf4e021ba6e1fca9afd39f119de7bb6ca Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 24 Oct 2020 04:18:25 +0800 Subject: [PATCH 4/7] Use platform implementation in ucstring for UTF-8 conversion on Windows to get valid UTF-16 --- nel/include/nel/misc/stream.h | 7 +++++++ nel/include/nel/misc/types_nl.h | 4 ++++ nel/include/nel/misc/ucstring.h | 4 ++++ nel/src/misc/seven_zip.cpp | 4 ++-- nel/src/misc/string_common.cpp | 2 +- nel/src/misc/ucstring.cpp | 17 +++++++++++++++++ 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/nel/include/nel/misc/stream.h b/nel/include/nel/misc/stream.h index 89db78a1c..35b6c3f26 100644 --- a/nel/include/nel/misc/stream.h +++ b/nel/include/nel/misc/stream.h @@ -300,6 +300,13 @@ public: virtual void serial(bool &b) ; #ifndef NL_OS_CYGWIN virtual void serial(char &b) ; +#endif +#ifdef NL_OS_WINDOWS + inline void serial(wchar_t &b) + { + nlctassert(sizeof(wchar_t) == sizeof(uint16)); + serial(reinterpret_cast(b)); + } #endif virtual void serial(std::string &b) ; virtual void serial(ucstring &b) ; diff --git a/nel/include/nel/misc/types_nl.h b/nel/include/nel/misc/types_nl.h index 445882c34..73c05b3a5 100644 --- a/nel/include/nel/misc/types_nl.h +++ b/nel/include/nel/misc/types_nl.h @@ -546,7 +546,11 @@ template<> struct hash * \typedef ucchar * An Unicode character (16 bits) */ +#if defined(NL_OS_WINDOWS) +typedef wchar_t ucchar; +#else typedef uint16 ucchar; +#endif #ifndef NL_OVERRIDE #define NL_OVERRIDE override diff --git a/nel/include/nel/misc/ucstring.h b/nel/include/nel/misc/ucstring.h index 28afcdb9a..8859a21d9 100644 --- a/nel/include/nel/misc/ucstring.h +++ b/nel/include/nel/misc/ucstring.h @@ -30,7 +30,11 @@ * An unicode string class (16 bits per character). * Add features to convert and assign \c ucstring to \c string and \c string to \c ucstring. */ +#if defined(NL_OS_WINDOWS) +typedef std::wstring ucstringbase; +#else typedef std::basic_string ucstringbase; +#endif class ucstring : public ucstringbase { diff --git a/nel/src/misc/seven_zip.cpp b/nel/src/misc/seven_zip.cpp index ff226af7d..ad07bf3cc 100644 --- a/nel/src/misc/seven_zip.cpp +++ b/nel/src/misc/seven_zip.cpp @@ -172,8 +172,8 @@ bool unpack7Zip(const std::string &sevenZipFile, const std::string &destFileName filename.resize(nameLen); // write filename into ucstring - SzArEx_GetFileNameUtf16(&db, 0, &filename[0]); - + SzArEx_GetFileNameUtf16(&db, 0, reinterpret_cast(&filename[0])); + // write the extracted file FILE *outputHandle = nlfopen(destFileName, "wb+"); diff --git a/nel/src/misc/string_common.cpp b/nel/src/misc/string_common.cpp index a0fb40942..93122cc70 100644 --- a/nel/src/misc/string_common.cpp +++ b/nel/src/misc/string_common.cpp @@ -244,7 +244,7 @@ std::wstring utf8ToWide(const char *str, size_t len) #if defined(NL_OS_WINDOWS) return winCpToWide(str, len, CP_UTF8); #else - // TODO: UTF-32 to UTF-8 + // TODO: UTF-8 to UTF-32 nlassert(false); #endif } diff --git a/nel/src/misc/ucstring.cpp b/nel/src/misc/ucstring.cpp index 8f81cbea1..5fad643ce 100644 --- a/nel/src/misc/ucstring.cpp +++ b/nel/src/misc/ucstring.cpp @@ -31,6 +31,12 @@ void ucstring::toString(std::string &str) const std::string ucstring::toUtf8() const { +#if defined(NL_OS_WINDOWS) + // Use OS implementation + nlctassert(sizeof(wchar_t) == sizeof(ucchar)); + nlctassert(sizeof(wchar_t) == sizeof(uint16)); + return NLMISC::wideToUtf8(static_cast(*this)); +#else std::string res; ucstring::const_iterator first(begin()), last(end()); for (; first != last; ++first) @@ -65,10 +71,20 @@ std::string ucstring::toUtf8() const } } return res; +#endif } void ucstring::fromUtf8(const std::string &stringUtf8) { +#if defined(NL_OS_WINDOWS) + // Use OS implementation + nlctassert(sizeof(wchar_t) == sizeof(ucchar)); + nlctassert(sizeof(wchar_t) == sizeof(uint16)); + nlctassert(sizeof(std::wstring) == sizeof(ucstring)); // These can be swapped on Windows + static_cast(*this) = nlmove(NLMISC::utf8ToWide(stringUtf8)); + if (stringUtf8.size() && !size()) + rawCopy(stringUtf8); +#else // clear the string erase(); @@ -146,6 +162,7 @@ void ucstring::fromUtf8(const std::string &stringUtf8) push_back(code); } } +#endif } void ucstring::rawCopy(const std::string &str) From 8be138931d8d14d5bb3c026cf839ce6412df92ef Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 24 Oct 2020 04:33:08 +0800 Subject: [PATCH 5/7] Fix pCB NULL --- ryzom/client/src/login.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ryzom/client/src/login.cpp b/ryzom/client/src/login.cpp index cb6117744..2da407ecb 100644 --- a/ryzom/client/src/login.cpp +++ b/ryzom/client/src/login.cpp @@ -1211,9 +1211,10 @@ void initShardDisplay() { CCtrlButton *pCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_SHARD ":s0:but")); if (pCB != NULL) + { pCB->setPushed(true); - CAHManager::getInstance()->runActionHandler (pCB->getActionOnLeftClick(), pCB, pCB->getParamsOnLeftClick()); - + CAHManager::getInstance()->runActionHandler(pCB->getActionOnLeftClick(), pCB, pCB->getParamsOnLeftClick()); + } } pList->invalidateCoords(); } From 0367e4f7c3adc0db9e762716f00d3dad334703c3 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 24 Oct 2020 04:35:18 +0800 Subject: [PATCH 6/7] Fix build warnings --- ryzom/common/src/game_share/visual_slot_manager.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ryzom/common/src/game_share/visual_slot_manager.h b/ryzom/common/src/game_share/visual_slot_manager.h index 4fd46cd81..135e729a8 100644 --- a/ryzom/common/src/game_share/visual_slot_manager.h +++ b/ryzom/common/src/game_share/visual_slot_manager.h @@ -53,7 +53,7 @@ public: static void releaseInstance(); public: - typedef struct + typedef struct TElement { uint32 Index; NLMISC::CSheetId SheetId; @@ -66,7 +66,7 @@ public: } } TElement; - typedef struct + typedef struct TElementList { // elements list for a visual slot. std::vector Element; From 9896eae64d55585ff6a94109c3736da5816eb0b8 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 24 Oct 2020 06:05:22 +0800 Subject: [PATCH 7/7] Fix build warnings --- .../3d/driver/direct3d/driver_direct3d.cpp | 2 +- .../driver_opengl_vertex_buffer_hard.cpp | 9 +- nel/src/3d/render_trav.cpp | 2 +- nel/src/3d/scene.cpp | 4 +- nel/src/3d/shadow_map_manager.cpp | 4 +- nel/src/3d/shape_bank.cpp | 3 +- nel/src/3d/surface_light_grid.cpp | 23 ++--- nel/src/3d/tessellation.cpp | 6 ++ nel/src/gui/group_header.cpp | 21 +++-- nel/src/logic/logic_state_machine.cpp | 2 +- nel/src/misc/big_file.cpp | 10 ++- nel/src/misc/bitmap.cpp | 2 +- nel/src/misc/cdb_branch.cpp | 2 +- nel/src/misc/debug.cpp | 2 + nel/src/misc/eval_num_expr.cpp | 6 +- nel/src/misc/i18n.cpp | 28 ++++--- nel/src/misc/mem_displayer.cpp | 2 + nel/src/misc/object_arena_allocator.cpp | 29 ++++--- nel/src/misc/path.cpp | 9 +- nel/src/misc/system_utils.cpp | 28 ++++--- nel/src/misc/win_thread.cpp | 2 +- ryzom/client/src/client_chat_manager.cpp | 10 ++- ryzom/client/src/continent.cpp | 1 + ryzom/client/src/forage_source_cl.cpp | 2 +- ryzom/client/src/fx_cl.cpp | 2 +- .../src/interface_v3/action_handler_game.cpp | 2 +- .../interface_v3/action_handler_phrase.cpp | 83 ++++++++++--------- .../interface_v3/dbgroup_list_sheet_trade.cpp | 2 +- .../src/interface_v3/interface_manager.cpp | 2 +- .../src/interface_v3/sphrase_manager.cpp | 11 ++- .../client/src/r2/displayer_visual_group.cpp | 2 +- .../src/r2/dmc/client_edition_module.cpp | 1 + ryzom/client/src/r2/editor.cpp | 2 +- ryzom/client/src/r2/prim_render.cpp | 2 +- ryzom/client/src/timed_fx_manager.cpp | 2 +- .../time_weather_season/weather_function.cpp | 2 +- 36 files changed, 181 insertions(+), 141 deletions(-) diff --git a/nel/src/3d/driver/direct3d/driver_direct3d.cpp b/nel/src/3d/driver/direct3d/driver_direct3d.cpp index 3a4f67aee..fc853602f 100644 --- a/nel/src/3d/driver/direct3d/driver_direct3d.cpp +++ b/nel/src/3d/driver/direct3d/driver_direct3d.cpp @@ -1173,7 +1173,7 @@ void D3DWndProc(CDriverD3D *driver, HWND hWnd, UINT message, WPARAM wParam, LPAR } } - if (driver->_EventEmitter.getNumEmitters() > 0) + if (driver && driver->_EventEmitter.getNumEmitters() > 0) { CWinEventEmitter *we = NLMISC::safe_cast(driver->_EventEmitter.getEmitter(0)); // Process the message by the emitter diff --git a/nel/src/3d/driver/opengl/driver_opengl_vertex_buffer_hard.cpp b/nel/src/3d/driver/opengl/driver_opengl_vertex_buffer_hard.cpp index 689c37ba5..8e539afd7 100644 --- a/nel/src/3d/driver/opengl/driver_opengl_vertex_buffer_hard.cpp +++ b/nel/src/3d/driver/opengl/driver_opengl_vertex_buffer_hard.cpp @@ -1373,10 +1373,11 @@ CVertexBufferHardARB::~CVertexBufferHardARB() } } #ifdef NL_DEBUG - if (_VertexPtr) - { - _VertexArrayRange->_MappedVBList.erase(_IteratorInMappedVBList); - } + if (_VertexPtr) + { + nlassert(_VertexArrayRange); + _VertexArrayRange->_MappedVBList.erase(_IteratorInMappedVBList); + } #endif #ifdef USE_OPENGLES diff --git a/nel/src/3d/render_trav.cpp b/nel/src/3d/render_trav.cpp index 0a071303f..355ceb7ab 100644 --- a/nel/src/3d/render_trav.cpp +++ b/nel/src/3d/render_trav.cpp @@ -921,7 +921,7 @@ void CRenderTrav::changeVPLightSetupMaterial(const CMaterial &mat, bool exclude Driver->setUniform4f(IDriver::VertexProgram, program->idxLighted().Diffuse[i], color); } - + nlassert(_VPNumLights < MaxVPLight); if (i != _VPNumLights) { color= _VPLightDiffuse[i] * matDiff; diff --git a/nel/src/3d/scene.cpp b/nel/src/3d/scene.cpp index 7f1263ea1..db8a629ff 100644 --- a/nel/src/3d/scene.cpp +++ b/nel/src/3d/scene.cpp @@ -775,9 +775,9 @@ CTransformShape *CScene::createInstance(const string &shapeName) // Look if this instance get lightmap information #if defined(__GNUC__) && __GNUC__ < 3 - CMeshBase *pMB = (CMeshBase*)((IShape*)(pTShp->Shape)); + CMeshBase *pMB = pTShp ? (CMeshBase*)((IShape*)(pTShp->Shape)) : NULL; #else // not GNUC - CMeshBase *pMB = dynamic_cast((IShape*)(pTShp->Shape)); + CMeshBase *pMB = pTShp ? dynamic_cast((IShape*)(pTShp->Shape)) : NULL; #endif // not GNUC CMeshBaseInstance *pMBI = dynamic_cast( pTShp ); if( ( pMB != NULL ) && ( pMBI != NULL ) ) diff --git a/nel/src/3d/shadow_map_manager.cpp b/nel/src/3d/shadow_map_manager.cpp index a8400ce0b..e6a7cfe50 100644 --- a/nel/src/3d/shadow_map_manager.cpp +++ b/nel/src/3d/shadow_map_manager.cpp @@ -256,14 +256,14 @@ void CShadowMapManager::renderGenerate(CScene *scene) garbageShadowTextures(scene); IDriver *driverForShadowGeneration= scene->getRenderTrav().getAuxDriver(); + nlassert(driverForShadowGeneration); CSmartPtr previousRenderTarget = driverForShadowGeneration->getRenderTarget(); // Init // ******** uint32 wndW= _BlurTextureW, wndH= _BlurTextureH; // get some text/screen size. - if(driverForShadowGeneration) - driverForShadowGeneration->getWindowSize(wndW, wndH); + driverForShadowGeneration->getWindowSize(wndW, wndH); uint baseTextureSize= scene->getShadowMapTextureSize(); // Minimize the Dest Texture size, so the blurTexture don't get too heavy in VRAM. uint32 textDestW= min(wndW, (uint32)NL3D_SMM_MAX_TEXTDEST_SIZE); diff --git a/nel/src/3d/shape_bank.cpp b/nel/src/3d/shape_bank.cpp index 61a65c423..a7c60cd03 100644 --- a/nel/src/3d/shape_bank.cpp +++ b/nel/src/3d/shape_bank.cpp @@ -683,8 +683,7 @@ void CShapeBank::reset() while( scmIt != ShapeCacheNameToShapeCache.end() ) { CShapeCache *pShpCache = getShapeCachePtrFromShapeCacheName( scmIt->first ); - if( pShpCache == NULL ) - nlstop; // Should never happen + nlassert(pShpCache); pShpCache->MaxSize = 0; checkShapeCache( pShpCache ); diff --git a/nel/src/3d/surface_light_grid.cpp b/nel/src/3d/surface_light_grid.cpp index deec090a4..b30abe730 100644 --- a/nel/src/3d/surface_light_grid.cpp +++ b/nel/src/3d/surface_light_grid.cpp @@ -121,17 +121,20 @@ void CSurfaceLightGrid::getStaticLightSetup(NLMISC::CRGBA sunAmbient, const CVe CLightInfluenceInterpolator::CCorner &corner= interp.Corners[y*2 + x]; // For all lights uint lid; - for(lid= 0; lid leave color and alpha To 0. - if(cellCorner.LocalAmbientId!=0xFF) + if(igPointLights && cellCorner.LocalAmbientId!=0xFF) { CPointLight &pl= igPointLights[cellCorner.LocalAmbientId]; // take current ambient from pointLight diff --git a/nel/src/3d/tessellation.cpp b/nel/src/3d/tessellation.cpp index 451e1013b..9dbc12296 100644 --- a/nel/src/3d/tessellation.cpp +++ b/nel/src/3d/tessellation.cpp @@ -2678,6 +2678,8 @@ void CTessFace::updateBindAndSplit() } else { + nlassert(f0); + nlassert(f1); // multipatch face case are detected when face->Patch==NULL !!! if(f0->FLeft && f0->FLeft->Patch==NULL) { @@ -2710,6 +2712,8 @@ void CTessFace::updateBindAndSplit() } else { + nlassert(f0); + nlassert(f1); if(f0->FLeft) { while(f0->FLeft->isLeaf()) @@ -2781,6 +2785,8 @@ void CTessFace::updateBindAndSplit() { CTessFace *f; sint i; + nlassert(f0); + nlassert(f1); // Same reasoning for rectangular patchs, as above. for(i=0;i<2;i++) diff --git a/nel/src/gui/group_header.cpp b/nel/src/gui/group_header.cpp index 03d688921..5fec1d4be 100644 --- a/nel/src/gui/group_header.cpp +++ b/nel/src/gui/group_header.cpp @@ -161,8 +161,14 @@ namespace NLGUI // ... limitingParent = limitingParent->getParent(); } - - getParentContainer()->setW(totalWidth + getParentContainer()->getWReal() - limitingParent->getWReal()); + if (limitingParent) + { + getParentContainer()->setW(totalWidth + getParentContainer()->getWReal() - limitingParent->getWReal()); + } + else + { + nlwarning("No limiting parent for width"); + } } // resize H @@ -178,9 +184,14 @@ namespace NLGUI CInterfaceGroup *limitingParent = colEnclosing->getParent(); while (limitingParent && (limitingParent->getResizeFromChildH() || dynamic_cast(limitingParent))) limitingParent = limitingParent->getParent(); - - nlassert(limitingParent); - getParentContainer()->setH(col->getH() + getParentContainer()->getHReal() - limitingParent->getHReal()); + if (limitingParent) + { + getParentContainer()->setH(col->getH() + getParentContainer()->getHReal() - limitingParent->getHReal()); + } + else + { + nlwarning("No limiting parent for height"); + } } } } diff --git a/nel/src/logic/logic_state_machine.cpp b/nel/src/logic/logic_state_machine.cpp index ff99255d2..3d55be849 100644 --- a/nel/src/logic/logic_state_machine.cpp +++ b/nel/src/logic/logic_state_machine.cpp @@ -50,7 +50,7 @@ void xmlCheckNodeName (xmlNodePtr &node, const char *nodeName) // Make an error message char tmp[512]; smprintf (tmp, 512, "LogicStateMachine STATE_MACHINE XML Syntax error in block line %d, node %s should be %s", - node ? (int)node->line:-1, node->name, nodeName); + node ? (int)node->line:-1, node ? (const char *)node->name : "NULL", nodeName); nlinfo (tmp); nlstop; diff --git a/nel/src/misc/big_file.cpp b/nel/src/misc/big_file.cpp index 9713610cb..f01bbf297 100644 --- a/nel/src/misc/big_file.cpp +++ b/nel/src/misc/big_file.cpp @@ -75,7 +75,7 @@ CBigFile::CHandleFile &CBigFile::CThreadFileArray::get(uint32 index) // if the vector is not allocated, allocate it (empty entries filled with NULL => not opened FILE* in this thread) if(index>=ptr->size()) { - ptr->resize(index+1); + ptr->resize((ptrdiff_t)index + 1); } return (*ptr)[index]; @@ -278,11 +278,13 @@ bool CBigFile::BNP::readHeader(FILE *file) } char sFileName[256]; - if (fread (sFileName, 1, nStringSize, file) != nStringSize) + if (nStringSize) { - return false; + if (fread(sFileName, 1, nStringSize, file) != nStringSize) + { + return false; + } } - sFileName[nStringSize] = 0; uint32 nFileSize2; diff --git a/nel/src/misc/bitmap.cpp b/nel/src/misc/bitmap.cpp index 015a9c4c4..967cc325e 100644 --- a/nel/src/misc/bitmap.cpp +++ b/nel/src/misc/bitmap.cpp @@ -4325,7 +4325,7 @@ void CBitmap::blend(CBitmap &Bm0, CBitmap &Bm1, uint16 factor, bool inputBitmapI else #endif //#ifdef NL_OS_WINDOWS { - uint8 *endPix = dest + (numPix << 2); + uint8 *endPix = dest + ((ptrdiff_t)numPix << 2); // no mmx version uint blendFact = (uint) factor; uint invblendFact = 256 - blendFact; diff --git a/nel/src/misc/cdb_branch.cpp b/nel/src/misc/cdb_branch.cpp index 5f5cea571..f3e4f7de5 100644 --- a/nel/src/misc/cdb_branch.cpp +++ b/nel/src/misc/cdb_branch.cpp @@ -215,7 +215,7 @@ void CCDBNodeBranch::init( xmlNodePtr node, IProgressCallback &progressCallBack, else { if (!_Nodes.empty()) - for ( _IdBits=1; _Nodes.size() > unsigned(1<<_IdBits) ; _IdBits++ ) {} + for ( _IdBits=1; _Nodes.size() > ((size_t)1 <<_IdBits) ; _IdBits++ ) {} else _IdBits = 0; } diff --git a/nel/src/misc/debug.cpp b/nel/src/misc/debug.cpp index 1f7cf38db..6a40d3b0b 100644 --- a/nel/src/misc/debug.cpp +++ b/nel/src/misc/debug.cpp @@ -807,6 +807,8 @@ public: DWORD symSize = 10000; PIMAGEHLP_SYMBOL sym = (PIMAGEHLP_SYMBOL) GlobalAlloc (GMEM_FIXED, symSize); + if (!sym) return str; + ::ZeroMemory (sym, symSize); sym->SizeOfStruct = symSize; sym->MaxNameLength = symSize - sizeof(IMAGEHLP_SYMBOL); diff --git a/nel/src/misc/eval_num_expr.cpp b/nel/src/misc/eval_num_expr.cpp index 52dce523f..5d19e22a1 100644 --- a/nel/src/misc/eval_num_expr.cpp +++ b/nel/src/misc/eval_num_expr.cpp @@ -773,7 +773,7 @@ CEvalNumExpr::TReturnState CEvalNumExpr::evalExpression (double &finalResult, TT case Exponent: { int exponent; - frexp( arg0, &exponent); + (void)frexp( arg0, &exponent); value = (double)exponent; } break; @@ -1032,13 +1032,13 @@ CEvalNumExpr::TReturnState CEvalNumExpr::evalExpression (double &finalResult, TT v0 -= v1; break; case ULeftShift: - v0 = (double)(((uint)floor (v0 + 0.5))<<((uint)floor (v1 + 0.5))); + v0 = (double)(uint)(((uint)floor (v0 + 0.5))<<((uint)floor (v1 + 0.5))); break; case URightShift: v0 = (double)(((uint)floor (v0 + 0.5))>>((uint)floor (v1 + 0.5))); break; case SLeftShift: - v0 = (double)(((sint)floor (v0 + 0.5))<<((sint)floor (v1 + 0.5))); + v0 = (double)(sint)(((sint)floor (v0 + 0.5))<<((sint)floor (v1 + 0.5))); break; case SRightShift: v0 = (double)(((sint)floor (v0 + 0.5))>>((sint)floor (v1 + 0.5))); diff --git a/nel/src/misc/i18n.cpp b/nel/src/misc/i18n.cpp index f692fd849..27a47c2e4 100644 --- a/nel/src/misc/i18n.cpp +++ b/nel/src/misc/i18n.cpp @@ -339,21 +339,25 @@ std::string CI18N::getSystemLanguageCode () typedef int (WINAPI* GetUserDefaultLocaleNamePtr)(LPWSTR lpLocaleName, int cchLocaleName); // get pointer on GetUserDefaultLocaleName, kernel32.dll is always in memory so no need to call LoadLibrary - GetUserDefaultLocaleNamePtr nlGetUserDefaultLocaleName = (GetUserDefaultLocaleNamePtr)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetUserDefaultLocaleName"); - - // only use it if found - if (nlGetUserDefaultLocaleName) + HMODULE hKernel32 = GetModuleHandleA("kernel32.dll"); + if (hKernel32) { - // get user locale - wchar_t buffer[LOCALE_NAME_MAX_LENGTH]; - sint res = nlGetUserDefaultLocaleName(buffer, LOCALE_NAME_MAX_LENGTH); + GetUserDefaultLocaleNamePtr nlGetUserDefaultLocaleName = (GetUserDefaultLocaleNamePtr)GetProcAddress(hKernel32, "GetUserDefaultLocaleName"); - // convert wide string to std::string - std::string lang = wideToUtf8(buffer); + // only use it if found + if (nlGetUserDefaultLocaleName) + { + // get user locale + wchar_t buffer[LOCALE_NAME_MAX_LENGTH]; + sint res = nlGetUserDefaultLocaleName(buffer, LOCALE_NAME_MAX_LENGTH); - // only keep 2 first characters - if (lang.size() > 1) - _SystemLanguageCode = lang.substr(0, 2); + // convert wide string to std::string + std::string lang = wideToUtf8(buffer); + + // only keep 2 first characters + if (lang.size() > 1) + _SystemLanguageCode = lang.substr(0, 2); + } } } #endif diff --git a/nel/src/misc/mem_displayer.cpp b/nel/src/misc/mem_displayer.cpp index 04e5c71dd..0250fc4c6 100644 --- a/nel/src/misc/mem_displayer.cpp +++ b/nel/src/misc/mem_displayer.cpp @@ -58,6 +58,8 @@ static string getFuncInfo (DWORD_TYPE funcAddr, DWORD_TYPE stackAddr) DWORD symSize = 10000; PIMAGEHLP_SYMBOL sym = (PIMAGEHLP_SYMBOL) GlobalAlloc (GMEM_FIXED, symSize); + if (!sym) return str; + ::ZeroMemory (sym, symSize); sym->SizeOfStruct = symSize; sym->MaxNameLength = symSize - sizeof(IMAGEHLP_SYMBOL); diff --git a/nel/src/misc/object_arena_allocator.cpp b/nel/src/misc/object_arena_allocator.cpp index bd00affc9..ba2c81148 100644 --- a/nel/src/misc/object_arena_allocator.cpp +++ b/nel/src/misc/object_arena_allocator.cpp @@ -60,22 +60,23 @@ CObjectArenaAllocator::~CObjectArenaAllocator() void *CObjectArenaAllocator::alloc(uint size) { #ifdef NL_DEBUG - if (_WantBreakOnAlloc) + if (_WantBreakOnAlloc) + { + if (_AllocID == _BreakAllocID) { - if (_AllocID == _BreakAllocID) - { - nlassert(0); - } + nlassert(0); } + } #endif if (size >= _MaxAllocSize) { // use standard allocator nlctassert(NL_DEFAULT_MEMORY_ALIGNMENT >= sizeof(uint)); - uint8 *block = (uint8 *)aligned_malloc(NL_DEFAULT_MEMORY_ALIGNMENT + size, NL_DEFAULT_MEMORY_ALIGNMENT); //new uint8[size + sizeof(uint)]; // an additionnal uint is needed to store size of block - if (!block) return NULL; + uint8 *block = (uint8 *)aligned_malloc(NL_DEFAULT_MEMORY_ALIGNMENT + (ptrdiff_t)size, NL_DEFAULT_MEMORY_ALIGNMENT); //new uint8[size + sizeof(uint)]; // an additionnal uint is needed to store size of block + if (!block) throw std::bad_alloc(); #ifdef NL_DEBUG - _MemBlockToAllocID[block] = _AllocID; + _MemBlockToAllocID[block] = _AllocID; + ++_AllocID; #endif *(uint *) block = size; return block + NL_DEFAULT_MEMORY_ALIGNMENT; @@ -87,16 +88,14 @@ void *CObjectArenaAllocator::alloc(uint size) _ObjectSizeToAllocator[entry] = new CFixedSizeAllocator(entry * _Granularity + NL_DEFAULT_MEMORY_ALIGNMENT, _MaxAllocSize / size); // an additionnal uint is needed to store size of block } void *block = _ObjectSizeToAllocator[entry]->alloc(); + if (!block) throw std::bad_alloc(); nlassert(((uintptr_t)block % NL_DEFAULT_MEMORY_ALIGNMENT) == 0); #ifdef NL_DEBUG - if (block) - { - _MemBlockToAllocID[block] = _AllocID; - } - ++_AllocID; + _MemBlockToAllocID[block] = _AllocID; + ++_AllocID; #endif - *(uint *) block = size; - return (void *) ((uint8 *) block + NL_DEFAULT_MEMORY_ALIGNMENT); + *(uint *)block = size; + return (void *)((uint8 *)block + NL_DEFAULT_MEMORY_ALIGNMENT); } // ***************************************************************************************************************** diff --git a/nel/src/misc/path.cpp b/nel/src/misc/path.cpp index cdc71c1eb..a2f817210 100644 --- a/nel/src/misc/path.cpp +++ b/nel/src/misc/path.cpp @@ -1341,10 +1341,13 @@ void CFileContainer::addSearchBigFile (const string &sBigFilename, bool recurse, fclose(Handle); return; } - if (fread (FileName, 1, nStringSize, Handle) != nStringSize) + if (nStringSize) { - fclose(Handle); - return; + if (fread(FileName, 1, nStringSize, Handle) != nStringSize) + { + fclose(Handle); + return; + } } FileName[nStringSize] = 0; uint32 nFileSize2; diff --git a/nel/src/misc/system_utils.cpp b/nel/src/misc/system_utils.cpp index 8e6a1feae..45da347bd 100644 --- a/nel/src/misc/system_utils.cpp +++ b/nel/src/misc/system_utils.cpp @@ -173,23 +173,25 @@ bool CSystemUtils::copyTextToClipboard(const ucstring &text) { // create a lock on this buffer void *hLock = GlobalLock(mem); + if (hLock) + { + // copy text to this buffer + if (isUnicode) + wcscpy((wchar_t *)hLock, (const wchar_t *)text.c_str()); + else + strcpy((char *)hLock, text.toString().c_str()); - // copy text to this buffer - if (isUnicode) - wcscpy((wchar_t*)hLock, (const wchar_t*)text.c_str()); - else - strcpy((char*)hLock, text.toString().c_str()); - - // unlock buffer - GlobalUnlock(mem); + // unlock buffer + GlobalUnlock(mem); - // empty clipboard - EmptyClipboard(); + // empty clipboard + EmptyClipboard(); - // set new data to clipboard in the right format - SetClipboardData(isUnicode ? CF_UNICODETEXT:CF_TEXT, mem); + // set new data to clipboard in the right format + SetClipboardData(isUnicode ? CF_UNICODETEXT : CF_TEXT, mem); - res = true; + res = true; + } } CloseClipboard(); diff --git a/nel/src/misc/win_thread.cpp b/nel/src/misc/win_thread.cpp index 0de191d55..c3624c161 100644 --- a/nel/src/misc/win_thread.cpp +++ b/nel/src/misc/win_thread.cpp @@ -209,11 +209,11 @@ void CWinThread::start () ThreadHandle = (void *) ::CreateThread (NULL, 0, ProxyFunc, this, 0, (DWORD *)&ThreadId); // nldebug("NLMISC: thread %x started for runnable '%x'", typeid( Runnable ).name()); // OutputDebugString(toString(NL_LOC_MSG " NLMISC: thread %x started for runnable '%s'\n", ThreadId, typeid( *Runnable ).name()).c_str()); - SetThreadPriorityBoost (ThreadHandle, TRUE); // FALSE == Enable Priority Boost if (ThreadHandle == NULL) { throw EThread ( "Cannot create new thread" ); } + SetThreadPriorityBoost (ThreadHandle, TRUE); // FALSE == Enable Priority Boost _SuspendCount = 0; } diff --git a/ryzom/client/src/client_chat_manager.cpp b/ryzom/client/src/client_chat_manager.cpp index 9d222a1b7..a61c21701 100644 --- a/ryzom/client/src/client_chat_manager.cpp +++ b/ryzom/client/src/client_chat_manager.cpp @@ -1230,11 +1230,13 @@ class CHandlerEnterTell : public IActionHandler { CGroupContainer *pGC = pCGW->createFreeTeller(receiver); if (pGC != NULL) - pGC->setActive(true); - CGroupEditBox *eb = dynamic_cast(pGC->getGroup("eb")); - if (eb) { - CWidgetManager::getInstance()->setCaptureKeyboard(eb); + pGC->setActive(true); + CGroupEditBox *eb = dynamic_cast(pGC->getGroup("eb")); + if (eb) + { + CWidgetManager::getInstance()->setCaptureKeyboard(eb); + } } } } diff --git a/ryzom/client/src/continent.cpp b/ryzom/client/src/continent.cpp index 03b9a1fce..6bd22741a 100644 --- a/ryzom/client/src/continent.cpp +++ b/ryzom/client/src/continent.cpp @@ -956,6 +956,7 @@ void CContinent::unselect() // Setup the Root scene. if (BackgroundIG) { + nlassert(SceneRoot); BackgroundIG->removeFromScene (*SceneRoot); SceneRoot->deleteInstanceGroup (BackgroundIG); BackgroundIG = NULL; diff --git a/ryzom/client/src/forage_source_cl.cpp b/ryzom/client/src/forage_source_cl.cpp index 4e673caaf..be41c0e75 100644 --- a/ryzom/client/src/forage_source_cl.cpp +++ b/ryzom/client/src/forage_source_cl.cpp @@ -101,7 +101,7 @@ bool CForageSourceCL::build( const CEntitySheet *sheet ) const CForageSourceSheet *forageSourceSheet = dynamic_cast(sheet); if ( ! forageSourceSheet ) { - nlwarning( "Bad sheet %s for forage source", sheet->Id.toString().c_str() ); + nlwarning( "Bad sheet %s for forage source", sheet ? sheet->Id.toString().c_str() : "NULL" ); return false; } if ( ! setFx( forageSourceSheet->FxFilename ) ) diff --git a/ryzom/client/src/fx_cl.cpp b/ryzom/client/src/fx_cl.cpp index e1f29fd77..aeb3ddcba 100644 --- a/ryzom/client/src/fx_cl.cpp +++ b/ryzom/client/src/fx_cl.cpp @@ -75,7 +75,7 @@ bool CFxCL::build( const CEntitySheet *sheet ) if ( (! _FXSheet) || (_FXSheet->PSList.empty()) ) { _BadBuild = true; - nlwarning( "Bad sheet %s for fx", sheet->Id.toString().c_str() ); + nlwarning( "Bad sheet %s for fx", sheet ? sheet->Id.toString().c_str() : "NULL" ); return false; } diff --git a/ryzom/client/src/interface_v3/action_handler_game.cpp b/ryzom/client/src/interface_v3/action_handler_game.cpp index 5af8485d6..bbb392131 100644 --- a/ryzom/client/src/interface_v3/action_handler_game.cpp +++ b/ryzom/client/src/interface_v3/action_handler_game.cpp @@ -1334,7 +1334,7 @@ class CSelectItemSheet : public IActionHandler // check if user has the level to use the item (applies to item & plans) if (ctrlSheet->getSheetCategory() == CDBCtrlSheet::Item) { - if (csg->getName() == "buy_selection") + if (csg && csg->getName() == "buy_selection") { const CItemSheet *is = ctrlSheet->asItemSheet(); if (is) diff --git a/ryzom/client/src/interface_v3/action_handler_phrase.cpp b/ryzom/client/src/interface_v3/action_handler_phrase.cpp index 8a94a4c16..dcc55f9ea 100644 --- a/ryzom/client/src/interface_v3/action_handler_phrase.cpp +++ b/ryzom/client/src/interface_v3/action_handler_phrase.cpp @@ -1191,57 +1191,60 @@ public: if( pPM->avoidCyclicForPhrase(phraseCom) ) cyclic= false; - // **** Launch the cast - // Cast only if their is a target, or if it is not a combat action - CEntityCL *target = EntitiesMngr.entity(UserEntity->targetSlot()); - if(target || !rootBrick->isCombat()) + if (UserEntity) { - // combat (may moveTo before) ? - if(rootBrick->isCombat()) + // **** Launch the cast + // Cast only if their is a target, or if it is not a combat action + CEntityCL *target = EntitiesMngr.entity(UserEntity->targetSlot()); + if (target || !rootBrick->isCombat()) { - if( !UserEntity->canEngageCombat() ) - return; + // combat (may moveTo before) ? + if (rootBrick->isCombat()) + { + if (!UserEntity->canEngageCombat()) + return; - UserEntity->executeCombatWithPhrase(target, memoryLine, memoryIndex, cyclic); - } - // else can cast soon! - else if ( rootBrick->isForageExtraction() && (! UserEntity->isRiding()) ) // if mounted, send directly to server (without moving) to receive the error message - { - // Yoyo: TEMP if a target selected, must be a forage source - if(!target || target->isForageSource()) + UserEntity->executeCombatWithPhrase(target, memoryLine, memoryIndex, cyclic); + } + // else can cast soon! + else if (rootBrick->isForageExtraction() && (!UserEntity->isRiding())) // if mounted, send directly to server (without moving) to receive the error message + { + // Yoyo: TEMP if a target selected, must be a forage source + if (!target || target->isForageSource()) + { + // Cancel any follow + UserEntity->disableFollow(); + // reset any moveTo also (if target==NULL, moveToExtractionPhrase() and therefore resetAnyMoveTo() not called) + // VERY important if previous MoveTo was a SPhrase MoveTo (because cancelClientExecute() must be called) + UserEntity->resetAnyMoveTo(); + + // Move to targetted source + if (target) + UserEntity->moveToExtractionPhrase(target->slot(), MaxExtractionDistance, memoryLine, memoryIndex, cyclic); + + // start client execution + pPM->clientExecute(memoryLine, memoryIndex, cyclic); + + if (!target) + { + // inform Server of phrase cast + pPM->sendExecuteToServer(memoryLine, memoryIndex, cyclic); + } + } + } + else { - // Cancel any follow - UserEntity->disableFollow(); - // reset any moveTo also (if target==NULL, moveToExtractionPhrase() and therefore resetAnyMoveTo() not called) + // Cancel any moveTo(), because don't want to continue reaching the prec entity // VERY important if previous MoveTo was a SPhrase MoveTo (because cancelClientExecute() must be called) UserEntity->resetAnyMoveTo(); - // Move to targetted source - if ( target ) - UserEntity->moveToExtractionPhrase( target->slot(), MaxExtractionDistance, memoryLine, memoryIndex, cyclic ); - - // start client execution + // start client execution: NB: start client execution even if it pPM->clientExecute(memoryLine, memoryIndex, cyclic); - if ( ! target ) - { - // inform Server of phrase cast - pPM->sendExecuteToServer(memoryLine, memoryIndex, cyclic); - } + // inform Server of phrase cast + pPM->sendExecuteToServer(memoryLine, memoryIndex, cyclic); } } - else - { - // Cancel any moveTo(), because don't want to continue reaching the prec entity - // VERY important if previous MoveTo was a SPhrase MoveTo (because cancelClientExecute() must be called) - UserEntity->resetAnyMoveTo(); - - // start client execution: NB: start client execution even if it - pPM->clientExecute(memoryLine, memoryIndex, cyclic); - - // inform Server of phrase cast - pPM->sendExecuteToServer(memoryLine, memoryIndex, cyclic); - } } } } diff --git a/ryzom/client/src/interface_v3/dbgroup_list_sheet_trade.cpp b/ryzom/client/src/interface_v3/dbgroup_list_sheet_trade.cpp index 4a7ef5701..ce7f2fcf5 100644 --- a/ryzom/client/src/interface_v3/dbgroup_list_sheet_trade.cpp +++ b/ryzom/client/src/interface_v3/dbgroup_list_sheet_trade.cpp @@ -475,7 +475,7 @@ bool CDBGroupListSheetTrade::CSheetChildTrade::isSheetValid(CDBGroupListSheetTex if ((pIS != NULL) && (!pIS->DropOrSell)) return false; // test if this whole family of items can be sold - if( !ITEMFAMILY::isSellableByPlayer(pIS->Family) ) + if((pIS != NULL) && !ITEMFAMILY::isSellableByPlayer(pIS->Family) ) return false; } diff --git a/ryzom/client/src/interface_v3/interface_manager.cpp b/ryzom/client/src/interface_v3/interface_manager.cpp index 23440218e..5737e50a0 100644 --- a/ryzom/client/src/interface_v3/interface_manager.cpp +++ b/ryzom/client/src/interface_v3/interface_manager.cpp @@ -2980,8 +2980,8 @@ void CInterfaceManager::log(const ucstring &str, const std::string &cat) { const string finalString = string(NLMISC::IDisplayer::dateToHumanString()) + " (" + NLMISC::toUpper(cat) + ") * " + str.toUtf8(); fprintf(f, "%s\n", finalString.c_str()); + fclose(f); } - fclose(f); } } diff --git a/ryzom/client/src/interface_v3/sphrase_manager.cpp b/ryzom/client/src/interface_v3/sphrase_manager.cpp index 5ebf3eee9..dc605d11d 100644 --- a/ryzom/client/src/interface_v3/sphrase_manager.cpp +++ b/ryzom/client/src/interface_v3/sphrase_manager.cpp @@ -3576,13 +3576,12 @@ void CSPhraseManager::updatePhraseProgressionDB() break; } } - } - - // if show, but only if full learnt, skip it if not fully learnt - if(phrase->ShowInAPOnlyIfLearnt && !known) - { - continue; + // if show, but only if full learnt, skip it if not fully learnt + if (phrase->ShowInAPOnlyIfLearnt && !known) + { + continue; + } } diff --git a/ryzom/client/src/r2/displayer_visual_group.cpp b/ryzom/client/src/r2/displayer_visual_group.cpp index 05e120e66..0edc18880 100644 --- a/ryzom/client/src/r2/displayer_visual_group.cpp +++ b/ryzom/client/src/r2/displayer_visual_group.cpp @@ -98,7 +98,7 @@ protected: { CGroupMap *gm = CTool::getWorldMap(); if (!gm) dest = CVector::Null; - gm->worldToWindow(dest, src); + else gm->worldToWindow(dest, src); } }; diff --git a/ryzom/client/src/r2/dmc/client_edition_module.cpp b/ryzom/client/src/r2/dmc/client_edition_module.cpp index f58a9f669..6740dabfe 100644 --- a/ryzom/client/src/r2/dmc/client_edition_module.cpp +++ b/ryzom/client/src/r2/dmc/client_edition_module.cpp @@ -2227,6 +2227,7 @@ void CClientEditionModule::addToSaveList(const std::string& filename, const std: if (!ok) { delete sv; + return; } else { diff --git a/ryzom/client/src/r2/editor.cpp b/ryzom/client/src/r2/editor.cpp index 8e146e9ad..96b935e34 100644 --- a/ryzom/client/src/r2/editor.cpp +++ b/ryzom/client/src/r2/editor.cpp @@ -6302,7 +6302,7 @@ CInstance *CEditor::getInstanceUnderPos(float x, float y, float distSelection, b objectSelected= precInstanceUnderPos->getDisplayerVisual(); } - if (objectSelected->getSelectionType() == ISelectableObject::GroundProjected) + if (objectSelected && objectSelected->getSelectionType() == ISelectableObject::GroundProjected) { if (borderSelected && borderSelected != objectSelected) { diff --git a/ryzom/client/src/r2/prim_render.cpp b/ryzom/client/src/r2/prim_render.cpp index 59b05e1c4..f4b6cb8a9 100644 --- a/ryzom/client/src/r2/prim_render.cpp +++ b/ryzom/client/src/r2/prim_render.cpp @@ -202,7 +202,7 @@ CCtrlPolygon *CPrimRender::newCtrlPolygon() const { CGroupMap *gm = CTool::getWorldMap(); if (!gm) dest = CVector::Null; - gm->worldToWindow(dest, src); + else gm->worldToWindow(dest, src); } }; CViewBase::TCtorParam param; diff --git a/ryzom/client/src/timed_fx_manager.cpp b/ryzom/client/src/timed_fx_manager.cpp index b316f0ab5..6f46d6712 100644 --- a/ryzom/client/src/timed_fx_manager.cpp +++ b/ryzom/client/src/timed_fx_manager.cpp @@ -204,7 +204,7 @@ CTimedFXManager::TFXGroupHandle CTimedFXManager::add(const std::vector //sint32 debugDay; if (!(fi.FXSheet && fi.FXSheet->Mode == CSeasonFXSheet::AlwaysStarted)) { - if (fi.FXSheet->Mode == CSeasonFXSheet::Spawn) + if (fi.FXSheet && fi.FXSheet->Mode == CSeasonFXSheet::Spawn) { // compute next spawn date float cycleLength = fi.FXSheet ? fi.FXSheet->CycleDuration : _DayLength; diff --git a/ryzom/common/src/game_share/time_weather_season/weather_function.cpp b/ryzom/common/src/game_share/time_weather_season/weather_function.cpp index 02432142f..f62a5a244 100644 --- a/ryzom/common/src/game_share/time_weather_season/weather_function.cpp +++ b/ryzom/common/src/game_share/time_weather_season/weather_function.cpp @@ -37,7 +37,7 @@ CWeatherFunction::CWeatherFunction() void CWeatherFunction::buildFromSheet(const CWeatherFunctionSheet &sheet, const CWeatherManager &wm) { // copy common part of objects (parameters) - *static_cast(this) = *static_cast(&sheet); + static_cast(*this) = static_cast(sheet); // get pointer on the setup from their names _WeatherSetups.resize(sheet.SetupNames.size()); nlassert(sheet.SetupWeights.size() == sheet.SetupNames.size());