This is no longer segfaulting?

This commit is contained in:
Brandon Thomas
2021-02-16 00:23:25 -05:00
parent 5d00a246f5
commit 8404975662
2 changed files with 55 additions and 7 deletions
@@ -4,8 +4,11 @@
DEFINE_LOG_CATEGORY(EventSourceLog); DEFINE_LOG_CATEGORY(EventSourceLog);
AEventSourceActor::AEventSourceActor() AEventSourceActor::AEventSourceActor() :
redis(nullptr)
{ {
UE_LOG(EventSourceLog, Log, TEXT("CTOR()"));
// Set this actor to call Tick() every frame. // Set this actor to call Tick() every frame.
// You can turn this off to improve performance if you don't need it. // You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.bCanEverTick = true;
@@ -21,21 +24,27 @@ AEventSourceActor::~AEventSourceActor()
// TODO: Memory leak (somehow placing a BP derivation into the editor causes the below lines to segfault) // TODO: Memory leak (somehow placing a BP derivation into the editor causes the below lines to segfault)
//delete redis; //delete redis;
//redis = nullptr; //redis = nullptr;
/*if (redis != nullptr) {
delete redis;
redis = nullptr;
}*/
} }
void AEventSourceActor::BeginPlay() void AEventSourceActor::BeginPlay()
{ {
UE_LOG(EventSourceLog, Log, TEXT("BeginPlay()"));
Super::BeginPlay(); Super::BeginPlay();
UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis is null? %b"), redis != nullptr); UE_LOG(EventSourceLog, Log, TEXT("BeginPlay()"));
if (redis == nullptr) {
UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Creating redis instance"));
redis = NewObject<URedisObject>(this, TEXT("RedisObject"));
}
UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis is null? ? %d"), redis == nullptr);
//UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis host: %s"), redisHost); //UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis host: %s"), redisHost);
UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis port: %d"), redisPort); UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis port: %d"), redisPort);
//UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis password (no secrets): %s"), redisPassword); //UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis password (no secrets): %s"), redisPassword);
//redis->Init(redisHost, redisPort, redisPassword);
} }
void AEventSourceActor::BeginDestroy() void AEventSourceActor::BeginDestroy()
@@ -51,8 +60,39 @@ void AEventSourceActor::Tick(float DeltaTime)
//redis->Tick(DeltaTime); //redis->Tick(DeltaTime);
} }
void AEventSourceActor::ConstructClient()
{
if (redis != nullptr) {
UE_LOG(EventSourceLog, Log, TEXT("Construct(): Redis is NOT null"));
return;
}
UE_LOG(EventSourceLog, Log, TEXT("construct(): redis = new Redis()"));
redis = NewObject<URedisObject>(this, TEXT("RedisObject"));
}
void AEventSourceActor::Init()
{
if (redis == nullptr) {
UE_LOG(EventSourceLog, Log, TEXT("Init(): Redis is null"));
return;
}
UE_LOG(EventSourceLog, Log, TEXT("construct(): redis = new Redis()"));
redis = NewObject<URedisObject>(this, TEXT("RedisObject"));
UE_LOG(EventSourceLog, Log, TEXT("Init(): redis->Init()"));
redis->Init(redisHost, redisPort, redisPassword);
}
void AEventSourceActor::Subscribe(const FString& Channel) void AEventSourceActor::Subscribe(const FString& Channel)
{ {
if (redis == nullptr) {
UE_LOG(EventSourceLog, Log, TEXT("Subscribe(): Redis is null"));
return;
}
UE_LOG(EventSourceLog, Log, TEXT("Subscribe(): redis->Subscribe()"));
redis->Subscribe(Channel); redis->Subscribe(Channel);
} }
@@ -41,6 +41,14 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EventCenter") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EventCenter")
FString redisPassword; FString redisPassword;
/** Construct Redis Object.*/
UFUNCTION(BlueprintCallable, Category = "EventCenter")
void ConstructClient();
/** Connect to Redis.*/
UFUNCTION(BlueprintCallable, Category = "EventCenter")
void Init();
/** Subscribe to a named Redis PubSub channel. */ /** Subscribe to a named Redis PubSub channel. */
UFUNCTION(BlueprintCallable, Category = "EventCenter") UFUNCTION(BlueprintCallable, Category = "EventCenter")
void Subscribe(const FString& Channel); void Subscribe(const FString& Channel);