File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -399,15 +399,22 @@ namespace NMR {
399
399
// Retrieve a unique Resource ID
400
400
ModelResourceID CModel::generateResourceID ()
401
401
{
402
- // TODO: is this truly safe?
403
- auto iIterator = m_ResourceMap.rbegin ();
404
- if (iIterator != m_ResourceMap.rend ())
405
- return iIterator->first + 1 ;
406
- else
407
- return 1 ;
402
+ ModelResourceID highestID = 0 ;
403
+
404
+ if (m_ResourceMap.empty ())
405
+ {
406
+ return 1 ;
407
+ }
408
+
409
+ highestID = std::max_element (m_ResourceMap.begin (), m_ResourceMap.end (),
410
+ [](const auto &a, const auto &b) {
411
+ return a.first < b.first ;
412
+ })->first ;
413
+
414
+ return highestID + 1 ;
408
415
}
409
416
410
- void CModel::updateUniqueResourceID (UniqueResourceID nOldID, UniqueResourceID nNewID)
417
+ void CModel::updateUniqueResourceID (UniqueResourceID nOldID, UniqueResourceID nNewID)
411
418
{
412
419
if (m_ResourceMap.find (nNewID) != m_ResourceMap.end ()) {
413
420
throw CNMRException (NMR_ERROR_DUPLICATEMODELRESOURCE);
You can’t perform that action at this time.
0 commit comments