Skip to content

Commit

Permalink
Enable ensures on entity handles so we can get more crash info
Browse files Browse the repository at this point in the history
  • Loading branch information
geneotech committed Aug 6, 2024
1 parent 70e2905 commit 2af792f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
8 changes: 7 additions & 1 deletion src/augs/window_framework/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
#include "augs/misc/mutex.h"
#include "all_paths.h"

#if PLATFORM_WINDOWS
#if PLATFORM_WEB
namespace augs {
int shell(const std::string&) { return 0; }

void open_text_editor(const std::string&) {}
}
#elif PLATFORM_WINDOWS
#include <Windows.h>
#undef min
#undef max
Expand Down
24 changes: 17 additions & 7 deletions src/game/cosmos/entity_handle.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once
#define DO_ENSURES 1

#include "augs/build_settings/compiler_defines.h"
#include "augs/templates/get_by_dynamic_id.h"
#include "augs/build_settings/compiler_defines.h"
Expand Down Expand Up @@ -117,21 +119,21 @@ class basic_entity_handle :
{}

const auto& get_meta() const {
#if !IS_PRODUCTION_BUILD
#if DO_ENSURES
ensure(alive());
#endif
return *reinterpret_cast<const entity_solvable_meta*>(ptr);
}

auto& get(cosmos_solvable_access) const {
#if !IS_PRODUCTION_BUILD
#if DO_ENSURES
ensure(alive());
#endif
return *ptr;
}

const auto& get() const {
#if !IS_PRODUCTION_BUILD
#if DO_ENSURES
ensure(alive());
#endif
return *ptr;
Expand Down Expand Up @@ -221,7 +223,7 @@ class basic_entity_handle :

template <class List, class F>
FORCE_INLINE decltype(auto) constrained_dispatch_ret(F&& callback) const {
#if !IS_PRODUCTION_BUILD
#if DO_ENSURES
ensure(alive());
#endif

Expand Down Expand Up @@ -285,7 +287,7 @@ class basic_entity_handle :

template <class F>
decltype(auto) dispatch(F&& callback) const {
#if !IS_PRODUCTION_BUILD
#if DO_ENSURES
ensure(alive());
#endif

Expand Down Expand Up @@ -326,14 +328,22 @@ class basic_entity_handle :
template<class T>
decltype(auto) get() const {
if constexpr(is_invariant_v<T>) {
return *find_invariant_ptr<T>();
const auto inv = find_invariant_ptr<T>();
#if DO_ENSURES
ensure(inv);
#endif
return *inv;
}
else {
if constexpr(is_synchronized_v<T>) {
return component_synchronizer<this_handle_type, T>(find_component_ptr<T>(), *this);
}
else {
return *find_component_ptr<T>();
const auto comp = find_component_ptr<T>();
#if DO_ENSURES
ensure(comp);
#endif
return *comp;
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/game/cosmos/typed_entity_handle.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once
#define DO_ENSURES 1

#include "augs/templates/folded_finders.h"
#include "augs/templates/for_each_std_get.h"

Expand Down Expand Up @@ -147,7 +149,7 @@ struct stored_id_provider {
}

void ensure_alive() const {
#if !IS_PRODUCTION_BUILD
#if DO_ENSURES
ensure(subject != nullptr);
#endif
}
Expand Down
16 changes: 11 additions & 5 deletions src/work.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3630,11 +3630,17 @@ work_result work(
};

WEBSTATIC auto main_ensure_handler = [&]() {
visit_current_setup(
[&](auto& setup) {
setup.ensure_handler();
}
);
if (has_current_setup() || has_main_menu()) {
/*
ensures could be called in the middle of constructing a setup,
which is why we need to check if a setup exists.
*/
visit_current_setup(
[&](auto& setup) {
setup.ensure_handler();
}
);
}
};

::ensure_handler = main_ensure_handler;
Expand Down

0 comments on commit 2af792f

Please sign in to comment.