Skip to content

Commit 3b29fae

Browse files
authored
[Messaging] Improve how the Notification is passed to C# (#1338)
1 parent a7e1be4 commit 3b29fae

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

docs/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ Release Notes
112112
### Upcoming
113113
- Changes
114114
- Firebase AI: Add support for enabling the model to use Code Execution.
115+
- Messaging: Fix crash when deleting a Message with a Notification.
116+
([#1334](https://github.com/firebase/firebase-unity-sdk/issues/1334)).
115117

116118
### 13.2.0
117119
- Changes

messaging/src/swig/messaging.i

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,20 @@ public:
179179
if (g_message_received_callback) {
180180
// Copy the message so that it can be owned and cleaned up by the C#
181181
// proxy object.
182-
Message *copy = new Message();
183-
*copy = *reinterpret_cast<Message*>(message);
182+
Message* original = reinterpret_cast<Message*>(message);
183+
Message* copy = new Message();
184+
*copy = *original;
185+
// If there is a notification, create a copy of that too
186+
if (original->notification) {
187+
copy->notification = new Notification();
188+
*copy->notification = *original->notification;
189+
190+
// Then, if there is an AndroidNotificationParams, we need to copy that too
191+
if (original->notification->android) {
192+
copy->notification->android = new AndroidNotificationParams();
193+
*copy->notification->android = *original->notification->android;
194+
}
195+
}
184196
// If the callback didn't take ownership of the message, delete it.
185197
if (!g_message_received_callback(copy)) {
186198
delete copy;

0 commit comments

Comments
 (0)