Image related leaks fix
This commit is contained in:
parent
6c70bb531b
commit
cbafb9a68b
@ -2,9 +2,12 @@
|
||||
#include "Assets.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "../constants.h"
|
||||
|
||||
using std::unique_ptr;
|
||||
|
||||
AssetsLoader::AssetsLoader(Assets* assets) : assets(assets) {
|
||||
}
|
||||
|
||||
@ -62,18 +65,17 @@ bool _load_texture(Assets* assets, const std::string& filename, const std::strin
|
||||
}
|
||||
|
||||
bool _load_atlas(Assets* assets, const std::string& filename, const std::string& name) {
|
||||
ImageData* image = png::load_image(filename);
|
||||
unique_ptr<ImageData> image (png::load_image(filename));
|
||||
if (image == nullptr) {
|
||||
std::cerr << "failed to load image '" << name << "'" << std::endl;
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < ATLAS_MARGIN_SIZE; i++) {
|
||||
ImageData* newimage = add_atlas_margins(image, 16);
|
||||
delete image;
|
||||
image = newimage;
|
||||
ImageData* newimage = add_atlas_margins(image.get(), 16);
|
||||
image.reset(newimage);
|
||||
}
|
||||
|
||||
Texture* texture = Texture::from(image);
|
||||
Texture* texture = Texture::from(image.get());
|
||||
assets->store(texture, name);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -326,12 +326,12 @@ ImageData* png::load_image(std::string filename) {
|
||||
}
|
||||
|
||||
Texture* png::load_texture(std::string filename) {
|
||||
ImageData* image = _png_load(filename.c_str());
|
||||
unique_ptr<ImageData> image (_png_load(filename.c_str()));
|
||||
if (image == nullptr){
|
||||
std::cerr << "Could not load image " << filename << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
return Texture::from(image);
|
||||
return Texture::from(image.get());
|
||||
}
|
||||
|
||||
void png::write_image(std::string filename, const ImageData* image) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user