CmCoreObjectManager.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. CM_LOCK_MUTEX(mObjectsMutex);
  13. if(mObjects.size() > 0)
  14. {
  15. // All objects MUST be destroyed at this point, otherwise there might be memory corruption.
  16. // (Reason: This is called on application shutdown and at that point we also unload any dynamic libraries,
  17. // which will invalidate any pointers to objects created from those libraries. Therefore we require of the user to
  18. // clean up all objects manually before shutting down the application).
  19. CM_EXCEPT(InternalErrorException, "Core GPU object manager destroyed, but not all objects were released. User must release ALL " \
  20. "engine objects before application shutdown.");
  21. }
  22. }
  23. UINT64 CoreObjectManager::registerObject(CoreObject* object)
  24. {
  25. assert(object != nullptr);
  26. CM_LOCK_MUTEX(mObjectsMutex);
  27. mObjects[mNextAvailableID] = object;
  28. return mNextAvailableID++;
  29. }
  30. void CoreObjectManager::unregisterObject(CoreObject* object)
  31. {
  32. assert(object != nullptr);
  33. CM_LOCK_MUTEX(mObjectsMutex);
  34. mObjects.erase(object->getInternalID());
  35. }
  36. }