From 4a998821187327c32840101ccdb02f3f035fa436 Mon Sep 17 00:00:00 2001 From: LUCASTUCIOUS Date: Sun, 29 Sep 2024 15:00:36 +0200 Subject: [PATCH] fix some memory issues --- Source/SkyPortal/Private/SkyPortalIO.cpp | 6 ++++-- Source/SkyPortal/Private/SkyPortalSubsystem.cpp | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/SkyPortal/Private/SkyPortalIO.cpp b/Source/SkyPortal/Private/SkyPortalIO.cpp index 2dcb737..a3a4b3e 100644 --- a/Source/SkyPortal/Private/SkyPortalIO.cpp +++ b/Source/SkyPortal/Private/SkyPortalIO.cpp @@ -191,10 +191,12 @@ uint8* USkyPortalIO::QueryBlock(uint8 FigureIndex, uint8 BlockIndex) command.data[3] = BlockIndex; unsigned char* output = nullptr; int attempt=0; + bool write; do { attempt++; UE_LOG(LogSkyportalIO, Verbose, TEXT("Trying to write... attempt:%d"), attempt); - if (Write(&command)) { + write = Write(&command); + if (write) { output = Read(); if (output != nullptr && output != 0) { UE_LOG(LogSkyportalIO, Verbose, TEXT("Read success: output[0]=%d, output[1]=%d, output[2]=%d"), output[0], output[1], output[2]); @@ -204,7 +206,7 @@ uint8* USkyPortalIO::QueryBlock(uint8 FigureIndex, uint8 BlockIndex) } } - } while ((output[0] != 'Q' || (output[1] % 0x10 != FigureIndex && output[1] != 0x01) || output[2] != BlockIndex) && attempt < 10); + } while (write == false && (output[0] != 'Q' || (output[1] % 0x10 != FigureIndex && output[1] != 0x01) || output[2] != BlockIndex) && attempt < 10); UE_LOG(LogSkyportalIO, Verbose, TEXT("Querying block %d - success"), BlockIndex); UE_LOG(LogSkyportalIO, VeryVerbose, TEXT("Data block %d = \n %s"), BlockIndex,*OutputToString(output)); return output; diff --git a/Source/SkyPortal/Private/SkyPortalSubsystem.cpp b/Source/SkyPortal/Private/SkyPortalSubsystem.cpp index 83a8000..7a59cd1 100644 --- a/Source/SkyPortal/Private/SkyPortalSubsystem.cpp +++ b/Source/SkyPortal/Private/SkyPortalSubsystem.cpp @@ -5,6 +5,8 @@ #include "HAL/RunnableThread.h" #include "SkyPortalFigure.h" +#include +#include void USkyPortalSubsystem::Initialize(FSubsystemCollectionBase& Collection) @@ -259,7 +261,7 @@ bool USkyPortalSubsystem::IsPortalReady() void USkyPortalSubsystem::PortalAnalyzeAsync(const uint8 Index) { bShouldPauseRunner = true; - UE_LOG(LogSkyportalIO, Log, TEXT("Starting async figure analysis...")); + UE_LOG(LogSkyportalIO, Log, TEXT("Starting async figure analysis for index %d..."), Index); // Run the PortalAnalyze function asynchronously on a background thread AsyncTask(ENamedThreads::AnyBackgroundThreadNormalTask, [this, Index]()