From 7d6a28f088455610f74b09eda7789381041555f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Bergstr=C3=B6m?= <davbe125@student.liu.se> Date: Thu, 19 Jul 2018 10:54:27 +0200 Subject: [PATCH] Fix bug where returning reference to {} would crash --- src/TechTreeImproved.cpp | 2 +- src/TechTreeImproved.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/TechTreeImproved.cpp b/src/TechTreeImproved.cpp index 74f853766..84a394fd5 100644 --- a/src/TechTreeImproved.cpp +++ b/src/TechTreeImproved.cpp @@ -119,6 +119,6 @@ const std::vector<BuildDescription> & TechTreeImproved::HowToBuild(sc2::UnitType else { std::cout << "No information about unit type " << sc2::UnitTypeToName(unit) << " (" << static_cast<int>(unit) << ")" << std::endl; - return {}; + return empty; } } \ No newline at end of file diff --git a/src/TechTreeImproved.h b/src/TechTreeImproved.h index 1c01572f8..c17d847f1 100644 --- a/src/TechTreeImproved.h +++ b/src/TechTreeImproved.h @@ -25,6 +25,9 @@ class TechTreeImproved std::map<sc2::UNIT_TYPEID, std::vector<BuildDescription>> producer_to_data; std::map<sc2::UNIT_TYPEID, std::vector<BuildDescription>> result_to_data; + // If there is no BuildDescription for a given type, a reference to tihs list is returned. + const std::vector<BuildDescription> empty {}; + void parse_unit(nlohmann::json::iterator it); public: TechTreeImproved(); -- GitLab