Skip to content

Commit a30dbab

Browse files
authored
Merge pull request #1 from Luz4r/master
Fixes for major issues
2 parents d42a85d + b7ca35f commit a30dbab

14 files changed

+87
-101
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## 1.0.4
4+
5+
### Fixes
6+
7+
- Fix getting proper player reference when in multiplayer session
8+
- Fix freeze when closing game
9+
- Fix invalid handle exception when closing pipes
10+
- Add stopping service when GameInstanceSubsystem is deinitialized
11+
- Change format for MaxRecordingDuration to integer
12+
313
## 1.0.3
414

515
### Fixes

Source/BetaHubBugReporter/Private/BH_Async.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ class BH_AsyncQueue
9999

100100
~BH_AsyncQueue()
101101
{
102-
for (T* Element : Queue)
102+
// This has been disabled as BH_AsyncPool deletes this element also and this freezes the game when trying to exit
103+
/*for (T* Element : Queue)
103104
{
104105
delete Element;
105-
}
106+
}*/
106107
}
107108

108109
void Enqueue(T* Element)

Source/BetaHubBugReporter/Private/BH_BackgroundService.cpp

Lines changed: 5 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,14 @@
66
#include "Components/CanvasPanelSlot.h"
77

88
UBH_BackgroundService::UBH_BackgroundService()
9-
: Settings(nullptr), GameRecorder(nullptr), InputComponent(nullptr)
9+
: Settings(nullptr), GameRecorder(nullptr)
1010
{
11-
static ConstructorHelpers::FClassFinder<UUserWidget> WidgetClassFinder(TEXT("/BetaHubBugReporter/BugReportForm"));
12-
if (WidgetClassFinder.Succeeded())
13-
{
14-
ReportFormWidgetClass = WidgetClassFinder.Class;
15-
}
16-
else
17-
{
18-
UE_LOG(LogTemp, Error, TEXT("Failed to find widget class at specified path."));
19-
}
11+
Settings = GetMutableDefault<UBH_PluginSettings>();
12+
ReportFormWidgetClass = Settings->ReportFormWidgetClass;
2013
}
2114

2215
void UBH_BackgroundService::StartService()
2316
{
24-
Settings = GetMutableDefault<UBH_PluginSettings>();
2517
GameRecorder = NewObject<UBH_GameRecorder>(this);
2618
LogCapture = new UBH_LogCapture();
2719

@@ -51,9 +43,9 @@ void UBH_BackgroundService::RetryInitializeService()
5143
{
5244
UE_LOG(LogTemp, Warning, TEXT("Retrying to initialize service."));
5345

54-
if (GEngine->GameViewport->GetWorld())
46+
if (GetWorld())
5547
{
56-
if (GEngine && GEngine->GameViewport)
48+
if (GEngine && GEngine->GameViewport && GEngine->GameViewport->Viewport)
5749
{
5850
// Viewport is now available, clear the timer and initialize the service
5951
GetWorld()->GetTimerManager().ClearTimer(TimerHandle);
@@ -72,68 +64,12 @@ void UBH_BackgroundService::RetryInitializeService()
7264
void UBH_BackgroundService::InitializeService()
7365
{
7466
GameRecorder->StartRecording(Settings->MaxRecordedFrames, Settings->MaxRecordingDuration);
75-
76-
if (Settings && Settings->bEnableShortcut)
77-
{
78-
UE_LOG(LogTemp, Log, TEXT("Shortcut is enabled."));
79-
80-
if (GEngine && GEngine->GameViewport)
81-
{
82-
UWorld* World = GEngine->GameViewport->GetWorld();
83-
if (World)
84-
{
85-
APlayerController* PlayerController = World->GetFirstPlayerController();
86-
if (PlayerController)
87-
{
88-
InputComponent = NewObject<UInputComponent>(PlayerController);
89-
InputComponent->RegisterComponent();
90-
InputComponent->BindKey(Settings->ShortcutKey, IE_Pressed, this, &UBH_BackgroundService::HandleInput);
91-
PlayerController->PushInputComponent(InputComponent);
92-
}
93-
else
94-
{
95-
UE_LOG(LogTemp, Error, TEXT("PlayerController is null."));
96-
}
97-
}
98-
else
99-
{
100-
UE_LOG(LogTemp, Error, TEXT("World is null."));
101-
102-
}
103-
}
104-
else
105-
{
106-
UE_LOG(LogTemp, Error, TEXT("GameViewport is null."));
107-
}
108-
}
109-
else
110-
{
111-
UE_LOG(LogTemp, Warning, TEXT("Shortcut is disabled."));
112-
}
11367
}
11468

11569
void UBH_BackgroundService::StopService()
11670
{
11771
GLog->RemoveOutputDevice(LogCapture);
11872
delete LogCapture;
119-
120-
if (InputComponent)
121-
{
122-
if (GEngine && GEngine->GameViewport)
123-
{
124-
UWorld* World = GEngine->GameViewport->GetWorld();
125-
if (World)
126-
{
127-
APlayerController* PlayerController = World->GetFirstPlayerController();
128-
if (PlayerController)
129-
{
130-
PlayerController->PopInputComponent(InputComponent);
131-
}
132-
}
133-
}
134-
InputComponent->DestroyComponent();
135-
InputComponent = nullptr;
136-
}
13773

13874
if (GameRecorder)
13975
{
@@ -196,9 +132,3 @@ UBH_GameRecorder* UBH_BackgroundService::GetGameRecorder()
196132
{
197133
return GameRecorder;
198134
}
199-
200-
void UBH_BackgroundService::HandleInput()
201-
{
202-
// trigger delegate
203-
OnTriggerFormKeyPressed.Broadcast();
204-
}

Source/BetaHubBugReporter/Private/BH_GameInstanceSubsystem.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ void UBH_GameInstanceSubsystem::Initialize(FSubsystemCollectionBase& Collection)
88
{
99
Super::Initialize(Collection);
1010

11+
if (GEngine->GetNetMode(GetWorld()) == ENetMode::NM_DedicatedServer)
12+
{
13+
return;
14+
}
15+
1116
UE_LOG(LogTemp, Log, TEXT("BH_GameInstanceSubsystem initialized."));
1217

1318
UBH_PluginSettings* Settings = GetMutableDefault<UBH_PluginSettings>();
@@ -17,6 +22,14 @@ void UBH_GameInstanceSubsystem::Initialize(FSubsystemCollectionBase& Collection)
1722
UE_LOG(LogTemp, Log, TEXT("Spawning background service automatically. This can be disabled in the plugin settings."))
1823

1924
Manager = NewObject<UBH_Manager>(this);
20-
Manager->StartService();
25+
Manager->StartService(GetGameInstance());
26+
}
27+
}
28+
29+
void UBH_GameInstanceSubsystem::Deinitialize()
30+
{
31+
if (Manager)
32+
{
33+
Manager->StopService();
2134
}
2235
}

Source/BetaHubBugReporter/Private/BH_GameRecorder.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ UBH_GameRecorder::UBH_GameRecorder(const FObjectInitializer& ObjectInitializer)
2929
FrameBuffer = ObjectInitializer.CreateDefaultSubobject<UBH_FrameBuffer>(this, TEXT("FrameBuffer"));
3030
}
3131

32-
void UBH_GameRecorder::StartRecording(int32 InTargetFPS, const FTimespan& InRecordingDuration)
32+
void UBH_GameRecorder::StartRecording(int32 InTargetFPS, int32 InRecordingDuration)
3333
{
3434
if (!GEngine)
3535
{
@@ -50,6 +50,12 @@ void UBH_GameRecorder::StartRecording(int32 InTargetFPS, const FTimespan& InReco
5050
return;
5151
}
5252

53+
if (!GEngine->GameViewport->Viewport)
54+
{
55+
UE_LOG(LogTemp, Error, TEXT("Viewport is null."));
56+
return;
57+
}
58+
5359
if (!VideoEncoder.IsValid())
5460
{
5561
FViewport* Viewport = GEngine->GameViewport->Viewport;
@@ -67,15 +73,15 @@ void UBH_GameRecorder::StartRecording(int32 InTargetFPS, const FTimespan& InReco
6773
FrameWidth = (FrameWidth + 3) & ~3;
6874
FrameHeight = (FrameHeight + 3) & ~3;
6975

70-
VideoEncoder = MakeShareable(new BH_VideoEncoder(InTargetFPS, InRecordingDuration, FrameWidth, FrameHeight, FrameBuffer));
76+
VideoEncoder = MakeShareable(new BH_VideoEncoder(InTargetFPS, FTimespan(0, 0, InRecordingDuration), FrameWidth, FrameHeight, FrameBuffer));
7177
}
7278

7379
if (!bIsRecording)
7480
{
7581
VideoEncoder->StartRecording();
7682
bIsRecording = true;
7783
TargetFPS = InTargetFPS;
78-
RecordingDuration = InRecordingDuration;
84+
RecordingDuration = FTimespan(0, 0, InRecordingDuration);
7985

8086
// Register delegate to capture frames during the rendering process
8187
if (GEngine->GameViewport)
@@ -157,7 +163,7 @@ void UBH_GameRecorder::Tick(float DeltaTime)
157163

158164
StopRecording();
159165
VideoEncoder.Reset(); // will need to recreate it
160-
StartRecording(TargetFPS, FTimespan::FromSeconds(0));
166+
StartRecording(TargetFPS, 0);
161167
}
162168
}
163169
}

Source/BetaHubBugReporter/Private/BH_GameRecorder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BETAHUBBUGREPORTER_API UBH_GameRecorder : public UObject, public FTickable
2020
UBH_GameRecorder(const FObjectInitializer& ObjectInitializer);
2121

2222
UFUNCTION(BlueprintCallable, Category="Recording")
23-
void StartRecording(int32 targetFPS, const FTimespan& RecordingDuration);
23+
void StartRecording(int32 targetFPS, int32 RecordingDuration);
2424

2525
UFUNCTION(BlueprintCallable, Category="Recording")
2626
void PauseRecording();

Source/BetaHubBugReporter/Private/BH_Manager.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
#include "BH_Manager.h"
22

33
UBH_Manager::UBH_Manager()
4+
: InputComponent(nullptr)
45
{
56
Settings = GetMutableDefault<UBH_PluginSettings>();
67
}
78

8-
void UBH_Manager::StartService()
9+
void UBH_Manager::StartService(UGameInstance* GI)
910
{
1011
if (BackgroundService)
1112
{
1213
UE_LOG(LogTemp, Error, TEXT("Service already started, did you forget to turn it off in the settings?"));
1314
return;
1415
}
16+
17+
GI->OnLocalPlayerAddedEvent.AddUObject(this, &UBH_Manager::OnLocalPlayerAdded);
1518

1619
BackgroundService = NewObject<UBH_BackgroundService>(this);
1720

1821
BackgroundService->StartService();
19-
20-
BackgroundService->OnTriggerFormKeyPressed.AddDynamic(this, &UBH_Manager::OnBackgroundServiceRequestWidget);
2122
}
2223

2324
void UBH_Manager::StopService()
2425
{
2526
if (BackgroundService)
2627
{
28+
if (CurrentPlayerController)
29+
{
30+
CurrentPlayerController->PopInputComponent(InputComponent);
31+
}
32+
2733
BackgroundService->StopService();
2834
BackgroundService = nullptr;
2935
}
@@ -60,5 +66,22 @@ UBH_ReportFormWidget* UBH_Manager::SpawnBugReportWidget(bool bTryCaptureMouse)
6066
UE_LOG(LogTemp, Error, TEXT("Cannot spawn bug report widget. No widget class specified or found."));
6167
return nullptr;
6268
}
63-
69+
}
70+
71+
void UBH_Manager::OnLocalPlayerAdded(ULocalPlayer* Player)
72+
{
73+
Player->OnPlayerControllerChanged().AddUObject(this, &UBH_Manager::OnPlayerControllerChanged);
74+
}
75+
76+
void UBH_Manager::OnPlayerControllerChanged(APlayerController* PC)
77+
{
78+
CurrentPlayerController = PC;
79+
80+
if (PC)
81+
{
82+
InputComponent = NewObject<UInputComponent>(PC);
83+
InputComponent->RegisterComponent();
84+
InputComponent->BindKey(Settings->ShortcutKey, IE_Pressed, this, &UBH_Manager::OnBackgroundServiceRequestWidget);
85+
PC->PushInputComponent(InputComponent);
86+
}
6487
}

Source/BetaHubBugReporter/Private/BH_PluginSettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ UBH_PluginSettings::UBH_PluginSettings()
1111
bEnableShortcut = true;
1212
ShortcutKey = EKeys::F12;
1313
MaxRecordedFrames = 30;
14-
MaxRecordingDuration = FTimespan::FromSeconds(60);
14+
MaxRecordingDuration = 60;
1515

1616
static ConstructorHelpers::FClassFinder<UBH_ReportFormWidget> WidgetClassFinder1(TEXT("/BetaHubBugReporter/BugReportForm"));
1717
static ConstructorHelpers::FClassFinder<UBH_PopupWidget> WidgetClassFinder2(TEXT("/BetaHubBugReporter/BugReportFormPopup"));

Source/BetaHubBugReporter/Private/BH_ReportFormWidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void UBH_ReportFormWidget::SubmitReport()
5656

5757
void UBH_ReportFormWidget::SetCursorState()
5858
{
59-
if (APlayerController* PlayerController = GetWorld()->GetFirstPlayerController())
59+
if (APlayerController* PlayerController = GetOwningPlayer())
6060
{
6161
// Save the current cursor state
6262
bCursorStateModified = true;
@@ -78,7 +78,7 @@ void UBH_ReportFormWidget::RestoreCursorState()
7878
return;
7979
}
8080

81-
if (APlayerController* PlayerController = GetWorld()->GetFirstPlayerController())
81+
if (APlayerController* PlayerController = GetOwningPlayer())
8282
{
8383
// Restore the previous cursor state
8484
PlayerController->bShowMouseCursor = bWasCursorVisible;

Source/BetaHubBugReporter/Private/BH_Runnable.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ FBH_Runnable::~FBH_Runnable()
4343
delete Thread;
4444
Thread = nullptr;
4545
}
46+
4647
FPlatformProcess::ClosePipe(StdInReadPipe, StdInWritePipe);
4748
FPlatformProcess::ClosePipe(StdOutReadPipe, StdOutWritePipe);
4849
}
@@ -88,6 +89,8 @@ uint32 FBH_Runnable::Run()
8889
{
8990
// close stdin pipe to terminate the process
9091
FPlatformProcess::ClosePipe(StdInReadPipe, StdInWritePipe);
92+
StdInReadPipe = nullptr;
93+
StdInWritePipe = nullptr;
9194
}
9295
else
9396
{

0 commit comments

Comments
 (0)