@@ -30,7 +30,9 @@ void CScriptStoryIDManager::VerifiedRegisterObject(CSE_Abstract* se_obj)
3030 R_ASSERT3 (false , " There is no 'story_id' field in [story_object] section :object" , se_obj->name ());
3131 }
3232 if (value)
33+ {
3334 self.Register (se_obj->ID , value);
35+ }
3436 return ;
3537 }
3638 auto story_id = READ_IF_EXISTS (pSettings, r_string, se_obj->name (), " story_id" , nullptr );
@@ -92,31 +94,38 @@ void CScriptStoryIDManager::script_register(lua_State* L)
9294void CScriptStoryIDManager::Register (ALife::_OBJECT_ID obj_id, shared_str script_story_id)
9395{
9496 xrSRWLockGuard guard (m_containers_lock);
97+ VERIFY (m_containers_by_id.size () == m_containers_by_script_story_id.size ());
98+ auto Finally = xr_scope_exit ([this ]()
99+ {
100+ VERIFY (m_containers_by_id.size () == m_containers_by_script_story_id.size ());
101+ });
95102 auto ByIDIt = m_containers_by_id.find (obj_id);
96103 auto ByScriptStoryIDIt = m_containers_by_script_story_id.find (script_story_id);
97104 if (ByScriptStoryIDIt != m_containers_by_script_story_id.end () && ByScriptStoryIDIt->second != obj_id)
98105 {
99- xr_string message = " You are trying to spawn two or more objects with the same story_id:[ " ;
100- message. append (script_story_id. c_str () );
101- message. append ( " ] --> [ " );
102- auto ExistName = ai (). alife (). objects (). object (ByScriptStoryIDIt-> second )-> name ();
103- message. append (ExistName);
104- message. append ( " ] try to add:[ " );
105- auto NewName = ai (). alife (). objects (). object (obj_id) ->name ();
106- message. append (NewName);
107- message. append ( " ] " );
108- R_ASSERT2 (ByScriptStoryIDIt == m_containers_by_script_story_id. end (), message. c_str () );
106+ auto ObjExist = ai (). alife (). objects (). object (ByScriptStoryIDIt-> second ) ;
107+ auto ObjNew = ai (). alife (). objects (). object (obj_id );
108+ I_ASSERT_M ( false ,
109+ " You are trying to spawn two or more objects with the same story_id [%s]: Old Obj [%d][%s], New obj [%d][%s] " ,
110+ script_story_id. c_str (),
111+ ObjExist-> ID ,
112+ ObjExist ->name (),
113+ std::to_string (ObjNew-> ID ),
114+ ObjNew-> name ()
115+ );
109116 }
110117 if (ByIDIt != m_containers_by_id.end ()){
111118 VERIFY (ByScriptStoryIDIt != m_containers_by_script_story_id.end ());
112119 if (ByScriptStoryIDIt->first != script_story_id){
113- xr_string message = " Object [" ;
114- message.append (script_story_id.c_str ());
115- message.append (" ] is already in story_objects_registry with story_id[" );
116- message.append (ByIDIt->second .c_str ());
117- R_ASSERT2 (ByScriptStoryIDIt != m_containers_by_script_story_id.end (), message.c_str ());
120+ I_ASSERT_M (false ,
121+ " Object [%d][%s] is already in story_objects_registry with story_id [%s]" ,
122+ ByIDIt->first ,
123+ script_story_id.c_str (),
124+ ByIDIt->second .c_str ()
125+ );
118126 }else
119127 {
128+ VERIFY (m_containers_by_id.size () == m_containers_by_script_story_id.size ());
120129 return ;
121130 }
122131 }
@@ -127,6 +136,11 @@ void CScriptStoryIDManager::Register(ALife::_OBJECT_ID obj_id, shared_str script
127136void CScriptStoryIDManager::Unregister (ALife::_OBJECT_ID obj_id)
128137{
129138 xrSRWLockGuard guard (m_containers_lock);
139+ VERIFY (m_containers_by_id.size () == m_containers_by_script_story_id.size ());
140+ auto Finally = xr_scope_exit ([this ]()
141+ {
142+ VERIFY (m_containers_by_id.size () == m_containers_by_script_story_id.size ());
143+ });
130144 if (m_containers_by_id.contains (obj_id)){
131145 auto elem = *m_containers_by_id.find (obj_id);
132146 m_containers_by_id.erase (elem.first );
@@ -137,6 +151,11 @@ void CScriptStoryIDManager::Unregister(ALife::_OBJECT_ID obj_id)
137151void CScriptStoryIDManager::Unregister (LPCSTR script_story_id)
138152{
139153 xrSRWLockGuard guard (m_containers_lock);
154+ VERIFY (m_containers_by_id.size () == m_containers_by_script_story_id.size ());
155+ auto Finally = xr_scope_exit ([this ]()
156+ {
157+ VERIFY (m_containers_by_id.size () == m_containers_by_script_story_id.size ());
158+ });
140159 if (m_containers_by_script_story_id.contains (script_story_id)){
141160 auto elem = *m_containers_by_script_story_id.find (script_story_id);
142161 m_containers_by_id.erase (elem.second );
@@ -147,13 +166,15 @@ void CScriptStoryIDManager::Unregister(LPCSTR script_story_id)
147166ALife::_OBJECT_ID CScriptStoryIDManager::GetID (LPCSTR script_story_id) const
148167{
149168 xrSRWLockGuard guard (m_containers_lock, true );
169+ VERIFY (m_containers_by_id.size () == m_containers_by_script_story_id.size ());
150170 auto it = m_containers_by_script_story_id.find (script_story_id);
151171 return it != m_containers_by_script_story_id.end () ? it->second : ALife::_OBJECT_ID (-1 );
152172}
153173
154174LPCSTR CScriptStoryIDManager::GetID (ALife::_OBJECT_ID obj_id) const
155175{
156176 xrSRWLockGuard guard (m_containers_lock, true );
177+ VERIFY (m_containers_by_id.size () == m_containers_by_script_story_id.size ());
157178 auto it = m_containers_by_id.find (obj_id);
158179 return it != m_containers_by_id.end () ? it->second .c_str () : nullptr ;
159180}
0 commit comments