diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 0202e810fd..200c9cb565 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -178,6 +178,8 @@ ENDIF(NOT POW_FUNCTION_EXISTS AND NOT NEED_LINKING_AGAINST_LIBM) IF (NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Release, RelWithDebInfo, Debug, Profiler" FORCE ) ENDIF (NOT CMAKE_BUILD_TYPE) +MESSAGE("** Build Type: ${CMAKE_BUILD_TYPE}") + #IF (NOT BUILD_OPT) # SET(BUILD_OPT -O2 CACHE STRING "-O0, -O1, -O2, -O3, -Os, -Ofast" FORCE ) @@ -296,10 +298,12 @@ add_compile_options("$<$:/FI${Vega_Strike_BINARY_DIR}/conf "$<$,$>:/Z7>" ) add_link_options("$<$:/DEBUG>") +# for DEBUG remove all optimizations add_compile_options("$<$,$,$>:-pipe>" "$<$,$,$>:-Wall>" "$<$,$,$>:-fvisibility=hidden>" - "$<$,$,$>,$,$,$>>:-Og>" + "$<$,$,$>,$>:-O0>" + "$<$,$,$>,$,$>>:-Og>" "$<$,$,$>,$,$>>:-g3>" "$<$,$,$>,$>:-pg>" "$<$,$,$>,$>:-g2>" diff --git a/engine/src/cmd/json.cpp b/engine/src/cmd/json.cpp index e5710b0515..cb576a1d68 100644 --- a/engine/src/cmd/json.cpp +++ b/engine/src/cmd/json.cpp @@ -5,6 +5,8 @@ #include "json.h" #include +#include "vs_logging.h" + /*! \brief Checks for an empty string * * @param str The string to check @@ -388,6 +390,12 @@ std::vector json::parsing::parse_array(const char *input) // Initalize the result std::vector result; + if (input != nullptr) { + VS_LOG_AND_FLUSH(debug, boost::format("JSON Data: %s") % input); + } else { + VS_LOG_AND_FLUSH(debug, "Invalid JSON Input - NULL Pointer"); + } + const char *index = json::parsing::tlws(input); if (*index != '[') throw json::parsing_error("Input was not an array"); index++; diff --git a/engine/src/cmd/upgradeable_unit.cpp b/engine/src/cmd/upgradeable_unit.cpp index 891b485cab..210b3fceb4 100644 --- a/engine/src/cmd/upgradeable_unit.cpp +++ b/engine/src/cmd/upgradeable_unit.cpp @@ -38,6 +38,7 @@ #include "unit_generic.h" #include "weapon_info.h" #include "vega_cast_utils.h" +#include "vs_logging.h" std::vector ParseUnitUpgrades(const std::string &upgrades) { if(upgrades.size() == 0) { @@ -141,6 +142,14 @@ bool UpgradeableUnit::UpgradeMounts(const Unit *up, return true; } + // there needs to be some mounts to be able to mount to + if (num_mounts == 0) { + // would be nice to make this more meaningful but that's a little harder given + // the casting of `unit` from `this`. + VS_LOG(debug, "No mounts to attach to."); + return false; + } + int j = mountoffset; int i = 0; bool cancompletefully = true; diff --git a/engine/src/gfx/mesh_gfx.cpp b/engine/src/gfx/mesh_gfx.cpp index d9f8ba0018..23edb8db44 100644 --- a/engine/src/gfx/mesh_gfx.cpp +++ b/engine/src/gfx/mesh_gfx.cpp @@ -438,15 +438,41 @@ Mesh::~Mesh() { vector *hashers = bfxmHashTable.Get(hash_name); vector::iterator finder; if (hashers) { - for (size_t i = hashers->size() - 1; i >= 0; --i) { - if (hashers->at(i) == this) { - hashers->erase(hashers->begin() + i); + // the foollowing loop has several tricks to it: + // 1. `std::vector::erase()` can take an interator and remove it from the vector; but invalidates + // the iterator in the process + // 2. To overcome the invalid iterator issue, the next previous iterator is cached + // 3. In the case that the previous iterator would be invalid (e.g it's at the start) then it needs + // to restart the loop without the loop conditions, therefore a simple GOTO is used instead to + // avoid the incrementing the iterator so that values are not skipped + // A reverse iterator could kind of help this; however, `std::vector::erase` unfortunately + // does not work on reverse iterators. + for (auto hashItem = hashers->begin(); hashItem != hashers->end(); ++hashItem) { +retryEraseItem: + if (*hashItem == this) { + bool resetIter = false; + auto cachedHashItem = hashers->begin(); + if (hashItem != hashers->begin()) { + cachedHashItem = hashItem - 1; + } else { + resetIter = true; + cachedHashItem = hashItem + 1; + } + hashers->erase(hashItem); if (hashers->empty()) { bfxmHashTable.Delete(hash_name); delete hashers; hashers = nullptr; break; } + + if (resetIter) { + hashItem = hashers->begin(); + // a necessary use of Goto as we do not want to use ++hashItem + goto retryEraseItem; + } else { + hashItem = cachedHashItem; + } } } } diff --git a/engine/vcpkg.json b/engine/vcpkg.json index 3d66e9e900..4f949e94b8 100644 --- a/engine/vcpkg.json +++ b/engine/vcpkg.json @@ -27,6 +27,7 @@ "version>=": "1.1.1m" }, "sdl1", + "sdl2", "zlib" ] }