Release of invalid GC handle. The handle is from a previous domain. The release operation is skipped. #209
-
First of all, I want to thank you for creating such a helpful Unity asset. It has significantly contributed to the completion of my project. However, I've encountered an odd issue after using the asset. Occasionally, messages from the Assistant are sent twice from a single chat request. The content of the messages is different. There are sometimes, a message is sent but receive no reply. When such issues arise, Unity has reported an error stating, "Release of invalid GC handle. The handle is from a previous domain. The release operation is skipped." Here is the code I've implemented in my Unity project. I noticed that when the Assistant sends a message twice, only one is recorded in the List. public async void AskChatGPTAsync(string newText)
{
responseTMP.text = "";
loadingAnimation.SetActive(true);
messages.Add(new Message(Role.User, newText));
var chatRequest = new ChatRequest(messages, languageModel);
var response = await api.ChatEndpoint.GetCompletionAsync(chatRequest);
var choice = response.FirstChoice;
loadingAnimation.SetActive(false);
responseTMP.text = choice.Message;
messages.Add(choice.Message);
foreach (var message in messages)
{
Debug.Log($"{message.Role}: {message}");
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @tunyawat. I'll need better steps to reproduce this issue you're running into. It sounds like maybe are reloading the domain or entering and exiting from play mode but not cancelling your previous sessions call. You should also be passing a cancellation token source. You can create your own or use var response = await api.ChatEndpoint.GetCompletionAsync(chatRequest, destroyCancellationToken); |
Beta Was this translation helpful? Give feedback.
-
I will try and give the feedback later, thanks. |
Beta Was this translation helpful? Give feedback.
Hi @tunyawat. I'll need better steps to reproduce this issue you're running into.
It sounds like maybe are reloading the domain or entering and exiting from play mode but not cancelling your previous sessions call.
You should also be passing a cancellation token source. You can create your own or use
GameObject.destroyCancellationToken