Browse Source

Merge pull request #511 from zrax/exception_cleanup

Exception stuff
Adam Johnson 9 years ago
parent
commit
f1dfd4750c
  1. 10
      Sources/Plasma/Apps/plPageOptimizer/main.cpp
  2. 2
      Sources/Plasma/CoreLib/CMakeLists.txt
  3. 16
      Sources/Plasma/CoreLib/HeadSpin.h
  4. 22
      Sources/Plasma/CoreLib/hsExceptions.cpp
  5. 78
      Sources/Plasma/CoreLib/hsExceptions.h
  6. 51
      Sources/Plasma/CoreLib/hsMemory.cpp
  7. 5
      Sources/Plasma/CoreLib/hsMemory.h
  8. 14
      Sources/Plasma/CoreLib/plString.cpp
  9. 120
      Sources/Plasma/CoreLib/plString.h
  10. 6
      Sources/Plasma/PubUtilLib/plAudio/plEAXEffects.cpp
  11. 8
      Sources/Plasma/PubUtilLib/plAvatar/plAvBrainHuman.cpp
  12. 6
      Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h
  13. 13
      Sources/Plasma/PubUtilLib/plGImage/plFont.cpp
  14. 18
      Sources/Plasma/PubUtilLib/plGImage/plJPEG.cpp
  15. 14
      Sources/Plasma/PubUtilLib/plGImage/plPNG.cpp
  16. 4
      Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h
  17. 12
      Sources/Plasma/PubUtilLib/plSDL/plSDLMgr.cpp
  18. 14
      Sources/Plasma/PubUtilLib/plSDL/plStateDataRecord.cpp
  19. 2
      Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.h
  20. 6
      Sources/Tools/plFontConverter/plFontConverter.cpp
  21. 2
      Sources/Tools/plLocalizationEditor/plAddDlgs.cpp
  22. 5
      Sources/Tools/plResBrowser/plResBrowser.h
  23. 20
      cmake/CompilerChecks.cmake
  24. 7
      cmake/check_noexcept.cpp
  25. 26
      cmake/check_override.cpp
  26. 2
      cmake/hsCompilerSpecific.h.cmake

10
Sources/Plasma/Apps/plPageOptimizer/main.cpp

@ -61,6 +61,9 @@ int main(int argc, char* argv[])
plResManager* resMgr = new plResManager; plResManager* resMgr = new plResManager;
hsgResMgr::Init(resMgr); hsgResMgr::Init(resMgr);
#ifndef _DEBUG #ifndef _DEBUG
} catch (std::exception &e) {
printf(" ***crashed on init: %s\n", e.what());
return 2;
} catch (...) { } catch (...) {
puts(" ***crashed on init"); puts(" ***crashed on init");
return 2; return 2;
@ -75,6 +78,10 @@ int main(int argc, char* argv[])
optimizer.Optimize(); optimizer.Optimize();
} }
#ifndef _DEBUG #ifndef _DEBUG
catch (std::exception &e) {
printf(" ***crashed on optimizing: %s\n", e.what());
return 2;
}
catch (...) { catch (...) {
puts(" ***crashed on optimizing"); puts(" ***crashed on optimizing");
return 2; return 2;
@ -92,6 +99,9 @@ int main(int argc, char* argv[])
hsgResMgr::Shutdown(); hsgResMgr::Shutdown();
#ifndef _DEBUG #ifndef _DEBUG
} catch (std::exception &e) {
printf(" ***crashed on shutdown: %s\n", e.what());
return 2;
} catch (...) { } catch (...) {
puts(" ***crashed on shutdown"); puts(" ***crashed on shutdown");
return 2; return 2;

2
Sources/Plasma/CoreLib/CMakeLists.txt

@ -14,6 +14,7 @@ set(CoreLib_SOURCES
hsBounds.cpp hsBounds.cpp
hsCpuID.cpp hsCpuID.cpp
hsCritSect.cpp hsCritSect.cpp
hsExceptions.cpp
hsExceptionStack.cpp hsExceptionStack.cpp
hsFastMath.cpp hsFastMath.cpp
hsGeometry3.cpp hsGeometry3.cpp
@ -59,6 +60,7 @@ set(CoreLib_HEADERS
hsCpuID.h hsCpuID.h
hsCritSect.h hsCritSect.h
hsExceptions.h hsExceptions.h
hsExceptionStack.h
hsFastMath.h hsFastMath.h
hsGeometry3.h hsGeometry3.h
hsHashTable.h hsHashTable.h

16
Sources/Plasma/CoreLib/HeadSpin.h

@ -130,6 +130,22 @@ typedef int32_t hsError;
# define hsDeprecated(message) # define hsDeprecated(message)
#endif #endif
#ifdef HAVE_OVERRIDE
# define HS_OVERRIDE override
# define HS_FINAL final
#else
# define HS_OVERRIDE
# define HS_FINAL
#endif
#ifdef HAVE_NOEXCEPT
# define HS_NOEXCEPT noexcept
# define HS_NOEXCEPT_IF(cond) noexcept(cond)
#else
# define HS_NOEXCEPT throw()
# define HS_NOEXCEPT_IF(cond)
#endif
//====================================== //======================================
// Endian swap funcitions // Endian swap funcitions
//====================================== //======================================

22
Sources/Plasma/CoreLib/hsExceptions.cpp

@ -0,0 +1,22 @@
#include "hsExceptions.h"
#include <cstring>
hsException::hsException(hsErrorEnum error, long param) HS_NOEXCEPT
: fError(error), fParam(param)
{
static const char *kErrorNames[] = {
"kNo_hsError",
"kNilParam_hsError",
"kBadParam_hsError",
"kInternal_hsError",
"kOS_hsError"
};
static_assert(arrsize(kErrorNames) == hsErrorEnum_MAX,
"kErrorNames not in sync with hsErrorEnum");
if (fError >= 0 && fError < hsErrorEnum_MAX)
snprintf(fWhat, arrsize(fWhat), "%s (%ld)", kErrorNames[fError], fParam);
else
snprintf(fWhat, arrsize(fWhat), "Unknown hsException error %d (%ld)", fError, fParam);
}

78
Sources/Plasma/CoreLib/hsExceptions.h

@ -43,64 +43,52 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define hsExceptionDefined #define hsExceptionDefined
#include "HeadSpin.h" #include "HeadSpin.h"
#include <exception>
// #define HS_NO_EXCEPTIONS -- this will turn off execptions you might want
// to do it with -D or equivalent instead of here since who knows who includes this.
enum hsErrorEnum { enum hsErrorEnum {
kNo_hsError, kNo_hsError,
kBadAlloc_hsError,
kNilParam_hsError, kNilParam_hsError,
kBadParam_hsError, kBadParam_hsError,
kInternal_hsError, kInternal_hsError,
kOS_hsError kOS_hsError,
hsErrorEnum_MAX
}; };
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
class hsException { class hsException : public std::exception {
public: public:
hsErrorEnum fError; hsErrorEnum fError;
long fParam; long fParam;
char fWhat[64];
hsException(hsErrorEnum error, long param = 0) : fError(error), fParam(param) {} hsException(hsErrorEnum error, long param = 0) HS_NOEXCEPT;
}; const char *what() const HS_NOEXCEPT HS_OVERRIDE { return fWhat; }
class hsBadAllocException : public hsException {
public:
hsBadAllocException() : hsException(kBadAlloc_hsError) {}
}; };
class hsNilParamException : public hsException { class hsNilParamException : public hsException {
public: public:
hsNilParamException() : hsException(kNilParam_hsError) {} hsNilParamException() HS_NOEXCEPT : hsException(kNilParam_hsError) {}
}; };
class hsBadParamException : public hsException { class hsBadParamException : public hsException {
public: public:
hsBadParamException() : hsException(kBadParam_hsError) {} hsBadParamException() HS_NOEXCEPT : hsException(kBadParam_hsError) {}
}; };
class hsInternalException : public hsException { class hsInternalException : public hsException {
public: public:
hsInternalException() : hsException(kInternal_hsError) {} hsInternalException() HS_NOEXCEPT : hsException(kInternal_hsError) {}
}; };
class hsOSException : public hsException { class hsOSException : public hsException {
public: public:
hsOSException(long error) : hsException(kOS_hsError, error) {} hsOSException(long error) HS_NOEXCEPT : hsException(kOS_hsError, error) {}
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
#ifndef HS_NO_EXCEPTIONS
#define hsThrow(a) { hsAssert(0,#a); throw a; } #define hsThrow(a) { hsAssert(0,#a); throw a; }
#define hsCatch(a) catch (a)
#define hsCatch2(a,b) catch (a b)
#define hsTry try
inline void hsThrowIfNilParam(const void* p) inline void hsThrowIfNilParam(const void* p)
{ {
@ -165,48 +153,4 @@ inline void hsThrowIfFalse(bool condition, const char message[])
} }
} }
#else
#define hsThrow(a) {hsAssert(0,#a);}
#define hsCatch(a) if(0)
#define hsCatch2(a,b) if(0)
#define hsTry
inline void hsThrowIfNilParam(const void* p)
{
hsAssert(p!=nil,"hsThrowIfNilParam");
}
inline void hsThrowIfBadParam(bool trueIfBadParam)
{
hsAssert(!trueIfBadParam,"hsThrowIfBadParam");
}
inline void hsThrowIfOSErr(long osErr)
{
hsAssert(osErr==0,"hsThrowIfOSErr");
}
inline void hsThrowIfTrue(bool condition)
{
hsAssert(!condition,"hsThrowIfTrue");
}
inline void hsThrowIfFalse(bool condition)
{
hsAssert(condition,"hsThrowIfFalse");
}
inline void hsThrowIfTrue(bool condition, const char message[])
{
hsAssert(!condition,message);
}
inline void hsThrowIfFalse(bool condition, const char message[])
{
hsAssert(condition,message);
}
#endif
#endif #endif

51
Sources/Plasma/CoreLib/hsMemory.cpp

@ -110,44 +110,6 @@ void HSMemory::Clear(void* m, uint32_t byteLen)
////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////
#if 0
template <class T> T* hsSoftNew(T*& obj)
{
try {
obj = new T;
}
catch (...) {
obj = nil;
}
return obj;
}
inline template <class T> T* hsSoftNew(T*& obj, unsigned count)
{
try {
obj = new T[count];
}
catch (...) {
obj = nil;
}
return obj;
}
#endif
void* HSMemory::SoftNew(uint32_t size)
{
uint32_t* p;
hsTry {
p = new uint32_t[(size + 3) >> 2];
} hsCatch(...) {
p = nil;
}
return p;
}
//////////////////////////////////////////////////////////////////////////////////////
struct hsPrivateChunk { struct hsPrivateChunk {
hsPrivateChunk* fNext; hsPrivateChunk* fNext;
char* fAvailableAddr; char* fAvailableAddr;
@ -222,19 +184,6 @@ void* hsChunkAllocator::Allocate(uint32_t size, const void* data)
return addr; return addr;
} }
void* hsChunkAllocator::SoftAllocate(uint32_t size, const void* data)
{
void* addr;
hsTry {
addr = this->Allocate(size, data);
}
hsCatch(...) {
addr = nil;
}
return addr;
}
////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////
struct hsAppenderHead { struct hsAppenderHead {

5
Sources/Plasma/CoreLib/hsMemory.h

@ -56,8 +56,6 @@ public:
static void* New(uint32_t size); static void* New(uint32_t size);
static void Delete(void* block); static void Delete(void* block);
static void* Copy(uint32_t length, const void* source); static void* Copy(uint32_t length, const void* source);
static void* SoftNew(uint32_t size); // returns nil if can't allocate
}; };
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -110,8 +108,7 @@ public:
void Reset(); void Reset();
void SetChunkSize(uint32_t size); void SetChunkSize(uint32_t size);
void* Allocate(uint32_t size, const void* data = nil); // throws if fails void* Allocate(uint32_t size, const void* data = nil);
void* SoftAllocate(uint32_t size, const void* data = nil); // returns nil if fails
}; };
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////

14
Sources/Plasma/CoreLib/plString.cpp

@ -489,23 +489,23 @@ plUnicodeBuffer plString::GetUnicodeArray() const
return result; return result;
} }
int plString::ToInt(int base) const int plString::ToInt(int base) const HS_NOEXCEPT
{ {
return static_cast<int>(strtol(c_str(), nullptr, base)); return static_cast<int>(strtol(c_str(), nullptr, base));
} }
unsigned int plString::ToUInt(int base) const unsigned int plString::ToUInt(int base) const HS_NOEXCEPT
{ {
return static_cast<unsigned int>(strtoul(c_str(), nullptr, base)); return static_cast<unsigned int>(strtoul(c_str(), nullptr, base));
} }
float plString::ToFloat() const float plString::ToFloat() const HS_NOEXCEPT
{ {
// strtof is C99, which MS doesn't support... // strtof is C99, which MS doesn't support...
return (float)strtod(c_str(), nullptr); return (float)strtod(c_str(), nullptr);
} }
double plString::ToDouble() const double plString::ToDouble() const HS_NOEXCEPT
{ {
return strtod(c_str(), nullptr); return strtod(c_str(), nullptr);
} }
@ -550,7 +550,7 @@ plString plString::IFormat(const char *fmt, va_list vptr)
return plString::FromUtf8(buffer, chars); return plString::FromUtf8(buffer, chars);
} }
ssize_t plString::Find(char ch, CaseSensitivity sense) const ssize_t plString::Find(char ch, CaseSensitivity sense) const HS_NOEXCEPT
{ {
if (sense == kCaseSensitive) { if (sense == kCaseSensitive) {
const char *cp = strchr(c_str(), ch); const char *cp = strchr(c_str(), ch);
@ -566,7 +566,7 @@ ssize_t plString::Find(char ch, CaseSensitivity sense) const
} }
} }
ssize_t plString::FindLast(char ch, CaseSensitivity sense) const ssize_t plString::FindLast(char ch, CaseSensitivity sense) const HS_NOEXCEPT
{ {
if (IsEmpty()) if (IsEmpty())
return -1; return -1;
@ -586,7 +586,7 @@ ssize_t plString::FindLast(char ch, CaseSensitivity sense) const
} }
} }
ssize_t plString::Find(const char *str, CaseSensitivity sense) const ssize_t plString::Find(const char *str, CaseSensitivity sense) const HS_NOEXCEPT
{ {
if (!str || !str[0]) if (!str || !str[0])
return -1; return -1;

120
Sources/Plasma/CoreLib/plString.h

@ -95,11 +95,11 @@ private:
unsigned int fRefs; unsigned int fRefs;
const _Ch *fStringData; const _Ch *fStringData;
StringRef(const _Ch *data) StringRef(const _Ch *data) HS_NOEXCEPT
: fRefs(1), fStringData(data) { } : fRefs(1), fStringData(data) { }
inline void AddRef() { ++fRefs; } inline void AddRef() HS_NOEXCEPT { ++fRefs; }
inline void DecRef() inline void DecRef() HS_NOEXCEPT
{ {
if (--fRefs == 0) { if (--fRefs == 0) {
delete [] fStringData; delete [] fStringData;
@ -114,14 +114,14 @@ private:
}; };
size_t fSize; size_t fSize;
bool IHaveACow() const { return fSize >= SSO_CHARS; } bool IHaveACow() const HS_NOEXCEPT { return fSize >= SSO_CHARS; }
public: public:
/** Construct an empty string buffer. */ /** Construct an empty string buffer. */
plStringBuffer() : fSize(0) { memset(fShort, 0, sizeof(fShort)); } plStringBuffer() HS_NOEXCEPT : fSize(0) { memset(fShort, 0, sizeof(fShort)); }
/** Copy constructor - adds a reference to the copied buffer */ /** Copy constructor - adds a reference to the copied buffer */
plStringBuffer(const plStringBuffer<_Ch> &copy) : fSize(copy.fSize) plStringBuffer(const plStringBuffer<_Ch> &copy) HS_NOEXCEPT : fSize(copy.fSize)
{ {
memcpy(fShort, copy.fShort, sizeof(fShort)); memcpy(fShort, copy.fShort, sizeof(fShort));
if (IHaveACow()) if (IHaveACow())
@ -129,7 +129,7 @@ public:
} }
/** Move constructor */ /** Move constructor */
plStringBuffer(plStringBuffer<_Ch> &&move) : fSize(move.fSize) plStringBuffer(plStringBuffer<_Ch> &&move) HS_NOEXCEPT : fSize(move.fSize)
{ {
memcpy(fShort, move.fShort, sizeof(fShort)); memcpy(fShort, move.fShort, sizeof(fShort));
move.fSize = 0; move.fSize = 0;
@ -154,7 +154,7 @@ public:
/** Destructor. The ref-counted data will only be freed if no other /** Destructor. The ref-counted data will only be freed if no other
* string buffers still reference it. * string buffers still reference it.
*/ */
~plStringBuffer<_Ch>() ~plStringBuffer<_Ch>() HS_NOEXCEPT
{ {
if (IHaveACow()) if (IHaveACow())
fData->DecRef(); fData->DecRef();
@ -163,7 +163,7 @@ public:
/** Assignment operator. Changes the reference to point to the /** Assignment operator. Changes the reference to point to the
* buffer in \a copy. * buffer in \a copy.
*/ */
plStringBuffer<_Ch> &operator=(const plStringBuffer<_Ch> &copy) plStringBuffer<_Ch> &operator=(const plStringBuffer<_Ch> &copy) HS_NOEXCEPT
{ {
if (copy.IHaveACow()) if (copy.IHaveACow())
copy.fData->AddRef(); copy.fData->AddRef();
@ -176,7 +176,7 @@ public:
} }
/** Move assignment operator */ /** Move assignment operator */
plStringBuffer<_Ch> &operator=(plStringBuffer<_Ch> &&move) plStringBuffer<_Ch> &operator=(plStringBuffer<_Ch> &&move) HS_NOEXCEPT
{ {
if (IHaveACow()) if (IHaveACow())
fData->DecRef(); fData->DecRef();
@ -188,17 +188,17 @@ public:
} }
/** Returns a pointer to the referenced string buffer. */ /** Returns a pointer to the referenced string buffer. */
const _Ch *GetData() const { return IHaveACow() ? fData->fStringData : fShort; } const _Ch *GetData() const HS_NOEXCEPT { return IHaveACow() ? fData->fStringData : fShort; }
/** Returns the number of characters (not including the '\0') in the /** Returns the number of characters (not including the '\0') in the
* referenced string buffer. * referenced string buffer.
*/ */
size_t GetSize() const { return fSize; } size_t GetSize() const HS_NOEXCEPT { return fSize; }
/** Cast operator. This is a shortcut for not needing to call GetData on /** Cast operator. This is a shortcut for not needing to call GetData on
* buffer objects passed to methods or objects expecting a C-style string. * buffer objects passed to methods or objects expecting a C-style string.
*/ */
operator const _Ch *() const { return GetData(); } operator const _Ch *() const HS_NOEXCEPT { return GetData(); }
/** Create a writable buffer for \a size characters. /** Create a writable buffer for \a size characters.
* From Haxxia with love! This will release the current string buffer * From Haxxia with love! This will release the current string buffer
@ -266,7 +266,7 @@ public:
public: public:
/** Construct a valid, empty string. */ /** Construct a valid, empty string. */
plString() { } plString() HS_NOEXCEPT { }
/** Construct a string from a C-style string. /** Construct a string from a C-style string.
* \note This constructor expects the input to be UTF-8 encoded. For * \note This constructor expects the input to be UTF-8 encoded. For
@ -286,19 +286,19 @@ public:
plString(char (&literal)[_Sz]) { IConvertFromUtf8(literal, STRLEN_AUTO); } plString(char (&literal)[_Sz]) { IConvertFromUtf8(literal, STRLEN_AUTO); }
/** Copy constructor. */ /** Copy constructor. */
plString(const plString &copy) : fUtf8Buffer(copy.fUtf8Buffer) { } plString(const plString &copy) HS_NOEXCEPT : fUtf8Buffer(copy.fUtf8Buffer) { }
/** Move constructor. */ /** Move constructor. */
plString(plString &&move) : fUtf8Buffer(std::move(move.fUtf8Buffer)) { } plString(plString &&move) HS_NOEXCEPT : fUtf8Buffer(std::move(move.fUtf8Buffer)) { }
/** Copy constructor from plStringBuffer<char>. /** Copy constructor from plStringBuffer<char>.
* \note This constructor expects the input to be UTF-8 encoded. For * \note This constructor expects the input to be UTF-8 encoded. For
* conversion from ISO-8859-1 8-bit data, use FromIso8859_1(). * conversion from ISO-8859-1 8-bit data, use FromIso8859_1().
*/ */
plString(const plStringBuffer<char> &init) { operator=(init); } plString(const plStringBuffer<char> &init) HS_NOEXCEPT { operator=(init); }
/** Move constructor from plStringBuffer<char>. */ /** Move constructor from plStringBuffer<char>. */
plString(plStringBuffer<char> &&init) { operator=(std::move(init)); } plString(plStringBuffer<char> &&init) HS_NOEXCEPT { operator=(std::move(init)); }
/** Construct a string from expanded Unicode data. */ /** Construct a string from expanded Unicode data. */
plString(const plUnicodeBuffer &init) { IConvertFromUtf32(init.GetData(), init.GetSize()); } plString(const plUnicodeBuffer &init) { IConvertFromUtf32(init.GetData(), init.GetSize()); }
@ -315,10 +315,10 @@ public:
plString &operator=(char (&literal)[_Sz]) { IConvertFromUtf8(literal, STRLEN_AUTO); return *this; } plString &operator=(char (&literal)[_Sz]) { IConvertFromUtf8(literal, STRLEN_AUTO); return *this; }
/** Assignment operator. Same as plString(const plString &). */ /** Assignment operator. Same as plString(const plString &). */
plString &operator=(const plString &copy) { fUtf8Buffer = copy.fUtf8Buffer; return *this; } plString &operator=(const plString &copy) HS_NOEXCEPT { fUtf8Buffer = copy.fUtf8Buffer; return *this; }
/** Assignment operator. Same as plString(plString &&). */ /** Assignment operator. Same as plString(plString &&). */
plString &operator=(plString &&move) { fUtf8Buffer = std::move(move.fUtf8Buffer); return *this; } plString &operator=(plString &&move) HS_NOEXCEPT { fUtf8Buffer = std::move(move.fUtf8Buffer); return *this; }
/** Assignment operator. Same as plString(const plStringBuffer<char> &). */ /** Assignment operator. Same as plString(const plStringBuffer<char> &). */
plString &operator=(const plStringBuffer<char> &init); plString &operator=(const plStringBuffer<char> &init);
@ -384,17 +384,17 @@ public:
* expecting C-style string pointers. If this string is empty, returns * expecting C-style string pointers. If this string is empty, returns
* \a substitute instead. * \a substitute instead.
*/ */
const char *c_str(const char *substitute = "") const const char *c_str(const char *substitute = "") const HS_NOEXCEPT
{ return IsEmpty() ? substitute : fUtf8Buffer.GetData(); } { return IsEmpty() ? substitute : fUtf8Buffer.GetData(); }
/** Return the byte at position \a position. Note that this may be in /** Return the byte at position \a position. Note that this may be in
* the middle of a UTF-8 sequence -- if you want an actual Unicode * the middle of a UTF-8 sequence -- if you want an actual Unicode
* character, use the buffer returned from GetUnicodeArray() instead. * character, use the buffer returned from GetUnicodeArray() instead.
*/ */
char CharAt(size_t position) const { return c_str()[position]; } char CharAt(size_t position) const HS_NOEXCEPT { return c_str()[position]; }
/** Returns the internal UTF-8 data buffer object. */ /** Returns the internal UTF-8 data buffer object. */
plStringBuffer<char> ToUtf8() const { return fUtf8Buffer; } plStringBuffer<char> ToUtf8() const HS_NOEXCEPT { return fUtf8Buffer; }
/** Convert this string's data to a UTF-16 string buffer. */ /** Convert this string's data to a UTF-16 string buffer. */
plStringBuffer<uint16_t> ToUtf16() const; plStringBuffer<uint16_t> ToUtf16() const;
@ -421,10 +421,10 @@ public:
/** Returns the size in number of bytes (excluding the null-terminator) of /** Returns the size in number of bytes (excluding the null-terminator) of
* this string. * this string.
*/ */
size_t GetSize() const { return fUtf8Buffer.GetSize(); } size_t GetSize() const HS_NOEXCEPT { return fUtf8Buffer.GetSize(); }
/** Returns \c true if this string is empty (""). */ /** Returns \c true if this string is empty (""). */
bool IsEmpty() const { return fUtf8Buffer.GetSize() == 0; } bool IsEmpty() const HS_NOEXCEPT { return fUtf8Buffer.GetSize() == 0; }
/** Returns \c true if this string is "null". Currently, this is just /** Returns \c true if this string is "null". Currently, this is just
* a synonym for IsEmpty(), as plString makes no distinction between * a synonym for IsEmpty(), as plString makes no distinction between
@ -432,27 +432,27 @@ public:
* \todo Evaluate whether Plasma actually needs to distinguish between * \todo Evaluate whether Plasma actually needs to distinguish between
* empty and NULL strings. Ideally, only IsEmpty should be required. * empty and NULL strings. Ideally, only IsEmpty should be required.
*/ */
bool IsNull() const { return IsEmpty(); } bool IsNull() const HS_NOEXCEPT { return IsEmpty(); }
/** Convert the string data to an integer in base \a base. /** Convert the string data to an integer in base \a base.
* If base is set to 0, this function behaves like strtol, which checks * If base is set to 0, this function behaves like strtol, which checks
* for hex or octal prefixes (e.g. 0777 or 0x1234), and assumes base 10 * for hex or octal prefixes (e.g. 0777 or 0x1234), and assumes base 10
* if none are found. * if none are found.
*/ */
int ToInt(int base = 0) const; int ToInt(int base = 0) const HS_NOEXCEPT;
/** Convert the string to an unsigned integer in base \a base. /** Convert the string to an unsigned integer in base \a base.
* If base is set to 0, this function behaves like strtoul, which checks * If base is set to 0, this function behaves like strtoul, which checks
* for hex or octal prefixes (e.g. 0777 or 0x1234), and assumes base 10 * for hex or octal prefixes (e.g. 0777 or 0x1234), and assumes base 10
* if none are found. * if none are found.
*/ */
unsigned int ToUInt(int base = 0) const; unsigned int ToUInt(int base = 0) const HS_NOEXCEPT;
/** Convert the string to a floating point value. */ /** Convert the string to a floating point value. */
float ToFloat() const; float ToFloat() const HS_NOEXCEPT;
/** Convert the string to a double precision floating point value. */ /** Convert the string to a double precision floating point value. */
double ToDouble() const; double ToDouble() const HS_NOEXCEPT;
/** Construct a plString using a printf-like format string. /** Construct a plString using a printf-like format string.
* This function should be called inside of other vararg functions, * This function should be called inside of other vararg functions,
@ -470,7 +470,7 @@ public:
* \li \p \<0 - this string is lexicographically less than \a str * \li \p \<0 - this string is lexicographically less than \a str
* \li \p \>0 - this string is lexicographically greater than \a str * \li \p \>0 - this string is lexicographically greater than \a str
*/ */
int Compare(const plString &str, CaseSensitivity sense = kCaseSensitive) const int Compare(const plString &str, CaseSensitivity sense = kCaseSensitive) const HS_NOEXCEPT
{ {
return (sense == kCaseSensitive) ? strcmp(c_str(), str.c_str()) return (sense == kCaseSensitive) ? strcmp(c_str(), str.c_str())
: stricmp(c_str(), str.c_str()); : stricmp(c_str(), str.c_str());
@ -482,7 +482,7 @@ public:
* \li \p \<0 - this string is lexicographically less than \a str * \li \p \<0 - this string is lexicographically less than \a str
* \li \p \>0 - this string is lexicographically greater than \a str * \li \p \>0 - this string is lexicographically greater than \a str
*/ */
int Compare(const char *str, CaseSensitivity sense = kCaseSensitive) const int Compare(const char *str, CaseSensitivity sense = kCaseSensitive) const HS_NOEXCEPT
{ {
return (sense == kCaseSensitive) ? strcmp(c_str(), str ? str : "") return (sense == kCaseSensitive) ? strcmp(c_str(), str ? str : "")
: stricmp(c_str(), str ? str : ""); : stricmp(c_str(), str ? str : "");
@ -492,7 +492,7 @@ public:
* string with \a str. * string with \a str.
* \sa Compare(const plString &, CaseSensitivity) const * \sa Compare(const plString &, CaseSensitivity) const
*/ */
int CompareN(const plString &str, size_t count, CaseSensitivity sense = kCaseSensitive) const int CompareN(const plString &str, size_t count, CaseSensitivity sense = kCaseSensitive) const HS_NOEXCEPT
{ {
return (sense == kCaseSensitive) ? strncmp(c_str(), str.c_str(), count) return (sense == kCaseSensitive) ? strncmp(c_str(), str.c_str(), count)
: strnicmp(c_str(), str.c_str(), count); : strnicmp(c_str(), str.c_str(), count);
@ -502,58 +502,58 @@ public:
* string with \a str. * string with \a str.
* \sa Compare(const char *, CaseSensitivity) const * \sa Compare(const char *, CaseSensitivity) const
*/ */
int CompareN(const char *str, size_t count, CaseSensitivity sense = kCaseSensitive) const int CompareN(const char *str, size_t count, CaseSensitivity sense = kCaseSensitive) const HS_NOEXCEPT
{ {
return (sense == kCaseSensitive) ? strncmp(c_str(), str ? str : "", count) return (sense == kCaseSensitive) ? strncmp(c_str(), str ? str : "", count)
: strnicmp(c_str(), str ? str : "", count); : strnicmp(c_str(), str ? str : "", count);
} }
/** Shortcut for Compare(str, kCaseInsensitive). */ /** Shortcut for Compare(str, kCaseInsensitive). */
int CompareI(const plString &str) const { return Compare(str, kCaseInsensitive); } int CompareI(const plString &str) const HS_NOEXCEPT { return Compare(str, kCaseInsensitive); }
/** Shortcut for Compare(str, kCaseInsensitive). */ /** Shortcut for Compare(str, kCaseInsensitive). */
int CompareI(const char *str) const { return Compare(str, kCaseInsensitive); } int CompareI(const char *str) const HS_NOEXCEPT { return Compare(str, kCaseInsensitive); }
/** Shortcut for CompareN(str, kCaseInsensitive). */ /** Shortcut for CompareN(str, kCaseInsensitive). */
int CompareNI(const plString &str, size_t count) const { return CompareN(str, count, kCaseInsensitive); } int CompareNI(const plString &str, size_t count) const HS_NOEXCEPT { return CompareN(str, count, kCaseInsensitive); }
/** Shortcut for CompareN(str, kCaseInsensitive). */ /** Shortcut for CompareN(str, kCaseInsensitive). */
int CompareNI(const char *str, size_t count) const { return CompareN(str, count, kCaseInsensitive); } int CompareNI(const char *str, size_t count) const HS_NOEXCEPT { return CompareN(str, count, kCaseInsensitive); }
/** Operator overload for use in containers which depend on \c std::less. */ /** Operator overload for use in containers which depend on \c std::less. */
bool operator<(const plString &other) const { return Compare(other) < 0; } bool operator<(const plString &other) const HS_NOEXCEPT { return Compare(other) < 0; }
/** Test if this string contains the same string data as \a other. */ /** Test if this string contains the same string data as \a other. */
bool operator==(const char *other) const { return Compare(other) == 0; } bool operator==(const char *other) const HS_NOEXCEPT { return Compare(other) == 0; }
/** Test if this string contains the same string data as \a other. */ /** Test if this string contains the same string data as \a other. */
bool operator==(const plString &other) const { return Compare(other) == 0; } bool operator==(const plString &other) const HS_NOEXCEPT { return Compare(other) == 0; }
/** Inverse of operator==(const char *) const. */ /** Inverse of operator==(const char *) const. */
bool operator!=(const char *other) const { return Compare(other) != 0; } bool operator!=(const char *other) const HS_NOEXCEPT { return Compare(other) != 0; }
/** Inverse of operator==(const plString &) const. */ /** Inverse of operator==(const plString &) const. */
bool operator!=(const plString &other) const { return Compare(other) != 0; } bool operator!=(const plString &other) const HS_NOEXCEPT { return Compare(other) != 0; }
/** Find the index (in bytes) of the first instance of \a ch in this string. /** Find the index (in bytes) of the first instance of \a ch in this string.
* \return -1 if the character was not found. * \return -1 if the character was not found.
*/ */
ssize_t Find(char ch, CaseSensitivity sense = kCaseSensitive) const; ssize_t Find(char ch, CaseSensitivity sense = kCaseSensitive) const HS_NOEXCEPT;
/** Find the index (in bytes) of the last instance of \a ch in this string. /** Find the index (in bytes) of the last instance of \a ch in this string.
* \return -1 if the character was not found. * \return -1 if the character was not found.
*/ */
ssize_t FindLast(char ch, CaseSensitivity sense = kCaseSensitive) const; ssize_t FindLast(char ch, CaseSensitivity sense = kCaseSensitive) const HS_NOEXCEPT;
/** Find the index (in bytes) of the first instance of \a str in this string. /** Find the index (in bytes) of the first instance of \a str in this string.
* \return -1 if the substring was not found. * \return -1 if the substring was not found.
*/ */
ssize_t Find(const char *str, CaseSensitivity sense = kCaseSensitive) const; ssize_t Find(const char *str, CaseSensitivity sense = kCaseSensitive) const HS_NOEXCEPT;
/** Find the index (in bytes) of the first instance of \a str in this string. /** Find the index (in bytes) of the first instance of \a str in this string.
* \return -1 if the substring was not found. * \return -1 if the substring was not found.
*/ */
ssize_t Find(const plString &str, CaseSensitivity sense = kCaseSensitive) const ssize_t Find(const plString &str, CaseSensitivity sense = kCaseSensitive) const HS_NOEXCEPT
{ return Find(str.c_str(), sense); } { return Find(str.c_str(), sense); }
/** Check that this string matches the specified regular expression. /** Check that this string matches the specified regular expression.
@ -645,7 +645,7 @@ public:
{ {
// TODO: This doesn't really use enough bits to be useful when // TODO: This doesn't really use enough bits to be useful when
// size_t is 64-bits. // size_t is 64-bits.
size_t operator()(const plString& str) const size_t operator()(const plString& str) const HS_NOEXCEPT
{ {
size_t hash = 0; size_t hash = 0;
for (size_t i = 0; i < str.GetSize(); ++i) { for (size_t i = 0; i < str.GetSize(); ++i) {
@ -660,7 +660,7 @@ public:
} }
protected: protected:
virtual char fetch_char(const plString& str, size_t index) const virtual char fetch_char(const plString& str, size_t index) const HS_NOEXCEPT
{ return str.CharAt(index); } { return str.CharAt(index); }
}; };
@ -670,21 +670,21 @@ public:
struct hash_i : public hash struct hash_i : public hash
{ {
protected: protected:
virtual char fetch_char(const plString& str, size_t index) const char fetch_char(const plString& str, size_t index) const HS_NOEXCEPT HS_FINAL HS_OVERRIDE
{ return tolower(str.CharAt(index)); } { return tolower(str.CharAt(index)); }
}; };
/** Functor which compares two strings case-insensitively for sorting. */ /** Functor which compares two strings case-insensitively for sorting. */
struct less_i struct less_i
{ {
bool operator()(const plString &_L, const plString &_R) const bool operator()(const plString &_L, const plString &_R) const HS_NOEXCEPT
{ return _L.Compare(_R, kCaseInsensitive) < 0; } { return _L.Compare(_R, kCaseInsensitive) < 0; }
}; };
/** Functor which compares two strings case-insensitively for equality. */ /** Functor which compares two strings case-insensitively for equality. */
struct equal_i struct equal_i
{ {
bool operator()(const plString &_L, const plString &_R) const bool operator()(const plString &_L, const plString &_R) const HS_NOEXCEPT
{ return _L.Compare(_R, kCaseInsensitive) == 0; } { return _L.Compare(_R, kCaseInsensitive) == 0; }
}; };
@ -715,16 +715,16 @@ public:
/** Construct a new empty string stream. The first STRING_STACK_SIZE /** Construct a new empty string stream. The first STRING_STACK_SIZE
* bytes are allocated on the stack for further efficiency. * bytes are allocated on the stack for further efficiency.
*/ */
plStringStream() : fBufSize(STRING_STACK_SIZE), fLength(0) { } plStringStream() HS_NOEXCEPT : fBufSize(STRING_STACK_SIZE), fLength(0) { }
/** Destructor, frees any allocated heap memory owned by the stream. */ /** Destructor, frees any allocated heap memory owned by the stream. */
~plStringStream() { if (ICanHasHeap()) delete [] fBuffer; } ~plStringStream() HS_NOEXCEPT { if (ICanHasHeap()) delete [] fBuffer; }
plStringStream(const plStringStream &) = delete; plStringStream(const plStringStream &) = delete;
plStringStream &operator=(const plStringStream &) = delete; plStringStream &operator=(const plStringStream &) = delete;
/** Move operator */ /** Move operator */
plStringStream(plStringStream &&move) plStringStream(plStringStream &&move) HS_NOEXCEPT
: fBufSize(move.fBufSize), fLength(move.fLength) : fBufSize(move.fBufSize), fLength(move.fLength)
{ {
memcpy(fShort, move.fShort, sizeof(fShort)); memcpy(fShort, move.fShort, sizeof(fShort));
@ -732,7 +732,7 @@ public:
} }
/** Move assignment operator. */ /** Move assignment operator. */
plStringStream &operator=(plStringStream &&move) plStringStream &operator=(plStringStream &&move) HS_NOEXCEPT
{ {
memcpy(fShort, move.fShort, sizeof(fShort)); memcpy(fShort, move.fShort, sizeof(fShort));
fBufSize = move.fBufSize; fBufSize = move.fBufSize;
@ -780,13 +780,13 @@ public:
/** Returns a pointer to the beginning of the stream buffer. /** Returns a pointer to the beginning of the stream buffer.
* \warning This pointer is not null-terminated. * \warning This pointer is not null-terminated.
*/ */
const char *GetRawBuffer() const const char *GetRawBuffer() const HS_NOEXCEPT
{ {
return ICanHasHeap() ? fBuffer : fShort; return ICanHasHeap() ? fBuffer : fShort;
} }
/** Return the size (in bytes) of the stream's data. */ /** Return the size (in bytes) of the stream's data. */
size_t GetLength() const { return fLength; } size_t GetLength() const HS_NOEXCEPT { return fLength; }
/** Convert the stream's data to a UTF-8 string. */ /** Convert the stream's data to a UTF-8 string. */
plString GetString() const { return plString::FromUtf8(GetRawBuffer(), fLength); } plString GetString() const { return plString::FromUtf8(GetRawBuffer(), fLength); }
@ -796,7 +796,7 @@ public:
* with as much space as it had before, making this method more * with as much space as it had before, making this method more
* useful for re-using string streams in loops. * useful for re-using string streams in loops.
*/ */
void Truncate() { fLength = 0; } void Truncate() HS_NOEXCEPT { fLength = 0; }
private: private:
union { union {
@ -805,7 +805,7 @@ private:
}; };
size_t fBufSize, fLength; size_t fBufSize, fLength;
bool ICanHasHeap() const { return fBufSize > STRING_STACK_SIZE; } bool ICanHasHeap() const HS_NOEXCEPT { return fBufSize > STRING_STACK_SIZE; }
}; };
/** \p strlen implementation for plUniChar based C-style string buffers. */ /** \p strlen implementation for plUniChar based C-style string buffers. */

6
Sources/Plasma/PubUtilLib/plAudio/plEAXEffects.cpp

@ -150,6 +150,12 @@ bool plEAXListener::Init( void )
SetGlobalEAXProperty(DSPROPSETID_EAX_ListenerProperties, DSPROPERTY_EAXLISTENER_ROOM, &lRoom, sizeof( unsigned int )); SetGlobalEAXProperty(DSPROPSETID_EAX_ListenerProperties, DSPROPERTY_EAXLISTENER_ROOM, &lRoom, sizeof( unsigned int ));
} }
catch (std::exception &e)
{
plStatusLog::AddLineS("audio.log", "Unable to set EAX Property Set (%s), disabling EAX...", e.what());
plgAudioSys::EnableEAX(false);
return false;
}
catch (...) catch (...)
{ {
plStatusLog::AddLineS("audio.log", "Unable to set EAX Property Set, disabling EAX..."); plStatusLog::AddLineS("audio.log", "Unable to set EAX Property Set, disabling EAX...");

8
Sources/Plasma/PubUtilLib/plAvatar/plAvBrainHuman.cpp

@ -161,11 +161,13 @@ bool plAvBrainHuman::Apply(double timeNow, float elapsed)
plArmatureBrain::Apply(timeNow, elapsed); plArmatureBrain::Apply(timeNow, elapsed);
#ifndef _DEBUG #ifndef _DEBUG
} catch (...) } catch (std::exception &e) {
{ plStatusLog *log = plAvatarMgr::GetInstance()->GetLog();
log->AddLineF("plAvBrainHuman::Apply - exception caught: %s", e.what());
} catch (...) {
// just catch all the crashes on exit... // just catch all the crashes on exit...
plStatusLog *log = plAvatarMgr::GetInstance()->GetLog(); plStatusLog *log = plAvatarMgr::GetInstance()->GetLog();
log->AddLine("plAvBrainHuman::Apply - crash caught"); log->AddLine("plAvBrainHuman::Apply - exception caught");
} }
#endif #endif

6
Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h

@ -130,9 +130,9 @@ class plDynamicTextMap : public plMipmap
virtual uint8_t GetNumLevels( void ) const { return 1; } virtual uint8_t GetNumLevels( void ) const { return 1; }
void Colorize() override { } void Colorize() HS_OVERRIDE { }
plMipmap *Clone() const override; plMipmap *Clone() const HS_OVERRIDE;
void CopyFrom(const plMipmap *source) override; void CopyFrom(const plMipmap *source) HS_OVERRIDE;
/// Operations to perform on the text block /// Operations to perform on the text block

13
Sources/Plasma/PubUtilLib/plGImage/plFont.cpp

@ -1475,6 +1475,12 @@ bool plFont::LoadFromFNTStream( hsStream *stream )
ICalcFontAscent(); ICalcFontAscent();
return true; return true;
} }
catch (std::exception &e)
{
printf("Exception caught in plFont::LoadFromFNTStream: %s\n", e.what());
IClear();
return false;
}
catch (...) catch (...)
{ {
// Somehow we crashed converting! // Somehow we crashed converting!
@ -2092,6 +2098,13 @@ bool plFont::LoadFromBDF( const plFileName &path, plBDFConvertCallback *callb
} }
} }
} }
catch (std::exception &e)
{
printf("Exception caught in plFont::LoadFromBDF: %s\n", e.what());
IClear();
fclose(fp);
return false;
}
catch (...) catch (...)
{ {
IClear(); IClear();

18
Sources/Plasma/PubUtilLib/plGImage/plJPEG.cpp

@ -73,7 +73,7 @@ static char jpegmsg[JMSG_LENGTH_MAX];
static void plJPEG_error_exit( j_common_ptr cinfo ) static void plJPEG_error_exit( j_common_ptr cinfo )
{ {
(*cinfo->err->format_message) ( cinfo, jpegmsg ); (*cinfo->err->format_message) ( cinfo, jpegmsg );
throw ( false ); throw false;
} }
static void plJPEG_emit_message( j_common_ptr cinfo, int msg_level ) static void plJPEG_emit_message( j_common_ptr cinfo, int msg_level )
{ {
@ -134,7 +134,7 @@ plMipmap *plJPEG::IRead( hsStream *inStream )
/// Read in the JPEG header /// Read in the JPEG header
if ( inStream->GetEOF() == 0 ) if ( inStream->GetEOF() == 0 )
throw( false ); throw false;
/// Wonderful limitation of mixing our streams with IJL--it wants either a filename /// Wonderful limitation of mixing our streams with IJL--it wants either a filename
/// or a memory buffer. Since we can't give it the former, we have to read the entire /// or a memory buffer. Since we can't give it the former, we have to read the entire
@ -142,11 +142,6 @@ plMipmap *plJPEG::IRead( hsStream *inStream )
/// have to write/read a length of said buffer. Such is life, I guess... /// have to write/read a length of said buffer. Such is life, I guess...
jpegSourceSize = inStream->ReadLE32(); jpegSourceSize = inStream->ReadLE32();
jpegSourceBuffer = new uint8_t[ jpegSourceSize ]; jpegSourceBuffer = new uint8_t[ jpegSourceSize ];
if( jpegSourceBuffer == nil )
{
// waah.
ERREXIT1( &cinfo, JERR_OUT_OF_MEMORY, 0 );
}
inStream->Read( jpegSourceSize, jpegSourceBuffer ); inStream->Read( jpegSourceSize, jpegSourceBuffer );
jpeg_mem_src( &cinfo, jpegSourceBuffer, jpegSourceSize ); jpeg_mem_src( &cinfo, jpegSourceBuffer, jpegSourceSize );
@ -183,11 +178,6 @@ plMipmap *plJPEG::IRead( hsStream *inStream )
/// Construct a new mipmap to hold everything /// Construct a new mipmap to hold everything
newMipmap = new plMipmap( cinfo.output_width, cinfo.output_height, plMipmap::kRGB32Config, 1, plMipmap::kJPEGCompression ); newMipmap = new plMipmap( cinfo.output_width, cinfo.output_height, plMipmap::kRGB32Config, 1, plMipmap::kJPEGCompression );
if( newMipmap == nil || newMipmap->GetImage() == nil )
{
ERREXIT1( &cinfo, JERR_OUT_OF_MEMORY, 0 );
}
/// Set up to read in to that buffer we now have /// Set up to read in to that buffer we now have
JSAMPROW jbuffer; JSAMPROW jbuffer;
int row_stride = cinfo.output_width * cinfo.output_components; int row_stride = cinfo.output_width * cinfo.output_components;
@ -282,10 +272,6 @@ bool plJPEG::IWrite( plMipmap *source, hsStream *outStream )
// Create a buffer to hold the data // Create a buffer to hold the data
jpgBufferSize = source->GetWidth() * source->GetHeight() * 3; jpgBufferSize = source->GetWidth() * source->GetHeight() * 3;
jpgBuffer = new uint8_t[ jpgBufferSize ]; jpgBuffer = new uint8_t[ jpgBufferSize ];
if( jpgBuffer == nil )
{
ERREXIT1( &cinfo, JERR_OUT_OF_MEMORY, 0 );
}
uint8_t *bufferAddr = jpgBuffer; uint8_t *bufferAddr = jpgBuffer;
unsigned long bufferSize = jpgBufferSize; unsigned long bufferSize = jpgBufferSize;

14
Sources/Plasma/PubUtilLib/plGImage/plPNG.cpp

@ -95,21 +95,21 @@ plMipmap* plPNG::IRead(hsStream* inStream)
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) { if (!png_ptr) {
throw(false); throw false;
} }
info_ptr = png_create_info_struct(png_ptr); info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) { if (!info_ptr) {
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
throw(false); throw false;
} }
end_info = png_create_info_struct(png_ptr); end_info = png_create_info_struct(png_ptr);
if (!end_info) { if (!end_info) {
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
throw(false); throw false;
} }
// Assign delegate function for reading from hsStream // Assign delegate function for reading from hsStream
@ -169,10 +169,8 @@ plMipmap* plPNG::IRead(hsStream* inStream)
delete [] row_ptrs; delete [] row_ptrs;
} }
} catch (...) { } catch (...) {
if (newMipmap != NULL) {
delete newMipmap; delete newMipmap;
newMipmap = NULL; newMipmap = nullptr;
}
} }
return newMipmap; return newMipmap;
@ -200,14 +198,14 @@ bool plPNG::IWrite(plMipmap* source, hsStream* outStream)
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) { if (!png_ptr) {
throw(false); throw false;
} }
png_infop info_ptr = png_create_info_struct(png_ptr); png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) { if (!info_ptr) {
png_destroy_write_struct(&png_ptr, (png_infopp)NULL); png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
throw(false); throw false;
} }
// Assign delegate function for writing to hsStream // Assign delegate function for writing to hsStream

4
Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h

@ -237,7 +237,7 @@ private:
int ISendGameMessage(plMessage* msg); int ISendGameMessage(plMessage* msg);
void IDisableNet (); void IDisableNet ();
void ICreateStatusLog() const override; void ICreateStatusLog() const HS_OVERRIDE;
public: public:
plNetClientMgr(); plNetClientMgr();
@ -265,7 +265,7 @@ public:
void SendApplyAvatarCustomizationsMsg(const plKey msgReceiver, bool netPropagate=true, bool localPropagate=true); void SendApplyAvatarCustomizationsMsg(const plKey msgReceiver, bool netPropagate=true, bool localPropagate=true);
// plLoggable // plLoggable
bool Log(const plString& str) const override; bool Log(const plString& str) const HS_OVERRIDE;
// setters // setters
void SetIniAuthServer(const char * value) { fIniAuthServer=value;} void SetIniAuthServer(const char * value) { fIniAuthServer=value;}

12
Sources/Plasma/PubUtilLib/plSDL/plSDLMgr.cpp

@ -191,6 +191,18 @@ int plSDLMgr::Read(hsStream* s, plSDL::DescriptorList* dl)
delete sd; // well that sucked delete sd; // well that sucked
} }
} }
catch (std::exception &e)
{
if (fNetApp)
{
hsLogEntry(fNetApp->DebugMsg("Something bad happened while reading SDLMgr data: %s", e.what()));
}
else
{
DebugMsg("Something bad happened while reading SDLMgr data: %s", e.what());
}
return 0;
}
catch (...) catch (...)
{ {
if (fNetApp) if (fNetApp)

14
Sources/Plasma/PubUtilLib/plSDL/plStateDataRecord.cpp

@ -274,6 +274,13 @@ bool plStateDataRecord::Read(hsStream* s, float timeConvert, uint32_t readOption
} }
} }
} }
catch (std::exception &e)
{
hsAssert(false,
plFormat("Something bad happened ({}) while reading simple var data, desc:{}",
e.what(), fDescriptor ? fDescriptor->GetName() : "?").c_str());
return false;
}
catch (...) catch (...)
{ {
hsAssert(false, hsAssert(false,
@ -308,6 +315,13 @@ bool plStateDataRecord::Read(hsStream* s, float timeConvert, uint32_t readOption
} }
} }
} }
catch (std::exception &e)
{
hsAssert(false,
plFormat("Something bad happened ({}) while reading nested var data, desc:{}",
e.what(), fDescriptor ? fDescriptor->GetName() : "?").c_str());
return false;
}
catch (...) catch (...)
{ {
hsAssert(false, hsAssert(false,

2
Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.h

@ -159,7 +159,7 @@ class plStatusLog : public plLog
~plStatusLog(); ~plStatusLog();
bool AddLine(const plString& line) override; bool AddLine(const plString& line) HS_OVERRIDE;
bool AddLine( const char *line, uint32_t color = kWhite ); bool AddLine( const char *line, uint32_t color = kWhite );

6
Sources/Tools/plFontConverter/plFontConverter.cpp

@ -350,12 +350,12 @@ class plMyBDFCallback : public plBDFConvertCallback
public: public:
plMyBDFCallback(QWidget *parent) : fProgress(parent) { } plMyBDFCallback(QWidget *parent) : fProgress(parent) { }
virtual void NumChars(uint16_t chars) override void NumChars(uint16_t chars) HS_OVERRIDE
{ {
fProgress.SetRange(chars); fProgress.SetRange(chars);
} }
virtual void CharDone() override void CharDone() HS_OVERRIDE
{ {
fPoint++; fPoint++;
fProgress.SetValue(fPoint); fProgress.SetValue(fPoint);
@ -498,7 +498,7 @@ class NumListValidator : public QValidator
public: public:
NumListValidator(QObject *parent = nullptr) : QValidator(parent) { } NumListValidator(QObject *parent = nullptr) : QValidator(parent) { }
virtual State validate(QString &input, int &pos) const override State validate(QString &input, int &pos) const HS_OVERRIDE
{ {
for (int ch = 0; ch < input.size(); ++ch) for (int ch = 0; ch < input.size(); ++ch)
{ {

2
Sources/Tools/plLocalizationEditor/plAddDlgs.cpp

@ -59,7 +59,7 @@ class AlphaNumericValidator : public QValidator
public: public:
AlphaNumericValidator(QObject *parent = nullptr) : QValidator(parent) { } AlphaNumericValidator(QObject *parent = nullptr) : QValidator(parent) { }
virtual State validate(QString &input, int &pos) const override State validate(QString &input, int &pos) const HS_OVERRIDE
{ {
for (int ch = 0; ch < input.size(); ++ch) for (int ch = 0; ch < input.size(); ++ch)
{ {

5
Sources/Tools/plResBrowser/plResBrowser.h

@ -43,6 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _plResBrowser_h #define _plResBrowser_h
#include <QMainWindow> #include <QMainWindow>
#include "HeadSpin.h"
class plResBrowser : public QMainWindow class plResBrowser : public QMainWindow
{ {
@ -55,8 +56,8 @@ public:
void SetWindowTitle(const QString &title); void SetWindowTitle(const QString &title);
protected: protected:
virtual void dragEnterEvent(QDragEnterEvent *event) override; void dragEnterEvent(QDragEnterEvent *event) HS_OVERRIDE;
virtual void dropEvent(QDropEvent *event) override; void dropEvent(QDropEvent *event) HS_OVERRIDE;
private slots: private slots:
void OpenFile(); void OpenFile();

20
cmake/CompilerChecks.cmake

@ -40,8 +40,7 @@ endif()
# Check for CPUID headers # Check for CPUID headers
try_compile(HAVE_CPUID ${PROJECT_BINARY_DIR} try_compile(HAVE_CPUID ${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/cmake/check_cpuid.cpp ${PROJECT_SOURCE_DIR}/cmake/check_cpuid.cpp)
OUTPUT_VARIABLE OUTPUT)
if(HAVE_CPUID) if(HAVE_CPUID)
message("CPUID header found -- using hardware math acceleration when available") message("CPUID header found -- using hardware math acceleration when available")
else() else()
@ -51,17 +50,22 @@ endif()
# Look for a supported "deprecated" attribute specifier. # Look for a supported "deprecated" attribute specifier.
try_compile(HAVE_CXX14_DEPRECATED_ATTR ${PROJECT_BINARY_DIR} try_compile(HAVE_CXX14_DEPRECATED_ATTR ${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/cmake/check_deprecated_attribute.cpp ${PROJECT_SOURCE_DIR}/cmake/check_deprecated_attribute.cpp
COMPILE_DEFINITIONS -DTRY_ATTRIBUTE COMPILE_DEFINITIONS -DTRY_ATTRIBUTE)
OUTPUT_VARIABLE OUTPUT)
try_compile(HAVE_GCC_DEPRECATED_ATTR ${PROJECT_BINARY_DIR} try_compile(HAVE_GCC_DEPRECATED_ATTR ${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/cmake/check_deprecated_attribute.cpp ${PROJECT_SOURCE_DIR}/cmake/check_deprecated_attribute.cpp
COMPILE_DEFINITIONS -DTRY_GCC_ATTR COMPILE_DEFINITIONS -DTRY_GCC_ATTR)
OUTPUT_VARIABLE OUTPUT)
# Look for C++11 constexpr support # Look for C++11 constexpr support
try_compile(HAVE_CONSTEXPR ${PROJECT_BINARY_DIR} try_compile(HAVE_CONSTEXPR ${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/cmake/check_constexpr.cpp ${PROJECT_SOURCE_DIR}/cmake/check_constexpr.cpp)
OUTPUT_VARIABLE OUTPUT)
# Look for C++11 override/final specifiers
try_compile(HAVE_OVERRIDE ${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/cmake/check_override.cpp)
# Look for C++11 noexcept specifier
try_compile(HAVE_NOEXCEPT ${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/cmake/check_noexcept.cpp)
configure_file(${PROJECT_SOURCE_DIR}/cmake/hsCompilerSpecific.h.cmake configure_file(${PROJECT_SOURCE_DIR}/cmake/hsCompilerSpecific.h.cmake
${PROJECT_BINARY_DIR}/hsCompilerSpecific.h) ${PROJECT_BINARY_DIR}/hsCompilerSpecific.h)

7
cmake/check_noexcept.cpp

@ -0,0 +1,7 @@
void doesnt_throw() noexcept { }
int main(int, char **)
{
doesnt_throw();
return 0;
}

26
cmake/check_override.cpp

@ -0,0 +1,26 @@
class Base
{
public:
virtual ~Base() { }
virtual void virtual_function() = 0;
};
class Override : public Base
{
public:
void virtual_function() override { }
};
class Final : public Override
{
public:
void virtual_function() final { }
};
int main(int, char **)
{
Final klass;
klass.virtual_function();
return 0;
}

2
cmake/hsCompilerSpecific.h.cmake

@ -52,5 +52,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#cmakedefine HAVE_GCC_DEPRECATED_ATTR #cmakedefine HAVE_GCC_DEPRECATED_ATTR
#cmakedefine HAVE_CONSTEXPR #cmakedefine HAVE_CONSTEXPR
#cmakedefine HAVE_OVERRIDE
#cmakedefine HAVE_NOEXCEPT
#endif #endif

Loading…
Cancel
Save