From b4b2024d1153e1f504dcf29554406d7d30fe9019 Mon Sep 17 00:00:00 2001 From: Austin Ferguson Date: Thu, 7 Jul 2022 14:55:02 -0400 Subject: [PATCH] Check if file exists while loading VCPU genome --- include/emp/hardware/VirtualCPU.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/emp/hardware/VirtualCPU.hpp b/include/emp/hardware/VirtualCPU.hpp index 88d9e0d4ae..0b69aaa9cb 100644 --- a/include/emp/hardware/VirtualCPU.hpp +++ b/include/emp/hardware/VirtualCPU.hpp @@ -212,6 +212,10 @@ namespace emp{ file.RemoveComments("//"); // Remove all C++ style comments file.RemoveComments("#"); // Remove all bash/Python/R style comments file.CompressWhitespace(); // Trim down remaining whitespace. + file.RemoveEmpty(); + if(file.GetNumLines() == 0){ + emp_error("Error! VirtualCPU trying to load a genome from an empty stream!"); + } file.Apply( [this](std::string & info){ PushInst(info); } ); nops_need_curated = true; return true; @@ -219,7 +223,11 @@ namespace emp{ /// Load instructions from file bool Load(const std::string & filename) { std::ifstream is(filename); - return Load(is); + if(is.is_open()){ + return Load(is); + } + emp_error("Error! VirtualCPU genome file is either empty or missing: ", filename); + return false; } /// Add a new instruction to the end of the genome, by index in the instruction library void PushInst(size_t idx){