Fixed new response system sometimes crashing on rule lookup when the system is reloaded by rr_reloadresponsesystems or map-specific talker files

This commit is contained in:
Blixibon 2021-04-07 13:50:05 -05:00
parent aa4d02fcbf
commit 80c26ea186
3 changed files with 22 additions and 0 deletions

View File

@ -246,7 +246,12 @@ void CResponseSystem::Clear()
{
m_Responses.RemoveAll();
m_Criteria.RemoveAll();
#ifdef MAPBASE
// Must purge to avoid issues with reloading the system
m_RulePartitions.PurgeAndDeleteElements();
#else
m_RulePartitions.RemoveAll();
#endif
m_Enumerations.RemoveAll();
}

View File

@ -88,6 +88,20 @@ void ResponseRulePartition::RemoveAll( void )
}
}
#ifdef MAPBASE
void ResponseRulePartition::PurgeAndDeleteElements()
{
for ( int bukkit = 0 ; bukkit < N_RESPONSE_PARTITIONS ; ++bukkit )
{
for ( int i = m_RuleParts[bukkit].FirstInorder(); i != m_RuleParts[bukkit].InvalidIndex(); i = m_RuleParts[bukkit].NextInorder( i ) )
{
delete m_RuleParts[bukkit][ i ];
}
m_RuleParts[bukkit].Purge();
}
}
#endif
// don't bucket "subject" criteria that prefix with operators, since stripping all that out again would
// be a big pain, and the most important rules that need subjects are tlk_remarks anyway.
static inline bool CanBucketBySubject( const char * RESTRICT pszSubject )

View File

@ -433,6 +433,9 @@ namespace ResponseRules
// dump everything.
void RemoveAll();
#ifdef MAPBASE
void PurgeAndDeleteElements();
#endif
inline Rule &operator[]( tIndex idx );
int Count( void ); // number of elements inside, but you can't iterate from 0 to this