From 7ba901978bf2f5ba96bd85d18c226490e39580c9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 10 Aug 2016 18:30:46 +0300 Subject: Use xml loader in particle effects. --- src/particle/particle.cpp | 9 +++++++-- src/particle/particleengine.cpp | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src/particle') diff --git a/src/particle/particle.cpp b/src/particle/particle.cpp index 9d755276d..11e36728b 100644 --- a/src/particle/particle.cpp +++ b/src/particle/particle.cpp @@ -38,6 +38,7 @@ #include "resources/image/image.h" #include "resources/loaders/imageloader.h" +#include "resources/loaders/xmlloader.h" #include "utils/delete2.h" #include "utils/dtor.h" @@ -410,14 +411,17 @@ Particle *Particle::addEffect(const std::string &restrict particleEffectFile, const size_t pos = particleEffectFile.find('|'); const std::string dyePalettes = (pos != std::string::npos) ? particleEffectFile.substr(pos + 1) : ""; - XML::Document doc(particleEffectFile.substr(0, pos), + XML::Document *doc = Loader::getXml(particleEffectFile.substr(0, pos), UseResman_true, SkipError_false); - const XmlNodePtrConst rootNode = doc.rootNode(); + if (!doc) + return nullptr; + const XmlNodePtrConst rootNode = doc->rootNode(); if (!rootNode || !xmlNameEqual(rootNode, "effect")) { logger->log("Error loading particle: %s", particleEffectFile.c_str()); + doc->decRef(); return nullptr; } @@ -537,6 +541,7 @@ Particle *Particle::addEffect(const std::string &restrict particleEffectFile, mChildParticles.push_back(newParticle); } + doc->decRef(); return newParticle; } diff --git a/src/particle/particleengine.cpp b/src/particle/particleengine.cpp index 6fd9a79f9..5486076c4 100644 --- a/src/particle/particleengine.cpp +++ b/src/particle/particleengine.cpp @@ -32,6 +32,7 @@ #include "resources/dye/dye.h" #include "resources/loaders/imageloader.h" +#include "resources/loaders/xmlloader.h" #include "utils/dtor.h" @@ -134,14 +135,19 @@ Particle *ParticleEngine::addEffect(const std::string &restrict const size_t pos = particleEffectFile.find('|'); const std::string dyePalettes = (pos != std::string::npos) ? particleEffectFile.substr(pos + 1) : ""; - XML::Document doc(particleEffectFile.substr(0, pos), + XML::Document *doc = Loader::getXml( + particleEffectFile.substr(0, pos), UseResman_true, SkipError_false); - const XmlNodePtrConst rootNode = doc.rootNode(); + if (!doc) + return nullptr; + + const XmlNodePtrConst rootNode = doc->rootNode(); if (!rootNode || !xmlNameEqual(rootNode, "effect")) { logger->log("Error loading particle: %s", particleEffectFile.c_str()); + doc->decRef(); return nullptr; } @@ -261,6 +267,7 @@ Particle *ParticleEngine::addEffect(const std::string &restrict mChildParticles.push_back(newParticle); } + doc->decRef(); return newParticle; } -- cgit v1.2.3-70-g09d2