mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-28 08:39:20 +00:00
attempt to fix a crash with LinphoneChatMessage (java) pointing to a null LinphoneChatMessage (C)
This commit is contained in:
parent
e99fdee766
commit
ddd0805222
1 changed files with 12 additions and 6 deletions
|
|
@ -4754,7 +4754,7 @@ static void message_state_changed(LinphoneChatMessage* msg, LinphoneChatMessageS
|
|||
}
|
||||
jclass clazz = (jclass) env->GetObjectClass(listener);
|
||||
jmethodID method = env->GetMethodID(clazz, "onLinphoneChatMessageStateChanged","(Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneChatMessage$State;)V");
|
||||
jobject jmessage = getChatMessage(env, msg);
|
||||
jobject jmessage = (jobject)linphone_chat_message_get_user_data(msg); /*this returns a global ref that was taken in setListener*/
|
||||
env->DeleteLocalRef(clazz);
|
||||
|
||||
LinphoneChatRoom *room = linphone_chat_message_get_chat_room(msg);
|
||||
|
|
@ -4765,9 +4765,10 @@ static void message_state_changed(LinphoneChatMessage* msg, LinphoneChatMessageS
|
|||
if (state == LinphoneChatMessageStateDisplayed) {
|
||||
env->DeleteGlobalRef(listener);
|
||||
msg->message_state_changed_user_data = NULL;
|
||||
}
|
||||
if (jmessage) {
|
||||
env->DeleteLocalRef(jmessage);
|
||||
//We are going to drop our global ref, as the listener is no longer needed.
|
||||
//Before, replace it by a weak ref, as other messages.
|
||||
linphone_chat_message_set_user_data(msg, env->NewWeakGlobalRef(jmessage));
|
||||
env->DeleteGlobalRef(jmessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -4852,11 +4853,17 @@ static LinphoneBuffer* file_transfer_send(LinphoneChatMessage *msg, const Linph
|
|||
return buffer;
|
||||
}
|
||||
|
||||
/*
|
||||
* When the listener is set, we must take a global reference to the listener and the message, so that
|
||||
* we are able to notify the state changes of the message, until it reaches its final state
|
||||
*/
|
||||
extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_setListener(JNIEnv* env, jobject thiz, jlong ptr, jobject jlistener) {
|
||||
jobject listener = env->NewGlobalRef(jlistener);
|
||||
LinphoneChatMessage *message = (LinphoneChatMessage *)ptr;
|
||||
LinphoneChatMessageCbs *cbs;
|
||||
|
||||
jobject jmessage = env->NewGlobalRef(thiz);
|
||||
linphone_chat_message_set_user_data(message, jmessage);
|
||||
message->message_state_changed_user_data = listener;
|
||||
cbs = linphone_chat_message_get_callbacks(message);
|
||||
linphone_chat_message_cbs_set_msg_state_changed(cbs, message_state_changed);
|
||||
|
|
@ -4963,8 +4970,7 @@ extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendChatMessage(JNIE
|
|||
,jlong chatroom_ptr
|
||||
,jobject message
|
||||
,jlong messagePtr) {
|
||||
message = env->NewGlobalRef(message);
|
||||
linphone_chat_message_set_user_data((LinphoneChatMessage*)messagePtr, message);
|
||||
|
||||
linphone_chat_room_send_chat_message_2((LinphoneChatRoom*)chatroom_ptr, (LinphoneChatMessage*)messagePtr);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue