@@ -93,10 +93,14 @@ void ASofaContext::Destroyed()
9393 if (m_log)
9494 UE_LOG (SUnreal_log, Warning, TEXT (" ######### ASofaContext::Destroyed(): Delete SofaAdvancePhysicsAPI: %s" ), *this ->GetName ());
9595
96+ if (m_isMsgHandlerActivated == true )
97+ catchSofaMessages ();
98+
9699 UE_LOG (SUnreal_log, Warning, TEXT (" ## ASofaContext::BeginDestroy: m_sofaAPI stop" ));
97100 m_sofaAPI->stop ();
101+ m_sofaAPI->activateMessageHandler (false );
98102 UE_LOG (SUnreal_log, Warning, TEXT (" ## ASofaContext::BeginDestroy: m_sofaAPI stopped" ));
99- delete m_sofaAPI;
103+ // delete m_sofaAPI;
100104 m_sofaAPI = nullptr ;
101105 UE_LOG (SUnreal_log, Warning, TEXT (" ## ASofaContext::BeginDestroy: m_sofaAPI deleted" ));
102106 }
@@ -237,19 +241,18 @@ void ASofaContext::createSofaContext()
237241 // create a new sofa context through sofaAdvancePhysicsAPI
238242 if (m_sofaAPI == nullptr )
239243 {
240- // TSharedRef<SofaAdvancePhysicsAPI> apiRef(new SofaAdvancePhysicsAPI());
241- // m_data.m_sofaAPI = apiRef;
242- m_sofaAPI = new SofaAdvancePhysicsAPI ();
244+ m_sofaAPI = MakeShared<SofaAdvancePhysicsAPI>();
243245 UE_LOG (SUnreal_log, Warning, TEXT (" ## ASofaDAGNode::loadComponents TEST 12" ));
244- // TODO restore that
245- // m_sofaAPI->activateMessageHandler(m_isMsgHandlerActivated);
246246
247247 if (m_sofaAPI == nullptr )
248248 {
249249 UE_LOG (SUnreal_log, Error, TEXT (" ## ASofaContext::createSofaContext SofaAdvancePhysicsAPI creation failed." ));
250250 return ;
251251 }
252252
253+ // activate message handler
254+ m_sofaAPI->activateMessageHandler (m_isMsgHandlerActivated);
255+
253256 m_apiName = m_sofaAPI->APIName ();
254257
255258 if (m_log)
@@ -321,8 +324,8 @@ void ASofaContext::loadSofaScene()
321324 // Start parsing scene loaded in SOFA
322325 // Create the actor of the scene:
323326
324- // if (m_isMsgHandlerActivated == true)
325- // catchSofaMessages();
327+ if (m_isMsgHandlerActivated == true )
328+ catchSofaMessages ();
326329
327330 // m_status++;
328331}
@@ -340,8 +343,8 @@ void ASofaContext::loadDefaultPlugin()
340343 UE_LOG (SUnreal_log, Error, TEXT (" ## ASofaContext::createSofaContext: loadDefaultPlugin failed, returns: %d" ), resPlug);
341344 }
342345
343- // if (m_isMsgHandlerActivated == true)
344- // catchSofaMessages();
346+ if (m_isMsgHandlerActivated == true )
347+ catchSofaMessages ();
345348}
346349
347350
@@ -498,6 +501,9 @@ void ASofaContext::reconnectNodeGraph()
498501 dagNode->reconnectComponents (m_sofaAPI);
499502 }
500503 }
504+
505+ if (m_isMsgHandlerActivated == true )
506+ catchSofaMessages ();
501507}
502508
503509
@@ -523,12 +529,17 @@ void ASofaContext::clearNodeGraph()
523529void ASofaContext::catchSofaMessages ()
524530{
525531 int nbrMsgs = m_sofaAPI->getNbMessages ();
532+ UE_LOG (SUnreal_log, Warning, TEXT (" ## ASofaContext::catchSofaMessages: nbr message: %d" ), nbrMsgs);
533+
526534 int * type = new int [1 ];
527535 type[0 ] = -1 ;
536+ std::string rawMsg;
528537 for (int i = 0 ; i < nbrMsgs; ++i)
529538 {
530- const char * rawMsg = m_sofaAPI->getMessage (i, *type).c_str ();
531- FString FMessage (rawMsg);
539+
540+ // const char* rawMsg = m_sofaAPI->getMessage(i, *type).c_str();
541+ m_sofaAPI->getMessage_out (i, *type, rawMsg);
542+ FString FMessage (rawMsg.c_str ());
532543
533544 if (type[0 ] == -1 ) {
534545 continue ;
0 commit comments