@@ -191,14 +191,14 @@ std::size_t SentryLogger::ErrorKeyHash::operator()(const ErrorKey &p_key) const
191191}
192192
193193void SentryLogger::_connect_process_frame () {
194- SceneTree *scene_tree = Object::cast_to<SceneTree>( Engine::get_singleton ()->get_main_loop () );
195- if (scene_tree) {
196- Callable callable = callable_mp ( this , &SentryLogger::_process_frame );
197- if (! scene_tree-> is_connected ( " process_frame" , callable)) {
198- scene_tree-> connect ( " process_frame " , callable);
199- }
200- } else {
201- ERR_PRINT ( " Sentry: Failed to connect ` process_frame` signal – main loop is null " );
194+ MainLoop *main_loop = Engine::get_singleton ()->get_main_loop ();
195+ ERR_FAIL_NULL_MSG (main_loop, " SentryLogger: Failed to connect to \" process_frame \" signal - main loop is null. " );
196+ SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop );
197+ ERR_FAIL_NULL_MSG ( scene_tree, " SentryLogger: Failed to connect to \" process_frame\" signal - expected SceneTree instance as main loop. " );
198+
199+ Callable callable = callable_mp ( this , &SentryLogger::_process_frame);
200+ if (!scene_tree-> is_connected ( " process_frame " , callable)) {
201+ scene_tree-> connect ( " process_frame" , callable );
202202 }
203203}
204204
@@ -364,10 +364,20 @@ void SentryLogger::_log_message(const String &p_message, bool p_error) {
364364 " debug" );
365365}
366366
367+ void SentryLogger::_bind_methods () {
368+ ClassDB::bind_method (D_METHOD (" _connect_process_frame" ), &SentryLogger::_connect_process_frame);
369+ }
370+
367371void SentryLogger::_notification (int p_what) {
368372 switch (p_what) {
369373 case NOTIFICATION_POSTINITIALIZE: {
370- callable_mp (this , &SentryLogger::_connect_process_frame).call_deferred ();
374+ SceneTree *scene_tree = Object::cast_to<SceneTree>(Engine::get_singleton ()->get_main_loop ());
375+ if (scene_tree) {
376+ _connect_process_frame ();
377+ } else {
378+ // Defer signal connection since SceneTree is not available during early initialization.
379+ call_deferred (" _connect_process_frame" );
380+ }
371381 } break ;
372382 case NOTIFICATION_PREDELETE: {
373383 _disconnect_process_frame ();
@@ -394,12 +404,6 @@ SentryLogger::~SentryLogger() {
394404 if (!Engine::get_singleton ()) {
395405 return ;
396406 }
397-
398- SceneTree *scene_tree = Object::cast_to<SceneTree>(Engine::get_singleton ()->get_main_loop ());
399- Callable callable = callable_mp (this , &SentryLogger::_process_frame);
400- if (scene_tree && scene_tree->is_connected (" process_frame" , callable)) {
401- scene_tree->disconnect (" process_frame" , callable);
402- }
403407}
404408
405409} // namespace sentry
0 commit comments