Skip to content

Commit

Permalink
Merge pull request #1 from BenjamenMeyer/bmeyer_bugfix_imgui_1
Browse files Browse the repository at this point in the history
Bug Fixes
  • Loading branch information
royfalk authored Sep 29, 2023
2 parents 2d6a4cb + ea61472 commit 868a1dc
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
6 changes: 5 additions & 1 deletion engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -296,10 +298,12 @@ add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/FI${Vega_Strike_BINARY_DIR}/conf
"$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Debug>>:/Z7>"
)
add_link_options("$<$<CXX_COMPILER_ID:MSVC>:/DEBUG>")
# for DEBUG remove all optimizations
add_compile_options("$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-pipe>"
"$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-Wall>"
"$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-fvisibility=hidden>"
"$<$<AND:$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>,$<OR:$<CONFIG:Debug>,$<CONFIG:Profiler>,$<CONFIG:RelWithDebInfo>>>:-Og>"
"$<$<AND:$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>,$<CONFIG:Debug>>:-O0>"
"$<$<AND:$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>,$<OR:$<CONFIG:Profiler>,$<CONFIG:RelWithDebInfo>>>:-Og>"
"$<$<AND:$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>,$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>>:-g3>"
"$<$<AND:$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>,$<CONFIG:Profiler>>:-pg>"
"$<$<AND:$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>,$<CONFIG:Profiler>>:-g2>"
Expand Down
8 changes: 8 additions & 0 deletions engine/src/cmd/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "json.h"
#include <string.h>

#include "vs_logging.h"

/*! \brief Checks for an empty string
*
* @param str The string to check
Expand Down Expand Up @@ -388,6 +390,12 @@ std::vector<std::string> json::parsing::parse_array(const char *input)
// Initalize the result
std::vector<std::string> 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++;
Expand Down
9 changes: 9 additions & 0 deletions engine/src/cmd/upgradeable_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "unit_generic.h"
#include "weapon_info.h"
#include "vega_cast_utils.h"
#include "vs_logging.h"

std::vector<std::string> ParseUnitUpgrades(const std::string &upgrades) {
if(upgrades.size() == 0) {
Expand Down Expand Up @@ -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;
Expand Down
32 changes: 29 additions & 3 deletions engine/src/gfx/mesh_gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,41 @@ Mesh::~Mesh() {
vector<Mesh *> *hashers = bfxmHashTable.Get(hash_name);
vector<Mesh *>::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;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions engine/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"version>=": "1.1.1m"
},
"sdl1",
"sdl2",
"zlib"
]
}

0 comments on commit 868a1dc

Please sign in to comment.