Skip to content

Commit 6f4e9d9

Browse files
committed
Main: Exception - avoid referencing dangling strings
hence directly resolve fullDesc
1 parent bcdda5c commit 6f4e9d9

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

OgreMain/include/OgreException.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ namespace Ogre {
9999
String description;
100100
String source;
101101
const char* file;
102-
mutable String fullDesc; // storage for char* returned by what()
102+
String fullDesc; // storage for char* returned by what()
103103
public:
104104
/** Static definitions of error codes.
105105
@todo
@@ -145,7 +145,7 @@ namespace Ogre {
145145
the place in which OGRE found the problem, and a text
146146
description from the 3D rendering library, if available.
147147
*/
148-
virtual const String& getFullDescription(void) const;
148+
const String& getFullDescription(void) const { return fullDesc; }
149149

150150
/** Gets the source function.
151151
*/
@@ -166,7 +166,7 @@ namespace Ogre {
166166
const String &getDescription(void) const { return description; }
167167

168168
/// Override std::exception::what
169-
const char* what() const throw() { return getFullDescription().c_str(); }
169+
const char* what() const throw() { return fullDesc.c_str(); }
170170

171171
};
172172

OgreMain/src/OgreException.cpp

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ THE SOFTWARE.
3434
namespace Ogre {
3535

3636
Exception::Exception(int num, const String& desc, const String& src) :
37-
line( 0 ),
38-
description( desc ),
39-
source( src )
37+
Exception(num, desc, src, "", "", 0)
4038
{
4139
}
4240

@@ -48,6 +46,18 @@ namespace Ogre {
4846
source( src ),
4947
file( fil )
5048
{
49+
StringStream ss;
50+
51+
ss << typeName << ": "
52+
<< description
53+
<< " in " << source;
54+
55+
if( line > 0 )
56+
{
57+
ss << " at " << file << " (line " << line << ")";
58+
}
59+
60+
fullDesc = ss.str();
5161
}
5262

5363
Exception::Exception(const Exception& rhs)
@@ -58,28 +68,5 @@ namespace Ogre {
5868
file( rhs.file )
5969
{
6070
}
61-
62-
const String& Exception::getFullDescription(void) const
63-
{
64-
if (fullDesc.empty())
65-
{
66-
67-
StringStream desc;
68-
69-
desc << typeName << ": "
70-
<< description
71-
<< " in " << source;
72-
73-
if( line > 0 )
74-
{
75-
desc << " at " << file << " (line " << line << ")";
76-
}
77-
78-
fullDesc = desc.str();
79-
}
80-
81-
return fullDesc;
82-
}
83-
8471
}
8572

RenderSystems/Direct3D11/include/OgreD3D11Prerequisites.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,13 @@ namespace Ogre
145145
int hresult;
146146
public:
147147
D3D11RenderingAPIException(int hr, const String& inDescription, const String& inSource, const char* inFile, long inLine)
148-
: RenderingAPIException(hr, inDescription, inSource, inFile, inLine), hresult(hr) {}
149-
150-
int getHResult() const { return hresult; }
151-
152-
const String& getFullDescription(void) const {
148+
: RenderingAPIException(hr, inDescription, inSource, inFile, inLine), hresult(hr) {
153149
StringStream ss;
154-
ss << RenderingAPIException::getFullDescription() << " HRESULT=0x" << std::hex << hresult;
150+
ss << fullDesc << " HRESULT=0x" << std::hex << hresult;
155151
fullDesc = ss.str();
156-
return fullDesc;
157152
}
153+
154+
int getHResult() const { return hresult; }
158155
};
159156
}
160157
#endif

0 commit comments

Comments
 (0)