Skip to content

Commit b879125

Browse files
Fix some ways to get crash.
1 parent 8c357db commit b879125

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

Source/PubnubLibrary/Private/PubnubSubsystem.cpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,26 @@ void UPubnubSubsystem::InitPubnub()
4949
PubnubError("Pubnub is already initialized", EPubnubErrorType::PET_Warning);
5050
return;
5151
}
52-
53-
//Create new threads - separate for subscribe and all other operations
54-
QuickActionThread = new FPubnubFunctionThread;
55-
LongpollThread = new FPubnubLoopingThread;
56-
57-
if(!CheckQuickActionThreadValidity())
58-
{return;}
5952

60-
QuickActionThread->AddFunctionToQueue( [this]
53+
InitPubnub_priv();
54+
55+
//If initialized correctly, create required thread.
56+
if(IsInitialized)
6157
{
62-
InitPubnub_priv();
63-
});
58+
//Create new threads - separate for subscribe and all other operations
59+
QuickActionThread = new FPubnubFunctionThread;
60+
LongpollThread = new FPubnubLoopingThread;
61+
}
62+
6463
}
6564

6665
void UPubnubSubsystem::DeinitPubnub()
6766
{
68-
if(!CheckQuickActionThreadValidity())
69-
{return;}
67+
if(!QuickActionThread)
68+
{
69+
DeinitPubnub_priv();
70+
return;
71+
}
7072

7173
QuickActionThread->AddFunctionToQueue( [this]
7274
{
@@ -828,6 +830,11 @@ void UPubnubSubsystem::PubnubError(FString ErrorMessage, EPubnubErrorType ErrorT
828830
UE_LOG(PubnubLog, Warning, TEXT("%s"), *ErrorMessage);
829831
}
830832

833+
if(!OnPubnubError.IsBound())
834+
{
835+
return;
836+
}
837+
831838
//Errors has to be broadcasted on GameThread, otherwise engine will crash if someone uses them for example with widgets
832839
AsyncTask(ENamedThreads::GameThread, [this, ErrorMessage, ErrorType]()
833840
{
@@ -959,11 +966,13 @@ void UPubnubSubsystem::InitPubnub_priv()
959966
if(std::strlen(PublishKey) == 0 )
960967
{
961968
PubnubError("Publish key is empty, can't initialize Pubnub");
969+
return;
962970
}
963971

964972
if(std::strlen(SubscribeKey) == 0 )
965973
{
966974
PubnubError("Subscribe key is empty, can't initialize Pubnub");
975+
return;
967976
}
968977

969978
ctx_pub = pubnub_alloc();
@@ -1179,8 +1188,11 @@ void UPubnubSubsystem::UnsubscribeFromAll_priv()
11791188
}
11801189

11811190
LongpollThread->ClearLoopingFunctions();
1182-
1183-
SystemPublish(ChannelForSystemPublish);
1191+
1192+
if(!ChannelForSystemPublish.IsEmpty())
1193+
{
1194+
SystemPublish(ChannelForSystemPublish);
1195+
}
11841196
}
11851197

11861198
void UPubnubSubsystem::AddChannelToGroup_priv(FString ChannelName, FString ChannelGroup)

0 commit comments

Comments
 (0)