Skip to content

Commit

Permalink
Inline terminate handler
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Oct 29, 2024
1 parent bfd8d38 commit 57f5556
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 49 deletions.
2 changes: 0 additions & 2 deletions source/core/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ target_sources(tactile-core
"src/debug/assert.cpp"
"src/debug/performance.cpp"
"src/debug/stacktrace.cpp"
"src/debug/terminate.cpp"
"src/document/document_manager.cpp"
"src/document/layer_view_impl.cpp"
"src/document/map_document.cpp"
Expand Down Expand Up @@ -133,7 +132,6 @@ target_sources(tactile-core
"inc/tactile/core/debug/assert.hpp"
"inc/tactile/core/debug/performance.hpp"
"inc/tactile/core/debug/stacktrace.hpp"
"inc/tactile/core/debug/terminate.hpp"
"inc/tactile/core/document/document_info.hpp"
"inc/tactile/core/document/document_manager.hpp"
"inc/tactile/core/document/layer_view_impl.hpp"
Expand Down
19 changes: 0 additions & 19 deletions source/core/lib/inc/tactile/core/debug/terminate.hpp

This file was deleted.

25 changes: 0 additions & 25 deletions source/core/lib/src/debug/terminate.cpp

This file was deleted.

20 changes: 17 additions & 3 deletions source/runtime/lib/src/runtime_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "tactile/runtime/runtime_impl.hpp"

#include <chrono> // steady_clock
#include <cstdlib> // malloc, free, EXIT_SUCCESS, EXIT_FAILURE
#include <cstdlib> // malloc, free, abort, EXIT_SUCCESS, EXIT_FAILURE
#include <exception> // exception, set_terminate
#include <optional> // optional
#include <unordered_map> // unordered_map
Expand All @@ -12,7 +12,7 @@
#include <imgui.h>

#include "tactile/base/render/renderer.hpp"
#include "tactile/core/debug/terminate.hpp"
#include "tactile/core/debug/stacktrace.hpp"
#include "tactile/core/logging.hpp"
#include "tactile/core/numeric/random.hpp"
#include "tactile/core/platform/win32.hpp"
Expand All @@ -28,6 +28,20 @@
namespace tactile::runtime {
namespace {

[[noreturn]]
void _on_terminate() noexcept
{
try {
const auto trace = core::get_stacktrace();
TACTILE_RUNTIME_ERROR("Into exile I must go. Failed I have.\n{}", trace);
}
catch (...) { // NOLINT(*-empty-catch)
// Not much we can do.
}

std::abort();
}

[[nodiscard]]
auto _imgui_malloc(const std::size_t bytes, void*) -> void*
{
Expand Down Expand Up @@ -112,7 +126,7 @@ struct RuntimeImpl::Data final

RuntimeImpl::RuntimeImpl(const CommandLineOptions& options)
{
std::set_terminate(&core::on_terminate);
std::set_terminate(&_on_terminate);
m_data = std::make_unique<Data>(options);

core::init_random_number_generator();
Expand Down

0 comments on commit 57f5556

Please sign in to comment.