Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Fixed setting `throttle_window_ms` to 0 should disable it ([#382](https://github.com/getsentry/sentry-godot/pull/382))
- Fixed failing to set initial user on Apple platforms ([#390](https://github.com/getsentry/sentry-godot/pull/390))
- Added missing `crashpad_wer.dll` to Windows builds and export dependencies ([#396](https://github.com/getsentry/sentry-godot/pull/396))
- Sanitize Variant values on Android, and fix custom context and local variables missing or null on Android ([#397](https://github.com/getsentry/sentry-godot/pull/397))

### Other changes

Expand Down
50 changes: 48 additions & 2 deletions project/mobile.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,56 @@ func _ready() -> void:
get_viewport().get_window().content_scale_mode = Window.CONTENT_SCALE_MODE_CANVAS_ITEMS
get_viewport().get_window().content_scale_aspect = Window.CONTENT_SCALE_ASPECT_EXPAND

# Show tests only if the test file is available
%Tests.visible = FileAccess.file_exists(MOBILE_TESTS_FILE)
%RunTestsButton.visible = FileAccess.file_exists(MOBILE_TESTS_FILE)


func _on_run_tests_button_pressed() -> void:
var tests = load(MOBILE_TESTS_FILE).new()
tests.run_tests()


func _on_test_diverse_context_button_pressed() -> void:
var context := {
"null": null,
"bool": true,
"int": 42,
"float": 42.42,
"string": "hello, world!",
"Vector2": Vector2(123.45, 67.89),
"Vector2i": Vector2i(123, 45),
"Rect2": Rect2(123.45, 67.89, 98.76, 54.32),
"Rect2i": Rect2i(12, 34, 56, 78),
"Vector3": Vector3(12.34, 56.78, 90.12),
"Vector3i": Vector3i(12, 34, 56),
"Transform2D": Transform2D().translated(Vector2(12.34, 56.78)),
"Vector4": Vector4(12.34, 56.78, 90.12, 34.56),
"Vector4i": Vector4i(12, 34, 56, 78),
"Plane": Plane(Vector3(1, 2, 3), 4),
"Quaternion": Quaternion(Vector3(0, 1, 0), 4),
"AABB": AABB(Vector3(1, 2, 3), Vector3(4, 5, 6)),
"Basis": Basis(Vector3(1, 2, 3), Vector3(4, 5, 6), Vector3(7, 8, 9)),
"Transform3D": Transform3D().translated(Vector3(12.34, 56.78, 90.12)),
"Projection": Projection(Vector4(73.21, 19.47, 85.63, 73.02), Vector4(41.92, 67.38, 22.14, 59.81), Vector4(93.76, 15.49, 38.72, 84.25), Vector4(26.58, 71.93, 47.16, 62.84)),
"Color": Color(12.34, 56.78, 90.12, 34.56),
"StringName": StringName("hello, world!"),
"NodePath": NodePath("/root"),
"RID": RID(),
"Object": self,
"Callable": _on_test_diverse_context_button_pressed,
"Signal": get_tree().process_frame,
"Dictionary": {"key1": "value1", "key2": 42, "key3": self},
"Array": [1, self, {"hello": "world"}],
"PackedByteArray": PackedByteArray([1, 2, 3, 4, 5]),
"PackedInt32Array": PackedInt32Array([1, 2, 3, 4, 5]),
"PackedInt64Array": PackedInt64Array([1, 2, 3, 4, 5]),
"PackedFloat32Array": PackedFloat32Array([1.23, 4.56, 7.89]),
"PackedFloat64Array": PackedFloat64Array([1.23, 4.56, 7.89]),
"PackedStringArray": PackedStringArray(["hello", "world"]),
"PackedVector2Array": PackedVector2Array([Vector2(1, 2), Vector2(3, 4)]),
"PackedVector3Array": PackedVector3Array([Vector3(1, 2, 3), Vector3(4, 5, 6)]),
"PackedColorArray": PackedColorArray([Color(1, 2, 3, 4), Color(5, 6, 7, 8)]),
"PackedVector4Array": PackedVector4Array([Vector4(1, 2, 3, 4), Vector4(5, 6, 7, 8)]),
}
SentrySDK.set_context("diverse_context", context)
DemoOutput.print_info("Added context with diverse values.")
SentrySDK.capture_message("Test diverse context")
16 changes: 11 additions & 5 deletions project/mobile.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,35 @@ metadata/_tab_index = 0
layout_mode = 2
metadata/_tab_index = 1

[node name="Tests" type="VBoxContainer" parent="VBoxContainer/VBoxContainer/TabContainer"]
[node name="Tools" type="VBoxContainer" parent="VBoxContainer/VBoxContainer/TabContainer"]
unique_name_in_owner = true
visible = false
layout_mode = 2
metadata/_tab_index = 2

[node name="Header - Mobile Tests" type="Label" parent="VBoxContainer/VBoxContainer/TabContainer/Tests"]
[node name="Header - Actions" type="Label" parent="VBoxContainer/VBoxContainer/TabContainer/Tools"]
custom_minimum_size = Vector2(0, 40.505)
layout_mode = 2
text = "MOBILE TESTS"
text = "ACTIONS"
horizontal_alignment = 1
vertical_alignment = 2

[node name="RunTestsButton" type="Button" parent="VBoxContainer/VBoxContainer/TabContainer/Tests"]
[node name="RunTestsButton" type="Button" parent="VBoxContainer/VBoxContainer/TabContainer/Tools"]
unique_name_in_owner = true
layout_mode = 2
text = "Run mobile tests"

[node name="TestDiverseContextButton" type="Button" parent="VBoxContainer/VBoxContainer/TabContainer/Tools"]
unique_name_in_owner = true
layout_mode = 2
text = "Test diverse context"

[node name="OutputPane" parent="VBoxContainer/VBoxContainer" instance=ExtResource("4_xux57")]
layout_mode = 2

[node name="Spacer2" type="Control" parent="VBoxContainer"]
custom_minimum_size = Vector2(0, 20)
layout_mode = 2

[connection signal="pressed" from="VBoxContainer/VBoxContainer/TabContainer/Tests/RunTestsButton" to="." method="_on_run_tests_button_pressed"]
[connection signal="pressed" from="VBoxContainer/VBoxContainer/TabContainer/Tools/RunTestsButton" to="." method="_on_run_tests_button_pressed"]
[connection signal="pressed" from="VBoxContainer/VBoxContainer/TabContainer/Tools/TestDiverseContextButton" to="." method="_on_test_diverse_context_button_pressed"]
2 changes: 1 addition & 1 deletion project/views/capture_events.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func _init_level_choice_popup() -> void:
func _init_user_info() -> void:
var user := SentryUser.create_default()
SentrySDK.set_user(user)

username.text = user.username
email.text = user.email
user_id.text = user.id
Expand Down
6 changes: 4 additions & 2 deletions src/sentry/android/android_event.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "android_event.h"

#include "android_string_names.h"
#include "android_util.h"

namespace sentry::android {

Expand Down Expand Up @@ -104,7 +105,8 @@ String AndroidEvent::get_tag(const String &p_key) {

void AndroidEvent::merge_context(const String &p_key, const Dictionary &p_value) {
ERR_FAIL_COND_MSG(p_key.is_empty(), "Sentry: Can't merge context with an empty key.");
android_plugin->call(ANDROID_SN(eventMergeContext), event_handle, p_key, p_value);
android_plugin->call(ANDROID_SN(eventMergeContext),
event_handle, p_key, sanitize_variant(p_value));
}

void AndroidEvent::add_exception(const Exception &p_exception) {
Expand All @@ -128,7 +130,7 @@ void AndroidEvent::add_exception(const Exception &p_exception) {
if (!frame.vars.is_empty()) {
Dictionary variables;
for (auto var : frame.vars) {
variables[var.first] = var.second;
variables[var.first] = sanitize_variant(var.second);
}
data["vars"] = variables;
}
Expand Down
3 changes: 2 additions & 1 deletion src/sentry/android/android_sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "android_breadcrumb.h"
#include "android_event.h"
#include "android_string_names.h"
#include "android_util.h"
#include "sentry/common_defs.h"
#include "sentry/processing/process_event.h"
#include "sentry/sentry_attachment.h"
Expand Down Expand Up @@ -40,7 +41,7 @@ void SentryAndroidBeforeSendHandler::_bind_methods() {

void AndroidSDK::set_context(const String &p_key, const Dictionary &p_value) {
ERR_FAIL_NULL(android_plugin);
android_plugin->call(ANDROID_SN(setContext), p_key, p_value);
android_plugin->call(ANDROID_SN(setContext), p_key, sanitize_variant(p_value));
}

void AndroidSDK::remove_context(const String &p_key) {
Expand Down
88 changes: 88 additions & 0 deletions src/sentry/android/android_util.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include "android_util.h"

#include "sentry/common_defs.h"

using namespace godot;

namespace sentry::android {

Variant sanitize_variant(const Variant &p_value, int p_depth) {
switch (p_value.get_type()) {
case Variant::DICTIONARY: {
if (p_depth > VARIANT_CONVERSION_MAX_DEPTH) {
ERR_PRINT_ONCE("Sentry: Maximum Variant depth reached!");
return Variant();
}

Dictionary old_dict = p_value;
Dictionary new_dict;

const Array &keys = old_dict.keys();
for (int i = 0; i < keys.size(); i++) {
const Variant &key = keys[i];
new_dict[key.stringify()] = sanitize_variant(old_dict[key], p_depth + 1);
}

return new_dict;
} break;
case Variant::ARRAY:
case Variant::PACKED_BYTE_ARRAY:
case Variant::PACKED_INT32_ARRAY:
case Variant::PACKED_INT64_ARRAY:
case Variant::PACKED_FLOAT32_ARRAY:
case Variant::PACKED_FLOAT64_ARRAY:
case Variant::PACKED_STRING_ARRAY:
case Variant::PACKED_VECTOR2_ARRAY:
case Variant::PACKED_VECTOR3_ARRAY:
case Variant::PACKED_COLOR_ARRAY:
case Variant::PACKED_VECTOR4_ARRAY: {
if (p_depth > VARIANT_CONVERSION_MAX_DEPTH) {
ERR_PRINT_ONCE("Sentry: Maximum Variant depth reached!");
return Variant();
}

Array arr;
bool oob = false;
bool valid = true;
int i = 0;

do {
Variant item = p_value.get_indexed(i++, valid, oob);
if (valid) {
arr.append(sanitize_variant(item, p_depth + 1));
}
} while (!oob);

return arr;
} break;
case Variant::VECTOR2:
case Variant::VECTOR2I:
case Variant::RECT2:
case Variant::RECT2I:
case Variant::VECTOR3:
case Variant::VECTOR3I:
case Variant::TRANSFORM2D:
case Variant::VECTOR4:
case Variant::VECTOR4I:
case Variant::PLANE:
case Variant::QUATERNION:
case Variant::AABB:
case Variant::BASIS:
case Variant::TRANSFORM3D:
case Variant::PROJECTION:
case Variant::COLOR:
case Variant::STRING_NAME:
case Variant::NODE_PATH:
case Variant::RID:
case Variant::OBJECT:
case Variant::CALLABLE:
case Variant::SIGNAL: {
return p_value.stringify();
} break;
default: {
return p_value;
} break;
}
}

} //namespace sentry::android
9 changes: 9 additions & 0 deletions src/sentry/android/android_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <godot_cpp/variant/variant.hpp>

namespace sentry::android {

godot::Variant sanitize_variant(const godot::Variant &p_value, int p_depth = 0);

} // namespace sentry::android
Loading