CmCoreObjectManager.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "CmCoreObjectManager.h"
  2. #include "CmCoreObject.h"
  3. #include "CmException.h"
  4. namespace BansheeEngine
  5. {
  6. CoreObjectManager::CoreObjectManager()
  7. :mNextAvailableID(1)
  8. {
  9. }
  10. CoreObjectManager::~CoreObjectManager()
  11. {
  12. #if BS_DEBUG_MODE
  13. BS_LOCK_MUTEX(mObjectsMutex);
  14. if(mObjects.size() > 0)
  15. {
  16. // All objects MUST be destroyed at this point, otherwise there might be memory corruption.
  17. // (Reason: This is called on application shutdown and at that point we also unload any dynamic libraries,
  18. // which will invalidate any pointers to objects created from those libraries. Therefore we require of the user to
  19. // clean up all objects manually before shutting down the application).
  20. BS_EXCEPT(InternalErrorException, "Core object manager shut down, but not all objects were released. User must release ALL " \
  21. "engine objects before application shutdown.");
  22. }
  23. #endif
  24. }
  25. UINT64 CoreObjectManager::registerObject(CoreObject* object)
  26. {
  27. assert(object != nullptr);
  28. BS_LOCK_MUTEX(mObjectsMutex);
  29. mObjects[mNextAvailableID] = object;
  30. return mNextAvailableID++;
  31. }
  32. void CoreObjectManager::unregisterObject(CoreObject* object)
  33. {
  34. assert(object != nullptr);
  35. BS_LOCK_MUTEX(mObjectsMutex);
  36. mObjects.erase(object->getInternalID());
  37. }
  38. }