#include "CmCoreObjectManager.h" #include "CmCoreObject.h" #include "CmException.h" namespace BansheeEngine { CoreObjectManager::CoreObjectManager() :mNextAvailableID(1) { } CoreObjectManager::~CoreObjectManager() { #if BS_DEBUG_MODE BS_LOCK_MUTEX(mObjectsMutex); if(mObjects.size() > 0) { // All objects MUST be destroyed at this point, otherwise there might be memory corruption. // (Reason: This is called on application shutdown and at that point we also unload any dynamic libraries, // which will invalidate any pointers to objects created from those libraries. Therefore we require of the user to // clean up all objects manually before shutting down the application). BS_EXCEPT(InternalErrorException, "Core object manager shut down, but not all objects were released. User must release ALL " \ "engine objects before application shutdown."); } #endif } UINT64 CoreObjectManager::registerObject(CoreObject* object) { assert(object != nullptr); BS_LOCK_MUTEX(mObjectsMutex); mObjects[mNextAvailableID] = object; return mNextAvailableID++; } void CoreObjectManager::unregisterObject(CoreObject* object) { assert(object != nullptr); BS_LOCK_MUTEX(mObjectsMutex); mObjects.erase(object->getInternalID()); } }