I’ve been using AudioCapture to automatically extract voice based on volume. However, I encountered an issue when integrating it within the Character class: it forcefully terminates after one minute. Setting it as a global variable resolved the previously mentioned problem, but upon Unreal Engine shutdown, I’m experiencing various internal errors such as garbage collector collisions or issues with WasapiStreamManager.
Despite configuring destruction in the destructor, I’m still troubled by these errors. Could you kindly provide guidance on how to resolve this matter? Any assistance would be greatly appreciated.
Do not specify destructors for base unreal objects. Unreal manages it’s own memory through the object lifecycle. Just be sure to mark your UAudioCapture with a UPROPERTY so it doesn’t get garbage collected.
is WasapiStreamManager a thirdparty library that you are including? Does it have the right definitions
like
THIRD_PARTY_INCLUDES_START
#if PLATFORM_WINDOWS
#include "Windows/AllowWindowsPlatformTypes.h"
#endif
// pure windows code here
#if PLATFORM_WINDOWS
#include "Windows/HideWindowsPlatformTypes.h"
#endif
THIRD_PARTY_INCLUDES_END
etc
Thank you! Integrating UAudioCapture into the Character class using UPROPERTY has prevented forced terminations even after running for more than a minute. However, upon closing Unreal, an Unhandled Exception: EXCEPTION_ACCESS_VIOLATION 0x0000000000000000 error occurs, seemingly originating from UnrealEditor_AudioCaptureWasapi. Are there any further steps or solutions available to address this issue?
All zeroes mean it’s a null pointer exception. Meaning you are trying to access a reference that is no longer valid.
The audio capture plugin should clean up after itself. Looking into the source code that is where the
AudioCaptureWasapi resides.
I’ll try and reproduce it in a quick project.
I’m guessing you added the module “AudioCapture” into your build file PublicDependencyModuleNames?
Important
Edit: also you mentioned that it’s connected to a character, wouldn’t the UAudioCaptureComponent be the better choice in this case. It would have the same lifecycle as the owning actor. Otherwise it might be left hanging after the actors destruction leading the the null reference.
An example code
.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "MyCharacter.generated.h"
class UAudioCaptureComponent;
UCLASS()
class YOUR_API AMyCharacter : public ACharacter
{
GENERATED_BODY()
public:
AMyCharacter();
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UPROPERTY(BlueprintReadWrite,EditAnywhere)
UAudioCaptureComponent* audioCapture;
};
.cpp
#include "MyCharacter.h"
#include "AudioCaptureComponent.h"
AMyCharacter::AMyCharacter()
{
PrimaryActorTick.bCanEverTick = true;
audioCapture = CreateDefaultSubobject<UAudioCaptureComponent>(TEXT("Audio Capture Component"));
}
void AMyCharacter::BeginPlay()
{
Super::BeginPlay();
}
void AMyCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
Build file modules:
Resulting character:
Not getting any crashes upon exiting.
If you want to stick with the not - component version then on the character’s override
EndPlay you would probably need to set the variable to nullptr manually and then call garbage collection before exit. I think the component version is the safer bet.
I resolved the issue by converting it to an AudioCaptureComponent! Thank you for your help!
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.