Skip to content

Conversation

vijaiaeroastro
Copy link
Collaborator

This PR addresses the following issues:

#380
#355
#183

In Microsoft 3D Builder, object IDs seem to start from 2, which affects the CModel::generateResourceID() function, causing it to generate duplicate resource IDs. This PR fixes the issue by checking the model resource IDs from the package and incrementing them accordingly to avoid collisions. Current tests show that it maintains the OPC package IDs correctly, incrementing them as needed. As a result, users will not notice any difference when the file is written out.

Feedback is welcome.

Copy link

codecov bot commented Aug 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.11%. Comparing base (2601a62) to head (267ec28).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #386   +/-   ##
========================================
  Coverage    71.10%   71.11%           
========================================
  Files          271      271           
  Lines        30307    30317   +10     
========================================
+ Hits         21551    21561   +10     
  Misses        8756     8756           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

ModelResourceID CModel::generateResourceID()
{
// Build a map with existing resource IDs
std::map<ModelResourceID, bool> existingResourceIDs;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be a std::unordered_set. since we dont use the bool value.

Copy link
Collaborator Author

@vijaiaeroastro vijaiaeroastro Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gangatp unordered_set won't sort the ModelResourceID's right ?
I am picking the new id from the map using a reverse iterator.

Would you be okay with std::set instead ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear this is a major bottleneck as it will build up the map every time "generateresourceID" is called.
It would be much easier to store a m_MaxResourceID in the model that is updated whenever we add a resource.

Copy link
Collaborator Author

@vijaiaeroastro vijaiaeroastro Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexanderoster I thought about this too. I can just populate it once and then simply reuse it or just store a m_MaxResourceID. m_Resources doesn't change after a model is read. So, it can be only read once and then reused.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was wrong in assuming this.. i will implement a m_MaxResourceID instead.

@vijaiaeroastro
Copy link
Collaborator Author

@gangatp @alexanderoster I have made the changes. Kindly review and let me know if this is what you were looking for.

@vijaiaeroastro vijaiaeroastro requested a review from gangatp August 16, 2024 16:58
else
return 1;
}
// Ensure the generated ID is unique
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to update m_maxResourceId here, if currentResourceId > m_maxResourceId ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests pass with this. m_MaxResourceID tracks the maximum of package id only. There is only a single collision scenario when ids don't start from 1.

I think incrementing m_maxResourceID here would make it skip even more ids.

Copy link

@jaimemachado jaimemachado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what we are doing at our internal version at HP

ModelResourceID CModel::generateResourceID()
{
// TODO: is this truly safe?
ModelResourceID ret{ 0 };
for ( const auto & it : m_ResourceMap )
{
ret = std::max(ret, it.second->getPackageResourceID()->getModelResourceID());
}
return ret + 1;
}

@gangatp
Copy link
Collaborator

gangatp commented Aug 19, 2024

This is what we are doing at our internal version at HP

ModelResourceID CModel::generateResourceID() { // TODO: is this truly safe? ModelResourceID ret{ 0 }; for ( const auto & it : m_ResourceMap ) { ret = std::max(ret, it.second->getPackageResourceID()->getModelResourceID()); } return ret + 1; }

Thanks for sharing. We are implementing in a similar way.

@vijaiaeroastro
Copy link
Collaborator Author

Resolves #380, Resolves #355, Resolves #183

@vijaiaeroastro vijaiaeroastro merged commit 21f793d into develop Aug 19, 2024
42 checks passed
@vijaiaeroastro vijaiaeroastro deleted the vijai/resourceids branch August 19, 2024 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants