Clears the user data cache when syncUserData is called.

Adds unit test for the UserData functons.
Changes the char pointer in btHashString to std::string. There were
problems where the object owning the string memory would deallocate the
string, making the btHashString object invalid.
This commit is contained in:
Tigran Gasparian
2018-06-04 15:10:48 +02:00
parent e0667d8579
commit bb72a91080
4 changed files with 259 additions and 2 deletions

View File

@@ -1385,6 +1385,15 @@ const SharedMemoryStatus* PhysicsClientSharedMemory::processServerStatus() {
if (serverCmd.m_type == CMD_SYNC_USER_DATA_COMPLETED) {
B3_PROFILE("CMD_SYNC_USER_DATA_COMPLETED");
// Remove all cached user data entries.
for(int i=0; i<m_data->m_bodyJointMap.size(); i++)
{
BodyJointInfoCache** bodyJointsPtr = m_data->m_bodyJointMap.getAtIndex(i);
if (bodyJointsPtr && *bodyJointsPtr)
{
(*bodyJointsPtr)->m_jointToUserDataMap.clear();
}
}
const int numIdentifiers = serverCmd.m_syncUserDataArgs.m_numUserDataIdentifiers;
if (numIdentifiers > 0) {
m_data->m_tempBackupServerStatus = m_data->m_lastServerStatus;

View File

@@ -695,6 +695,7 @@ void PhysicsDirect::processAddUserData(const struct SharedMemoryStatus& serverCm
(userDataCachePtr)->m_userDataMap.insert(userDataGlobalId.m_userDataId, SharedMemoryUserData(serverCmd.m_userDataResponseArgs.m_key));
userDataPtr = (userDataCachePtr)->m_userDataMap[userDataGlobalId.m_userDataId];
userDataPtr->replaceValue(dataStream,serverCmd.m_userDataResponseArgs.m_valueLength,userDataValue.m_type);
(userDataCachePtr)->m_keyToUserDataIdMap.insert(serverCmd.m_userDataResponseArgs.m_key, userDataGlobalId.m_userDataId);
}
}
}
@@ -1127,6 +1128,15 @@ void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd
case CMD_SYNC_USER_DATA_COMPLETED:
{
B3_PROFILE("CMD_SYNC_USER_DATA_COMPLETED");
// Remove all cached user data entries.
for(int i=0; i<m_data->m_bodyJointMap.size(); i++)
{
BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap.getAtIndex(i);
if (bodyJointsPtr && *bodyJointsPtr)
{
(*bodyJointsPtr)->m_jointToUserDataMap.clear();
}
}
const int numIdentifiers = serverCmd.m_syncUserDataArgs.m_numUserDataIdentifiers;
b3UserDataGlobalIdentifier *identifiers = new b3UserDataGlobalIdentifier[numIdentifiers];
memcpy(identifiers, &m_data->m_bulletStreamDataServerToClient[0], numIdentifiers * sizeof(b3UserDataGlobalIdentifier));