diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
index fa593ad..ec4bfba 100644
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@ -1,7 +1,9 @@
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(PlatformGlob)
-include_directories("${PROJECT_SOURCE_DIR}")
+include_directories("${PROJECT_SOURCE_DIR}"
+ "${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
+ )
platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
diff --git a/utils/imgfile_sdl.cpp b/utils/imgfile_sdl.cpp
index 5694da2..4cffebe 100644
--- a/utils/imgfile_sdl.cpp
+++ b/utils/imgfile_sdl.cpp
@@ -20,6 +20,7 @@ along with this program. If not, see .
*/
#include
+#include
#include
#include
@@ -59,17 +60,29 @@ bool ImgFile::open(const std::string &img_path)
void ImgFile::close()
{
+ if (!impl->stream) {
+ LOG_F(WARNING, "ImgFile::close before disk was opened, ignoring.");
+ return;
+ }
impl->stream.reset();
}
uint64_t ImgFile::size() const
{
+ if (!impl->stream) {
+ LOG_F(WARNING, "ImgFile::size before disk was opened, ignoring.");
+ return 0;
+ }
impl->stream->seekg(0, impl->stream->end);
return impl->stream->tellg();
}
uint64_t ImgFile::read(void* buf, uint64_t offset, uint64_t length) const
{
+ if (!impl->stream) {
+ LOG_F(WARNING, "ImgFile::read before disk was opened, ignoring.");
+ return 0;
+ }
impl->stream->seekg(offset, std::ios::beg);
impl->stream->read((char *)buf, length);
return impl->stream->gcount();
@@ -77,6 +90,10 @@ uint64_t ImgFile::read(void* buf, uint64_t offset, uint64_t length) const
uint64_t ImgFile::write(const void* buf, uint64_t offset, uint64_t length)
{
+ if (!impl->stream) {
+ LOG_F(WARNING, "ImgFile::write before disk was opened, ignoring.");
+ return 0;
+ }
impl->stream->seekg(offset, std::ios::beg);
impl->stream->write((const char *)buf, length);
#if defined(WIN32) || defined(__APPLE__) || defined(__linux)