Skip to content

Commit 2b2cd0e

Browse files
authored
[src] Update SofaContext loading to split the node and component loading using gui button to track crash (#24)
1 parent eeec89f commit 2b2cd0e

2 files changed

Lines changed: 50 additions & 58 deletions

File tree

Source/SofaUE5/Private/SofaContext.cpp

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ void ASofaContext::createSofaContext()
240240
//TSharedRef<SofaAdvancePhysicsAPI> apiRef(new SofaAdvancePhysicsAPI());
241241
//m_data.m_sofaAPI = apiRef;
242242
m_sofaAPI = new SofaAdvancePhysicsAPI();
243-
UE_LOG(SUnreal_log, Warning, TEXT("## ASofaDAGNode::loadComponents TEST 11"));
243+
UE_LOG(SUnreal_log, Warning, TEXT("## ASofaDAGNode::loadComponents TEST 12"));
244244
// TODO restore that
245245
//m_sofaAPI->activateMessageHandler(m_isMsgHandlerActivated);
246246

@@ -278,15 +278,11 @@ void ASofaContext::createSofaContext()
278278
return;
279279
}
280280

281-
// Load default plugins
282-
FString pluginPaths = curPath + "Plugins/SofaUE5/Binaries/ThirdParty/SofaUE5Library/Win64";
283-
const char* pluginPchar = TCHAR_TO_ANSI(*pluginPaths);
284-
int resPlug = m_sofaAPI->loadDefaultPlugins(pluginPchar);
285-
if (resPlug != 0) {
286-
UE_LOG(SUnreal_log, Error, TEXT("## ASofaContext::createSofaContext: loadDefaultPlugin failed, returns: %d"), resPlug);
287-
}
281+
// Load default plugins at start before loading SOFA scene
282+
loadDefaultPlugin();
288283

289284

285+
// If file is already set will load directly the file
290286
if (!filePath.FilePath.IsEmpty()) {
291287
loadSofaScene();
292288

@@ -317,8 +313,7 @@ void ASofaContext::loadSofaScene()
317313
UE_LOG(SUnreal_log, Log, TEXT("## ASofaContext::loadSofaScene: Scene loading with success: %s"), *my_filePath);
318314
}
319315

320-
//FPlatformProcess::Sleep(0.01f);
321-
316+
322317
// Pass default scene parameter
323318
// this->setDT(Dt);
324319
// this->setGravity(Gravity);
@@ -332,28 +327,18 @@ void ASofaContext::loadSofaScene()
332327
//m_status++;
333328
}
334329

335-
void ASofaContext::mapSofaScene()
336-
{
337-
if (m_status == -1) {
338-
this->loadNodeGraph();
339-
}
340-
else
341-
{
342-
this->reconnectNodeGraph();
343-
344-
}
345-
m_status++;
346-
}
347-
348-
349330
void ASofaContext::loadDefaultPlugin()
350331
{
351332
if (m_sofaAPI == nullptr)
352333
return;
353334

354-
//m_sofaAPI->loadPlugin("C:/projects/UnrealEngine/SOFA_test2/Plugins/SofaUE5/Binaries/ThirdParty/SofaUE5Library/Win64/Sofa.Component.dll");
355-
//m_sofaAPI->loadPlugin("C:/projects/UnrealEngine/SOFA_test2/Plugins/SofaUE5/Binaries/ThirdParty/SofaUE5Library/Win64/Sofa.GL.Component.dll");
356-
//m_sofaAPI->loadPlugin("C:/projects/UnrealEngine/SOFA_test2/Plugins/SofaUE5/Binaries/ThirdParty/SofaUE5Library/Win64/Sofa.GUI.Component.dll");
335+
FString curPath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir());
336+
FString pluginPaths = curPath + "Plugins/SofaUE5/Binaries/ThirdParty/SofaUE5Library/Win64";
337+
const char* pluginPchar = TCHAR_TO_ANSI(*pluginPaths);
338+
int resPlug = m_sofaAPI->loadDefaultPlugins(pluginPchar);
339+
if (resPlug != 0) {
340+
UE_LOG(SUnreal_log, Error, TEXT("## ASofaContext::createSofaContext: loadDefaultPlugin failed, returns: %d"), resPlug);
341+
}
357342

358343
//if (m_isMsgHandlerActivated == true)
359344
// catchSofaMessages();
@@ -398,7 +383,7 @@ void ASofaContext::loadNodeGraph()
398383
FString fs_nodeDisplayName(nodeDisplayName.c_str());
399384

400385
FActorSpawnParameters SpawnParams;
401-
//SpawnParams.Name = MakeUniqueObjectName(World, ASofaDAGNode::StaticClass(), FName(*fs_nodeDisplayName));
386+
SpawnParams.Name = MakeUniqueObjectName(World, ASofaDAGNode::StaticClass(), FName(*fs_nodeDisplayName));
402387
SpawnParams.Owner = this;
403388

404389
ASofaDAGNode* dagNode = World->SpawnActorDeferred<ASofaDAGNode>(
@@ -411,9 +396,6 @@ void ASofaContext::loadNodeGraph()
411396

412397
if (dagNode != nullptr)
413398
{
414-
//FAttachmentTransformRules att = FAttachmentTransformRules(EAttachmentRule::KeepRelative, true);
415-
//dagNode->AttachToActor(this, FAttachmentTransformRules::KeepRelativeTransform);
416-
417399
std::string parentNameId = "";
418400
int resParentNameId = m_sofaAPI->getDAGNodeParentAPIName_out(nodeUniqID, parentNameId);
419401
if (resParentNameId != 0)
@@ -446,8 +428,10 @@ void ASofaContext::loadNodeGraph()
446428

447429
const FString& parentName = dagNode->getParentName();
448430
auto res = parentName.Compare("None");
449-
if (res == 0)
431+
if (res == 0) {
432+
dagNode->AttachToActor(this, FAttachmentTransformRules::KeepRelativeTransform);
450433
continue;
434+
}
451435

452436
for (auto& WeakOther : m_dagNodes)
453437
{
@@ -461,6 +445,12 @@ void ASofaContext::loadNodeGraph()
461445
}
462446
}
463447

448+
m_status++;
449+
}
450+
451+
452+
void ASofaContext::loadSofaComponents()
453+
{
464454
UE_LOG(SUnreal_log, Warning, TEXT("## ASofaContext::loadNodeGraph: Load all components | nbr Nodes: %d"), m_dagNodes.Num());
465455
// Load Components Graph
466456
for (auto& WeakDagNode : m_dagNodes)
@@ -470,7 +460,6 @@ void ASofaContext::loadNodeGraph()
470460
dagNode->loadComponents(m_sofaAPI);
471461
}
472462
}
473-
474463
}
475464

476465

Source/SofaUE5/Public/SofaContext.h

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,13 @@ class SOFAUE5_API ASofaContext : public AActor
4545
// Called when the game starts or when spawned
4646
virtual void BeginPlay() override;
4747

48+
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
49+
4850

4951
public:
5052
// Sets default values for this actor's properties
5153
ASofaContext();
5254

53-
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
54-
55-
UFUNCTION(CallInEditor, Category = "Sofa")
56-
void loadSofaScene();
57-
58-
UFUNCTION(CallInEditor, Category = "Sofa")
59-
void mapSofaScene();
60-
61-
#if WITH_EDITOR
62-
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
63-
#endif
64-
6555
// Called every frame
6656
virtual void Tick( float DeltaSeconds ) override;
6757

@@ -70,33 +60,46 @@ class SOFAUE5_API ASofaContext : public AActor
7060
void setGravity(FVector value);
7161

7262
public:
73-
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sofa Parameters")
74-
FFilePath filePath;
63+
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sofa")
64+
FFilePath filePath;
65+
66+
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sofa")
67+
float Dt;
68+
69+
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sofa")
70+
FVector Gravity;
7571

76-
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sofa Parameters")
77-
float Dt;
72+
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sofa")
73+
bool m_isMsgHandlerActivated = false;
7874

79-
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sofa Parameters")
80-
FVector Gravity;
75+
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sofa")
76+
bool m_log = true;
8177

82-
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sofa Parameters")
83-
bool m_isMsgHandlerActivated = false;
78+
UFUNCTION(CallInEditor, Category = "Sofa")
79+
void loadNodeGraph();
8480

85-
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sofa Parameters")
86-
bool m_log = true;
81+
UFUNCTION(CallInEditor, Category = "Sofa")
82+
void loadSofaComponents();
8783

88-
protected:
89-
void catchSofaMessages();
84+
#if WITH_EDITOR
85+
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
86+
#endif
9087

88+
protected:
9189
void createSofaContext();
9290

91+
// Internal method to load SOFA scene inside the SofaContext
92+
void loadSofaScene();
9393

94+
// Method to internally load SOFA default plugin dll
9495
void loadDefaultPlugin();
9596

96-
void loadNodeGraph();
97+
9798
void reconnectNodeGraph();
9899
void clearNodeGraph();
99100

101+
void catchSofaMessages();
102+
100103
private:
101104
int32 m_dllLoadStatus;
102105
FString m_apiName;

0 commit comments

Comments
 (0)