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