From 9381acb6a42da653cb6dfd9e610dfccead11aa98 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Wed, 23 Mar 2022 11:08:58 +0200 Subject: Make FileAccess and DirAccess classes reference counted. --- drivers/png/image_loader_png.cpp | 4 +--- drivers/png/image_loader_png.h | 2 +- drivers/png/resource_saver_png.cpp | 6 +----- 3 files changed, 3 insertions(+), 9 deletions(-) (limited to 'drivers/png') diff --git a/drivers/png/image_loader_png.cpp b/drivers/png/image_loader_png.cpp index 46e271f9c9..917bfec574 100644 --- a/drivers/png/image_loader_png.cpp +++ b/drivers/png/image_loader_png.cpp @@ -36,18 +36,16 @@ #include -Error ImageLoaderPNG::load_image(Ref p_image, FileAccess *f, bool p_force_linear, float p_scale) { +Error ImageLoaderPNG::load_image(Ref p_image, Ref f, bool p_force_linear, float p_scale) { const uint64_t buffer_size = f->get_length(); Vector file_buffer; Error err = file_buffer.resize(buffer_size); if (err) { - f->close(); return err; } { uint8_t *writer = file_buffer.ptrw(); f->get_buffer(writer, buffer_size); - f->close(); } const uint8_t *reader = file_buffer.ptr(); return PNGDriverCommon::png_to_image(reader, buffer_size, p_force_linear, p_image); diff --git a/drivers/png/image_loader_png.h b/drivers/png/image_loader_png.h index af3bcd5b66..522cc901d4 100644 --- a/drivers/png/image_loader_png.h +++ b/drivers/png/image_loader_png.h @@ -40,7 +40,7 @@ private: static Ref load_mem_png(const uint8_t *p_png, int p_size); public: - virtual Error load_image(Ref p_image, FileAccess *f, bool p_force_linear, float p_scale); + virtual Error load_image(Ref p_image, Ref f, bool p_force_linear, float p_scale); virtual void get_recognized_extensions(List *p_extensions) const; ImageLoaderPNG(); }; diff --git a/drivers/png/resource_saver_png.cpp b/drivers/png/resource_saver_png.cpp index ca84fb6be9..8633d2dc4e 100644 --- a/drivers/png/resource_saver_png.cpp +++ b/drivers/png/resource_saver_png.cpp @@ -52,20 +52,16 @@ Error ResourceSaverPNG::save_image(const String &p_path, const Ref &p_img Vector buffer; Error err = PNGDriverCommon::image_to_png(p_img, buffer); ERR_FAIL_COND_V_MSG(err, err, "Can't convert image to PNG."); - FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); + Ref file = FileAccess::open(p_path, FileAccess::WRITE, &err); ERR_FAIL_COND_V_MSG(err, err, vformat("Can't save PNG at path: '%s'.", p_path)); const uint8_t *reader = buffer.ptr(); file->store_buffer(reader, buffer.size()); if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) { - memdelete(file); return ERR_CANT_CREATE; } - file->close(); - memdelete(file); - return OK; } -- cgit v1.2.3