Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on end play due to null HTTP response from newly activated dictation #98

Open
EvanMcRae opened this issue Feb 18, 2025 · 0 comments

Comments

@EvanMcRae
Copy link

EvanMcRae commented Feb 18, 2025

When activating dictation and then exiting play before the Wit service provides any transcription output, UWitRequestSubsystem::OnRequestComplete is called with a null value for Response. This causes a crash when Response is then dereferenced on line 368 of WitRequestSubsystem.cpp. This issue occurs on at least UE 5.3.

After checking if the HTTP request was unsuccessful, you should also check that Response is valid in order to safely issue an HTTP error message referencing its response code.

Original code:

/**
 * Called when an HTTP request is fully completed to process the response payload
 *
 * @param Request the completed request
 * @param Response the full and final response
 * @param bIsSuccessful whether the request successfully completed
 */
void UWitRequestSubsystem::OnRequestComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bIsSuccessful)
{
	HttpRequest = nullptr;
	
	if (!bIsSuccessful)
	{
		const FString ErrorMessage = FString::Format(TEXT("HTTP Error {0}"), { Response->GetResponseCode()});
		const FString HumanReadableErrorMessage = FString::Format(TEXT("Request failed with error code {0}"), { Response->GetResponseCode()});
		
		Configuration.OnRequestError.Broadcast(ErrorMessage, HumanReadableErrorMessage);
		
		return;
	}

Proposed code (excluding any other desired error message for this case):

/**
 * Called when an HTTP request is fully completed to process the response payload
 *
 * @param Request the completed request
 * @param Response the full and final response
 * @param bIsSuccessful whether the request successfully completed
 */
void UWitRequestSubsystem::OnRequestComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bIsSuccessful)
{
	HttpRequest = nullptr;
	
	if (!bIsSuccessful)
	{
		if (Response)
		{
			const FString ErrorMessage = FString::Format(TEXT("HTTP Error {0}"), { Response->GetResponseCode()});
			const FString HumanReadableErrorMessage = FString::Format(TEXT("Request failed with error code {0}"), { Response->GetResponseCode()});
		
			Configuration.OnRequestError.Broadcast(ErrorMessage, HumanReadableErrorMessage);
		}
		return;
	}
EvanMcRae added a commit to EvanMcRae/wit-unreal that referenced this issue Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant