Skip to content

Commit

Permalink
SONIC: Use ScopedPtr in AreaBackground
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Oct 26, 2016
1 parent b9ff75c commit fceb7ac
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/engines/sonic/areabackground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* The scrolling background image panel in Sonic Chronicles: The Dark Brotherhood.
*/

#include "src/common/scopedptr.h"
#include "src/common/util.h"
#include "src/common/ustring.h"
#include "src/common/error.h"
Expand Down Expand Up @@ -92,33 +93,28 @@ void AreaBackground::render(Graphics::RenderPass pass) {
}

void AreaBackground::loadTexture(const Common::UString &name) {
Common::SeekableReadStream *cbgt = 0, *pal = 0, *twoda = 0;
Graphics::CBGT *image = 0;

try {
if (!(cbgt = ResMan.getResource(name, Aurora::kFileTypeCBGT)))
Common::ScopedPtr<Common::SeekableReadStream> cbgt(ResMan.getResource(name, Aurora::kFileTypeCBGT));
if (!cbgt)
throw Common::Exception("No such CBGT");
if (!(pal = ResMan.getResource(name, Aurora::kFileTypePAL)))

Common::ScopedPtr<Common::SeekableReadStream> pal(ResMan.getResource(name, Aurora::kFileTypePAL));
if (!pal)
throw Common::Exception("No such PAL");
if (!(twoda = ResMan.getResource(name, Aurora::kFileType2DA)))

Common::ScopedPtr<Common::SeekableReadStream> twoda(ResMan.getResource(name, Aurora::kFileType2DA));
if (!twoda)
throw Common::Exception("No such 2DA");

image = new Graphics::CBGT(*cbgt, *pal, *twoda);
_texture = TextureMan.add(Graphics::Aurora::Texture::create(image, Aurora::kFileTypeCBGT), name);
Common::ScopedPtr<Graphics::CBGT> image(new Graphics::CBGT(*cbgt, *pal, *twoda));

} catch (Common::Exception &e) {
delete image;
delete cbgt;
delete pal;
delete twoda;
_texture = TextureMan.add(Graphics::Aurora::Texture::create(image.get(), Aurora::kFileTypeCBGT), name);
image.release();

} catch (Common::Exception &e) {
e.add("Failed loading area background \"%s\"", name.c_str());
throw;
}

delete cbgt;
delete pal;
delete twoda;
}

void AreaBackground::setPosition(float x, float y) {
Expand Down

0 comments on commit fceb7ac

Please sign in to comment.