From 48e51bb3cb4a7bfc7be9d9368cf10bdd03d10ff5 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Fri, 25 Nov 2016 22:32:42 +0100 Subject: [PATCH] handle non existant serialized state better --- CMakeLists.txt | 1 - src/Serializer.h | 10 ++++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 05d5b4e..94ab6c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,7 +69,6 @@ SET ( protot_SRCS src/shaderc_hlsl.cpp src/RuntimeModuleManager.cc - # src/Serializer.cc 3rdparty/glfw/deps/glad.c ) diff --git a/src/Serializer.h b/src/Serializer.h index d528d04..a850368 100644 --- a/src/Serializer.h +++ b/src/Serializer.h @@ -5,7 +5,7 @@ #include #include #include - +#include struct WriteSerializer { enum { IsReading = 0 }; @@ -71,13 +71,19 @@ struct ReadSerializer { } void Open(const char* filename) { + // early out if file does not (yet) exist + struct stat fstat; + if (stat(filename, &fstat) == -1) { + return; + } + std::ifstream stream(filename, std::ios::binary); + size_t key_size; size_t block_size; while (!stream.eof()) { - // read key size stream.read(reinterpret_cast(&key_size), sizeof(size_t)); std::cout << "read key size " << key_size << std::endl;