fix some memory issues

This commit is contained in:
Lucas 2024-09-29 15:00:36 +02:00
parent a377bf6f00
commit 4a99882118
2 changed files with 7 additions and 3 deletions

View file

@ -191,10 +191,12 @@ uint8* USkyPortalIO::QueryBlock(uint8 FigureIndex, uint8 BlockIndex)
command.data[3] = BlockIndex; command.data[3] = BlockIndex;
unsigned char* output = nullptr; unsigned char* output = nullptr;
int attempt=0; int attempt=0;
bool write;
do { do {
attempt++; attempt++;
UE_LOG(LogSkyportalIO, Verbose, TEXT("Trying to write... attempt:%d"), attempt); UE_LOG(LogSkyportalIO, Verbose, TEXT("Trying to write... attempt:%d"), attempt);
if (Write(&command)) { write = Write(&command);
if (write) {
output = Read(); output = Read();
if (output != nullptr && output != 0) { 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]); 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, Verbose, TEXT("Querying block %d - success"), BlockIndex);
UE_LOG(LogSkyportalIO, VeryVerbose, TEXT("Data block %d = \n %s"), BlockIndex,*OutputToString(output)); UE_LOG(LogSkyportalIO, VeryVerbose, TEXT("Data block %d = \n %s"), BlockIndex,*OutputToString(output));
return output; return output;

View file

@ -5,6 +5,8 @@
#include "HAL/RunnableThread.h" #include "HAL/RunnableThread.h"
#include "SkyPortalFigure.h" #include "SkyPortalFigure.h"
#include <Async/TaskGraphInterfaces.h>
#include <Async/Async.h>
void USkyPortalSubsystem::Initialize(FSubsystemCollectionBase& Collection) void USkyPortalSubsystem::Initialize(FSubsystemCollectionBase& Collection)
@ -259,7 +261,7 @@ bool USkyPortalSubsystem::IsPortalReady()
void USkyPortalSubsystem::PortalAnalyzeAsync(const uint8 Index) void USkyPortalSubsystem::PortalAnalyzeAsync(const uint8 Index)
{ {
bShouldPauseRunner = true; 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 // Run the PortalAnalyze function asynchronously on a background thread
AsyncTask(ENamedThreads::AnyBackgroundThreadNormalTask, [this, Index]() AsyncTask(ENamedThreads::AnyBackgroundThreadNormalTask, [this, Index]()