@@ -77,26 +77,31 @@ void SentryAndroidBeforeSendLogHandler::_bind_methods() {
7777// *** AndroidSDK
7878
7979void AndroidSDK::set_context (const String &p_key, const Dictionary &p_value) {
80+ Object *android_plugin = _get_android_plugin ();
8081 ERR_FAIL_NULL (android_plugin);
8182 android_plugin->call (ANDROID_SN (setContext), p_key, sanitize_variant (p_value));
8283}
8384
8485void AndroidSDK::remove_context (const String &p_key) {
86+ Object *android_plugin = _get_android_plugin ();
8587 ERR_FAIL_NULL (android_plugin);
8688 android_plugin->call (ANDROID_SN (removeContext), p_key);
8789}
8890
8991void AndroidSDK::set_tag (const String &p_key, const String &p_value) {
92+ Object *android_plugin = _get_android_plugin ();
9093 ERR_FAIL_NULL (android_plugin);
9194 android_plugin->call (ANDROID_SN (setTag), p_key, p_value);
9295}
9396
9497void AndroidSDK::remove_tag (const String &p_key) {
98+ Object *android_plugin = _get_android_plugin ();
9599 ERR_FAIL_NULL (android_plugin);
96100 android_plugin->call (ANDROID_SN (removeTag), p_key);
97101}
98102
99103void AndroidSDK::set_user (const Ref<SentryUser> &p_user) {
104+ Object *android_plugin = _get_android_plugin ();
100105 ERR_FAIL_NULL (android_plugin);
101106
102107 if (p_user.is_valid ()) {
@@ -111,25 +116,29 @@ void AndroidSDK::set_user(const Ref<SentryUser> &p_user) {
111116}
112117
113118void AndroidSDK::remove_user () {
119+ Object *android_plugin = _get_android_plugin ();
114120 ERR_FAIL_NULL (android_plugin);
115121 android_plugin->call (ANDROID_SN (removeUser));
116122}
117123
118124Ref<SentryBreadcrumb> AndroidSDK::create_breadcrumb () {
125+ Object *android_plugin = _get_android_plugin ();
119126 ERR_FAIL_NULL_V (android_plugin, nullptr );
120127 int32_t handle = android_plugin->call (ANDROID_SN (createBreadcrumb));
121128 Ref<AndroidBreadcrumb> crumb = memnew (AndroidBreadcrumb (android_plugin, handle));
122129 return crumb;
123130}
124131
125132void AndroidSDK::add_breadcrumb (const Ref<SentryBreadcrumb> &p_breadcrumb) {
133+ Object *android_plugin = _get_android_plugin ();
126134 ERR_FAIL_NULL (android_plugin);
127135 Ref<AndroidBreadcrumb> crumb = p_breadcrumb;
128136 ERR_FAIL_COND (crumb.is_null ());
129137 android_plugin->call (ANDROID_SN (addBreadcrumb), crumb->get_handle ());
130138}
131139
132140void AndroidSDK::log (LogLevel p_level, const String &p_body, const Dictionary &p_attributes) {
141+ Object *android_plugin = _get_android_plugin ();
133142 ERR_FAIL_NULL (android_plugin);
134143
135144 if (p_body.is_empty ()) {
@@ -152,23 +161,27 @@ void AndroidSDK::log(LogLevel p_level, const String &p_body, const Dictionary &p
152161}
153162
154163String AndroidSDK::capture_message (const String &p_message, Level p_level) {
164+ Object *android_plugin = _get_android_plugin ();
155165 ERR_FAIL_NULL_V (android_plugin, String ());
156166 return android_plugin->call (ANDROID_SN (captureMessage), p_message, p_level);
157167}
158168
159169String AndroidSDK::get_last_event_id () {
170+ Object *android_plugin = _get_android_plugin ();
160171 ERR_FAIL_NULL_V (android_plugin, String ());
161172 return android_plugin->call (ANDROID_SN (getLastEventId));
162173}
163174
164175Ref<SentryEvent> AndroidSDK::create_event () {
176+ Object *android_plugin = _get_android_plugin ();
165177 ERR_FAIL_NULL_V (android_plugin, nullptr );
166178 int32_t event_handle = android_plugin->call (ANDROID_SN (createEvent));
167179 Ref<AndroidEvent> event = memnew (AndroidEvent (android_plugin, event_handle));
168180 return event;
169181}
170182
171183String AndroidSDK::capture_event (const Ref<SentryEvent> &p_event) {
184+ Object *android_plugin = _get_android_plugin ();
172185 ERR_FAIL_NULL_V (android_plugin, String ());
173186 ERR_FAIL_COND_V (p_event.is_null (), String ());
174187 Ref<AndroidEvent> android_event = p_event;
@@ -179,6 +192,7 @@ String AndroidSDK::capture_event(const Ref<SentryEvent> &p_event) {
179192}
180193
181194void AndroidSDK::capture_feedback (const Ref<SentryFeedback> &p_feedback) {
195+ Object *android_plugin = _get_android_plugin ();
182196 ERR_FAIL_NULL (android_plugin);
183197 ERR_FAIL_COND_MSG (p_feedback.is_null (), " Sentry: Can't capture feedback - feedback object is null." );
184198 ERR_FAIL_COND_MSG (p_feedback->get_message ().is_empty (), " Sentry: Can't capture feedback - feedback message is empty." );
@@ -190,6 +204,8 @@ void AndroidSDK::capture_feedback(const Ref<SentryFeedback> &p_feedback) {
190204}
191205
192206void AndroidSDK::add_attachment (const Ref<SentryAttachment> &p_attachment) {
207+ Object *android_plugin = _get_android_plugin ();
208+ ERR_FAIL_NULL (android_plugin);
193209 ERR_FAIL_COND (p_attachment.is_null ());
194210
195211 if (p_attachment->get_path ().is_empty ()) {
@@ -211,6 +227,7 @@ void AndroidSDK::add_attachment(const Ref<SentryAttachment> &p_attachment) {
211227}
212228
213229void AndroidSDK::init (const PackedStringArray &p_global_attachments, const Callable &p_configuration_callback) {
230+ Object *android_plugin = _get_android_plugin ();
214231 ERR_FAIL_NULL (android_plugin);
215232
216233 if (p_configuration_callback.is_valid ()) {
@@ -251,20 +268,23 @@ void AndroidSDK::init(const PackedStringArray &p_global_attachments, const Calla
251268}
252269
253270void AndroidSDK::close () {
271+ Object *android_plugin = _get_android_plugin ();
254272 if (android_plugin != nullptr ) {
255273 android_plugin->call (ANDROID_SN (close));
256274 }
257275}
258276
259277bool AndroidSDK::is_enabled () const {
278+ Object *android_plugin = _get_android_plugin ();
260279 return android_plugin && android_plugin->call (ANDROID_SN (isEnabled));
261280}
262281
263282AndroidSDK::AndroidSDK () {
264283 AndroidStringNames::create_singleton ();
265284
266- android_plugin = Engine::get_singleton ()->get_singleton (" SentryAndroidGodotPlugin" );
285+ Object * android_plugin = Engine::get_singleton ()->get_singleton (" SentryAndroidGodotPlugin" );
267286 ERR_FAIL_NULL_MSG (android_plugin, " Sentry: Unable to locate SentryAndroidGodotPlugin singleton." );
287+ android_plugin_instance_id = android_plugin->get_instance_id ();
268288
269289 before_send_handler = memnew (SentryAndroidBeforeSendHandler);
270290 before_send_handler->_initialize (android_plugin);
@@ -274,10 +294,6 @@ AndroidSDK::AndroidSDK() {
274294}
275295
276296AndroidSDK::~AndroidSDK () {
277- if (is_enabled ()) {
278- close ();
279- }
280-
281297 AndroidStringNames::destroy_singleton ();
282298 if (before_send_handler) {
283299 memdelete (before_send_handler);
0 commit comments