[Scummvm-cvs-logs] SF.net SVN: scummvm:[33711] scummvm/branches/gsoc2008-gui
Tanoku at users.sourceforge.net
Tanoku at users.sourceforge.net
Sat Aug 9 16:15:35 CEST 2008
Revision: 33711
http://scummvm.svn.sourceforge.net/scummvm/?rev=33711&view=rev
Author: Tanoku
Date: 2008-08-09 14:15:34 +0000 (Sat, 09 Aug 2008)
Log Message:
-----------
Fixed 1.000.000 Valgrind warnings.
Modified Paths:
--------------
scummvm/branches/gsoc2008-gui/common/xmlparser.cpp
scummvm/branches/gsoc2008-gui/common/xmlparser.h
scummvm/branches/gsoc2008-gui/gui/ThemeEval.cpp
scummvm/branches/gsoc2008-gui/gui/ThemeEval.h
scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp
scummvm/branches/gsoc2008-gui/gui/ThemeParser.h
scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp
scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h
Modified: scummvm/branches/gsoc2008-gui/common/xmlparser.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/common/xmlparser.cpp 2008-08-09 10:52:48 UTC (rev 33710)
+++ scummvm/branches/gsoc2008-gui/common/xmlparser.cpp 2008-08-09 14:15:34 UTC (rev 33711)
@@ -191,6 +191,9 @@
if (_XMLkeys == 0)
buildLayout();
+ while (!_activeKey.empty())
+ delete _activeKey.pop();
+
cleanup();
bool activeClosure = false;
Modified: scummvm/branches/gsoc2008-gui/common/xmlparser.h
===================================================================
--- scummvm/branches/gsoc2008-gui/common/xmlparser.h 2008-08-09 10:52:48 UTC (rev 33710)
+++ scummvm/branches/gsoc2008-gui/common/xmlparser.h 2008-08-09 14:15:34 UTC (rev 33711)
@@ -179,13 +179,13 @@
for a working sample of a Custom XML Parser.
*/
-
+
#define XML_KEY(keyName) {\
- lay = new XMLKeyLayout; \
- lay->custom = new kLocalParserName::CustomParserCallback; \
- ((kLocalParserName::CustomParserCallback*)(lay->custom))->callback = (&kLocalParserName::parserCallback_##keyName); \
- layout.top()->children[#keyName] = lay; \
+ lay = new CustomXMLKeyLayout;\
+ lay->callback = (&kLocalParserName::parserCallback_##keyName);\
+ layout.top()->children[#keyName] = lay;\
layout.push(lay); \
+ _layoutList.push_back(lay);\
for (Common::List<XMLKeyLayout::XMLKeyProperty>::const_iterator p = globalProps.begin(); p != globalProps.end(); ++p){\
layout.top()->properties.push_back(*p);}
@@ -209,16 +209,18 @@
#define CUSTOM_XML_PARSER(parserName) \
protected: \
- typedef bool (parserName::*ParserCallback)(ParserNode *node); \
typedef parserName kLocalParserName; \
- struct CustomParserCallback { ParserCallback callback; }; \
- bool keyCallback(ParserNode *node) {return (this->*(((parserName::CustomParserCallback*)(node->layout->custom))->callback))(node);}\
+ bool keyCallback(ParserNode *node) {return node->layout->doCallback(this, node); }\
+ struct CustomXMLKeyLayout : public XMLKeyLayout {\
+ typedef bool (parserName::*ParserCallback)(ParserNode *node);\
+ ParserCallback callback;\
+ bool doCallback(XMLParser *parent, ParserNode *node) {return ((kLocalParserName*)parent->*callback)(node);} };\
virtual void buildLayout() { \
Common::Stack<XMLKeyLayout*> layout; \
- XMLKeyLayout *lay = 0; \
+ CustomXMLKeyLayout *lay = 0; \
XMLKeyLayout::XMLKeyProperty prop; \
Common::List<XMLKeyLayout::XMLKeyProperty> globalProps; \
- _XMLkeys = new XMLKeyLayout; \
+ _XMLkeys = new CustomXMLKeyLayout; \
layout.push(_XMLkeys);
#define PARSER_END() layout.clear(); }
@@ -280,8 +282,14 @@
virtual ~XMLParser() {
while (!_activeKey.empty())
delete _activeKey.pop();
-
+
delete _XMLkeys;
+
+ for (Common::List<XMLKeyLayout*>::iterator i = _layoutList.begin();
+ i != _layoutList.end(); ++i)
+ delete *i;
+
+ _layoutList.clear();
}
/** Active state for the parser */
@@ -297,12 +305,12 @@
};
struct XMLKeyLayout;
+ struct ParserNode;
typedef Common::HashMap<Common::String, XMLParser::XMLKeyLayout*, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> ChildMap;
/** nested struct representing the layout of the XML file */
struct XMLKeyLayout {
- void *custom;
struct XMLKeyProperty {
Common::String name;
bool required;
@@ -311,9 +319,10 @@
Common::List<XMLKeyProperty> properties;
ChildMap children;
- ~XMLKeyLayout() {
+ virtual bool doCallback(XMLParser *parent, ParserNode *node) = 0;
+
+ virtual ~XMLKeyLayout() {
properties.clear();
- children.clear();
}
} *_XMLkeys;
@@ -336,8 +345,10 @@
bool loadFile(Common::String filename) {
Common::File *f = new Common::File;
- if (!f->open(filename))
+ if (!f->open(filename)) {
+ delete f;
return false;
+ }
_fileName = filename;
_text.loadStream(f);
@@ -564,6 +575,7 @@
*/
virtual void cleanup() {}
+ Common::List<XMLKeyLayout*> _layoutList;
private:
int _pos; /** Current position on the XML buffer. */
Modified: scummvm/branches/gsoc2008-gui/gui/ThemeEval.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeEval.cpp 2008-08-09 10:52:48 UTC (rev 33710)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeEval.cpp 2008-08-09 14:15:34 UTC (rev 33711)
@@ -178,11 +178,14 @@
_w += _children[i]->getWidth() + _spacing;
}
-
_h = MAX(_h, (int16)(_children[i]->getHeight() + _paddingTop + _paddingBottom));
}
}
+ThemeEval::~ThemeEval() {
+ reset();
+}
+
void ThemeEval::buildBuiltinVars() {
_builtin["kThumbnailWidth"] = kThumbnailWidth;
_builtin["kThumbnailHeight"] = kThumbnailHeight1;
@@ -236,6 +239,9 @@
if (!layout)
error("Error when loading dialog position for '%s'", overlays.c_str());
+
+ if (_layouts.contains(name))
+ delete _layouts[name];
_layouts[name] = layout;
Modified: scummvm/branches/gsoc2008-gui/gui/ThemeEval.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeEval.h 2008-08-09 10:52:48 UTC (rev 33710)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeEval.h 2008-08-09 14:15:34 UTC (rev 33711)
@@ -55,7 +55,8 @@
_centered(false), _defaultW(-1), _defaultH(-1) { }
virtual ~ThemeLayout() {
- _children.clear();
+ for (uint i = 0; i < _children.size(); ++i)
+ delete _children[i];
}
virtual void reflowLayout() = 0;
@@ -305,8 +306,9 @@
ThemeEval() {
buildBuiltinVars();
}
- ~ThemeEval() {}
+ ~ThemeEval();
+
void buildBuiltinVars();
int getVar(const Common::String &s) {
@@ -379,6 +381,16 @@
// _layouts["Dialog.GameOptions_Graphics"]->debugDraw(screen, font);
}
+ void reset() {
+ _vars.clear();
+ _builtin.clear();
+ _curDialog.clear();
+ _curLayout.clear();
+
+ for (LayoutsMap::iterator i = _layouts.begin(); i != _layouts.end(); ++i)
+ delete i->_value;
+ }
+
private:
VariablesMap _vars;
VariablesMap _builtin;
Modified: scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp 2008-08-09 10:52:48 UTC (rev 33710)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp 2008-08-09 14:15:34 UTC (rev 33711)
@@ -97,12 +97,12 @@
Graphics::DrawStep *ThemeParser::newDrawStep() {
assert(_defaultStepGlobal);
- Graphics::DrawStep *step = new DrawStep;
+ Graphics::DrawStep *step = 0 ; //new DrawStep;
if (_defaultStepLocal) {
- memcpy(step, _defaultStepLocal, sizeof(DrawStep));
+ step = new DrawStep(*_defaultStepLocal);
} else {
- memcpy(step, _defaultStepGlobal, sizeof(DrawStep));
+ step = new DrawStep(*_defaultStepGlobal);
}
return step;
@@ -116,9 +116,8 @@
step = _defaultStepGlobal;
} else if (parentNode->name == "drawdata") {
if (_defaultStepLocal == 0)
- _defaultStepLocal = new DrawStep;
+ _defaultStepLocal = new DrawStep(*_defaultStepLocal);
- memcpy(_defaultStepLocal, _defaultStepGlobal, sizeof(DrawStep));
step = _defaultStepLocal;
} else {
return parserError("<default> key out of scope. Must be inside <drawdata> or <render_info> keys.");
Modified: scummvm/branches/gsoc2008-gui/gui/ThemeParser.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeParser.h 2008-08-09 10:52:48 UTC (rev 33710)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeParser.h 2008-08-09 14:15:34 UTC (rev 33711)
@@ -312,10 +312,17 @@
class ThemeParser : public XMLParser {
typedef void (VectorRenderer::*DrawingFunctionCallback)(const Common::Rect &, const DrawStep &);
-
+
public:
ThemeParser(GUI::ThemeRenderer *parent);
+ virtual ~ThemeParser() {
+ delete _defaultStepGlobal;
+ delete _defaultStepLocal;
+ _palette.clear();
+ _drawFunctions.clear();
+ }
+
bool getPaletteColor(const Common::String &name, int &r, int &g, int &b) {
if (!_palette.contains(name))
return false;
Modified: scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp 2008-08-09 10:52:48 UTC (rev 33710)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp 2008-08-09 14:15:34 UTC (rev 33711)
@@ -123,6 +123,15 @@
_themeName = themeName;
}
+ThemeRenderer::~ThemeRenderer() {
+ freeRenderer();
+ freeScreen();
+ freeBackbuffer();
+ unloadTheme();
+ delete _parser;
+ delete _themeEval;
+}
+
bool ThemeRenderer::init() {
// reset everything and reload the graphics
deinit();
@@ -174,17 +183,16 @@
template<typename PixelType>
void ThemeRenderer::screenInit(bool backBuffer) {
- freeScreen();
- freeBackbuffer();
-
uint32 width = _system->getOverlayWidth();
uint32 height = _system->getOverlayHeight();
if (backBuffer) {
+ freeBackbuffer();
_backBuffer = new Surface;
_backBuffer->create(width, height, sizeof(PixelType));
}
+ freeScreen();
_screen = new Surface;
_screen->create(width, height, sizeof(PixelType));
_system->clearOverlay();
Modified: scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h 2008-08-09 10:52:48 UTC (rev 33710)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h 2008-08-09 14:15:34 UTC (rev 33711)
@@ -35,13 +35,15 @@
#include "gui/dialog.h"
#include "gui/ThemeParser.h"
-#include "gui/ThemeEval.h"
#include "graphics/VectorRenderer.h"
+#include "gui/ThemeEval.h"
+
namespace GUI {
struct WidgetDrawData;
struct DrawDataInfo;
+class ThemeEval;
struct TextDrawData {
const Graphics::Font *_fontPtr;
@@ -210,12 +212,7 @@
ThemeRenderer(Common::String themeName, GraphicsMode mode);
/** Default destructor */
- ~ThemeRenderer() {
- freeRenderer();
- freeScreen();
- unloadTheme();
- delete _parser;
- }
+ ~ThemeRenderer();
GUI::ThemeEval *themeEval() { return _themeEval; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list