Skip to content

Commit

Permalink
v1.4.1 Hotfix: Bind PIE End to avoid crash on shutdown if there's an …
Browse files Browse the repository at this point in the history
…active task + Bind Start & Fail delegates in Editor tool
  • Loading branch information
lucoiso committed Mar 21, 2023
1 parent d379414 commit b9c6a55
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion HttpGPT.uplugin
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 6,
"VersionName": "1.4.0",
"VersionName": "1.4.1",
"EngineVersion": "5.1.0",
"FriendlyName": "HttpGPT - ChatGPT integrated in the Engine",
"Description": "HttpGPT is an Unreal Engine plugin that facilitates integration with Chat GPT through asynchronous REST requests, making it easy for developers to communicate with the chatbot. HttpGPT also includes a new Editor Tool to integrate Chat GPT directly in the Engine.",
Expand Down
5 changes: 5 additions & 0 deletions Source/HttpGPT/HttpGPT.Build.cs
Expand Up @@ -24,5 +24,10 @@ public HttpGPT(ReadOnlyTargetRules Target) : base(Target)
"CoreUObject",
"DeveloperSettings"
});

if (Target.bBuildEditor)
{
PrivateDependencyModuleNames.Add("UnrealEd");
}
}
}
32 changes: 31 additions & 1 deletion Source/HttpGPT/Private/HttpGPTRequest.cpp
Expand Up @@ -16,6 +16,10 @@
#include <Misc/ScopeTryLock.h>
#include <Async/Async.h>

#if WITH_EDITOR
#include <Editor.h>
#endif

#ifdef UE_INLINE_GENERATED_CPP_BY_NAME
#include UE_INLINE_GENERATED_CPP_BY_NAME(HttpGPTRequest)
#endif
Expand Down Expand Up @@ -102,6 +106,10 @@ void UHttpGPTRequest::Activate()
SendRequest();
}
);

#if WITH_EDITOR
FEditorDelegates::PrePIEEnded.AddUObject(this, &UHttpGPTRequest::PrePIEEnded);
#endif
}

void UHttpGPTRequest::SetReadyToDestroy()
Expand All @@ -115,12 +123,34 @@ void UHttpGPTRequest::SetReadyToDestroy()

UE_LOG(LogHttpGPT, Display, TEXT("%s (%d): Setting task as Ready to Destroy"), *FString(__func__), GetUniqueID());

Super::SetReadyToDestroy();
#if WITH_EDITOR
if (FEditorDelegates::PrePIEEnded.IsBoundToObject(this))
{
FEditorDelegates::PrePIEEnded.RemoveAll(this);
}
#endif

bIsReadyToDestroy = true;
bIsActive = false;

Super::SetReadyToDestroy();
}

#if WITH_EDITOR
void UHttpGPTRequest::PrePIEEnded(bool bIsSimulating)
{
if (!IsValid(this))
{
return;
}

UE_LOG(LogHttpGPT, Display, TEXT("%s (%d): Trying to finish task due to PIE end"), *FString(__func__), GetUniqueID());

bEndingPIE = true;
StopHttpGPTTask();
}
#endif

void UHttpGPTRequest::SendRequest()
{
FScopeLock Lock(&Mutex);
Expand Down
6 changes: 6 additions & 0 deletions Source/HttpGPT/Public/HttpGPTRequest.h
Expand Up @@ -89,4 +89,10 @@ class HTTPGPT_API UHttpGPTRequest : public UBlueprintAsyncActionBase
bool bInitialized = false;
bool bIsReadyToDestroy = false;
bool bIsActive = false;

#if WITH_EDITOR
virtual void PrePIEEnded(bool bIsSimulating);

bool bEndingPIE = false;
#endif
};
2 changes: 2 additions & 0 deletions Source/HttpGPTEditor/Private/SHttpGPTChatView.cpp
Expand Up @@ -129,6 +129,8 @@ FReply SHttpGPTChatView::HandleSendMessageButton()
RequestReference->ProgressUpdated.AddDynamic(NewMessage, &UHttpGPTMessagingHandler::ResponseReceived);
RequestReference->ProcessCompleted.AddDynamic(NewMessage, &UHttpGPTMessagingHandler::ResponseReceived);
RequestReference->ErrorReceived.AddDynamic(NewMessage, &UHttpGPTMessagingHandler::ResponseReceived);
RequestReference->RequestFailed.AddDynamic(NewMessage, &UHttpGPTMessagingHandler::RequestFailed);
RequestReference->RequestSent.AddDynamic(NewMessage, &UHttpGPTMessagingHandler::RequestSent);

RequestReference->Activate();

Expand Down

0 comments on commit b9c6a55

Please sign in to comment.