core: Add assert and debugging message to catch ObjectFactory errors

This commit is contained in:
Tom Henderson
2024-02-13 20:50:05 -08:00
committed by Tommaso Pecorella
parent 2f160894a6
commit 27aa41e454
2 changed files with 5 additions and 1 deletions

View File

@@ -93,6 +93,9 @@ Ptr<Object>
ObjectFactory::Create() const
{
NS_LOG_FUNCTION(this);
NS_ASSERT_MSG(
m_tid.GetUid(),
"ObjectFactory::Create - can't use an ObjectFactory without setting a TypeId first.");
Callback<ObjectBase*> cb = m_tid.GetConstructor();
ObjectBase* base = cb();
auto derived = dynamic_cast<Object*>(base);

View File

@@ -457,7 +457,8 @@ IidManager::IidInformation*
IidManager::LookupInformation(uint16_t uid) const
{
NS_LOG_FUNCTION(IID << uid);
NS_ASSERT(uid <= m_information.size() && uid != 0);
NS_ASSERT_MSG(uid <= m_information.size() && uid != 0,
"The uid " << uid << " for this TypeId is invalid");
NS_LOG_LOGIC(IIDL << m_information[uid - 1].name);
return const_cast<IidInformation*>(&m_information[uid - 1]);
}