@@ -69,6 +69,7 @@ void ASofaContext::OnConstruction(const FTransform& Transform)
6969 Super::OnConstruction (Transform);
7070
7171#if WITH_EDITOR
72+ UE_LOG (SUnreal_log, Log, TEXT (" ########## ASofaContext:: BEfore createSofaContext: %s | %s ##########" ), *this ->GetName (), *LexToString (this ->GetFlags ()));
7273 if (m_sofaAPI == nullptr )
7374 {
7475 createSofaContext ();
@@ -93,15 +94,16 @@ void ASofaContext::Destroyed()
9394 // First stop SOFA simulation
9495 m_sofaAPI->stop ();
9596
96- if (m_isMsgHandlerActivated == true )
97- catchSofaMessages ();
97+ // if (m_isMsgHandlerActivated == true)
98+ // catchSofaMessages();
9899
99100 if (m_log)
100101 UE_LOG (SUnreal_log, Log, TEXT (" ## ASofaContext::BeginDestroy: m_sofaAPI stopped" ));
101102
102- // Deactivate message handler
103+ // Deactivate message handler
103104 m_sofaAPI->activateMessageHandler (false );
104- // Free SOFA context Ptr
105+
106+ // Free SOFA context Ptr
105107 m_sofaAPI.Reset ();
106108
107109 if (m_log)
@@ -134,6 +136,9 @@ void ASofaContext::BeginPlay()
134136
135137 // Start SOFA simulation on UE play
136138 m_sofaAPI->start ();
139+
140+ if (m_isMsgHandlerActivated == true )
141+ catchSofaMessages ();
137142 }
138143 else
139144 {
@@ -153,8 +158,8 @@ void ASofaContext::EndPlay(const EEndPlayReason::Type EndPlayReason)
153158 // Stop SOFA simulation on UE play
154159 m_sofaAPI->stop ();
155160
156- if (m_isMsgHandlerActivated == true )
157- catchSofaMessages ();
161+ if (m_isMsgHandlerActivated == true )
162+ catchSofaMessages ();
158163 }
159164
160165 Super::EndPlay (EndPlayReason);
@@ -214,12 +219,14 @@ void ASofaContext::Tick( float DeltaTime )
214219{
215220 if (m_status != -1 && m_sofaAPI)
216221 {
217- // Step SOFA simulation on each UE tick
222+ // Step SOFA simulation on each UE tick
218223 m_sofaAPI->step ();
219224
220- float value = this ->GetGameTimeSinceCreation ();
221225 // double stime = m_sofaAPI->getTime();
222-
226+
227+ // if (m_isMsgHandlerActivated == true)
228+ // catchSofaMessages();
229+ float value = this ->GetGameTimeSinceCreation ();
223230 // UE_LOG(LogTemp, Warning, TEXT("## ASofaContext: Tick: %f %f"), value, stime);
224231 }
225232
@@ -231,8 +238,8 @@ void ASofaContext::Tick( float DeltaTime )
231238
232239void ASofaContext::createSofaContext ()
233240{
234- if (m_log)
235- UE_LOG (SUnreal_log, Log, TEXT (" ########## ASofaContext::createSofaContext: %s | %s ##########" ), *this ->GetName (), *LexToString (this ->GetFlags ()));
241+ // if (m_log)
242+ UE_LOG (SUnreal_log, Log, TEXT (" ########## ASofaContext::createSofaContext: %s | %s ##########" ), *this ->GetName (), *LexToString (this ->GetFlags ()));
236243
237244 if (m_sofaAPI != nullptr ) {
238245 UE_LOG (SUnreal_log, Error, TEXT (" ## ASofaContext::createSofaContext is called with a SofaAPI already created." ));
@@ -324,39 +331,48 @@ void ASofaContext::loadSofaScene()
324331 // Pass default scene parameter
325332 // this->setDT(Dt);
326333 // this->setGravity(Gravity);
327-
328- // Start parsing scene loaded in SOFA
329- // Create the actor of the scene:
330334
331335 if (m_isMsgHandlerActivated == true )
332336 catchSofaMessages ();
333-
334- // m_status++;
335337}
336338
337339void ASofaContext::loadDefaultPlugin ()
338340{
339341 if (m_sofaAPI == nullptr )
340342 return ;
341343
344+ bool debugMode = false ;
345+
346+ #if (UE_BUILD_DEBUG || UE_BUILD_DEVELOPMENT) && !UE_BUILD_SHIPPING
347+ debugMode = true ;
348+ #endif
349+
342350 FString curPath = FPaths::ConvertRelativePathToFull (FPaths::ProjectDir ());
343- FString pluginPaths = curPath + " Plugins/SofaUE5/Binaries/ThirdParty/SofaUE5Library/Win64" ;
351+ FString pluginPaths;
352+ if (debugMode)
353+ pluginPaths = curPath + " Plugins/SofaUE5/Binaries/ThirdParty/SofaUE5Library/Win64/Debug/" ;
354+ else
355+ pluginPaths = curPath + " Plugins/SofaUE5/Binaries/ThirdParty/SofaUE5Library/Win64/Release/" ;
356+
344357 const char * pluginPchar = TCHAR_TO_ANSI (*pluginPaths);
345358 int resPlug = m_sofaAPI->loadDefaultPlugins (pluginPchar);
346359 if (resPlug != 0 ) {
347360 UE_LOG (SUnreal_log, Error, TEXT (" ## ASofaContext::createSofaContext: loadDefaultPlugin failed, returns: %d" ), resPlug);
348361 }
349362
350- if (m_isMsgHandlerActivated == true )
351- catchSofaMessages ();
363+ // if (m_isMsgHandlerActivated == true)
364+ // catchSofaMessages();
352365}
353366
354367
368+ // Start parsing scene loaded in SOFA
369+ // Create the actor of the scene:
370+
355371void ASofaContext::loadNodeGraph ()
356372{
357373 if (m_sofaAPI == nullptr )
358374 return ;
359-
375+
360376 clearNodeGraph ();
361377
362378 int nbrNode = m_sofaAPI->getNbrDAGNode ();
@@ -540,25 +556,23 @@ void ASofaContext::catchSofaMessages()
540556{
541557 int nbrMsgs = m_sofaAPI->getNbMessages ();
542558 UE_LOG (SUnreal_log, Warning, TEXT (" ## ASofaContext::catchSofaMessages: nbr message: %d" ), nbrMsgs);
543-
544- int * type = new int [1 ];
545- type[0 ] = -1 ;
546- std::string rawMsg;
559+
547560 for (int i = 0 ; i < nbrMsgs; ++i)
548561 {
549- m_sofaAPI->getMessage_out (i, *type, rawMsg);
562+ std::string rawMsg;
563+ int type = m_sofaAPI->getMessage_out (i, rawMsg);
550564 FString FMessage (rawMsg.c_str ());
551565
552- if (type[ 0 ] == -1 ) {
566+ if (type == -1 ) {
553567 continue ;
554568 }
555- else if (type[ 0 ] == 3 ) {
569+ else if (type == 3 ) {
556570 UE_LOG (SofaLog, Warning, TEXT (" %s" ), *FMessage);
557571 }
558- else if (type[ 0 ] == 4 ) {
572+ else if (type == 4 ) {
559573 UE_LOG (SofaLog, Error, TEXT (" %s" ), *FMessage);
560574 }
561- else if (type[ 0 ] == 5 ) {
575+ else if (type == 5 ) {
562576 UE_LOG (SofaLog, Fatal, TEXT (" %s" ), *FMessage);
563577 }
564578 else {
@@ -567,6 +581,4 @@ void ASofaContext::catchSofaMessages()
567581 }
568582
569583 m_sofaAPI->clearMessages ();
570-
571- delete[] type;
572584}
0 commit comments