Skip to content

Commit

Permalink
Fix crash on shutdown on Windows (#36)
Browse files Browse the repository at this point in the history
* Fix crash on shutdown on Windows

* Strengthen code & add debug prints
  • Loading branch information
limbonaut authored Dec 4, 2024
1 parent 2806ae1 commit 4912c35
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ void _init_logger() {
return;
}
// Add experimental logger to scene tree.
SentryLogger *logger = memnew(SentryLogger);
SceneTree *sml = Object::cast_to<SceneTree>(Engine::get_singleton()->get_main_loop());
if (sml) {
sml->get_root()->add_child(logger);
if (sml && sml->get_root()) {
sml->get_root()->add_child(memnew(SentryLogger));
} else {
ERR_FAIL_MSG("Sentry: Internal error: SceneTree is null.");
}
Expand Down Expand Up @@ -55,9 +54,13 @@ void initialize_module(ModuleInitializationLevel p_level) {
}

void uninitialize_module(ModuleInitializationLevel p_level) {
if (p_level == MODULE_INITIALIZATION_LEVEL_CORE) {
memdelete(SentrySDK::get_singleton());
delete SentryOptions::get_singleton();
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
if (SentrySDK::get_singleton()) {
memdelete(SentrySDK::get_singleton());
}
if (SentryOptions::get_singleton()) {
delete SentryOptions::get_singleton();
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/sentry_sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void SentrySDK::set_context(const godot::String &p_key, const godot::Dictionary
}

void SentrySDK::_init_contexts() {
sentry::util::print_debug("initializing contexts");
internal_sdk->set_context("device", sentry::contexts::make_device_context(runtime_config));
internal_sdk->set_context("app", sentry::contexts::make_app_context());
internal_sdk->set_context("gpu", sentry::contexts::make_gpu_context());
Expand Down Expand Up @@ -121,6 +122,7 @@ SentrySDK::SentrySDK() {

enabled = enabled && SentryOptions::get_singleton()->is_enabled();
if (!enabled) {
sentry::util::print_debug("Sentry SDK is DISABLED! Operations with Sentry SDK will result in no-ops.");
internal_sdk = std::make_shared<DisabledSDK>();
return;
}
Expand Down

0 comments on commit 4912c35

Please sign in to comment.