debug option to track Entities (#2526)

* debug option to track Entities

Set FILAMENT_UTILS_TRACK_ENTITIES to true when building libutils to
activate entity tracking. This adds two public methods:

getActiveEntities() and dumpActiveEntities() the later displays the
stack trace of where the remaining entities were allocated.

This is useful for tracking leaks.

* Update libs/utils/include/utils/EntityManager.h

Co-authored-by: Philip Rideout <philiprideout@gmail.com>

Co-authored-by: Philip Rideout <philiprideout@gmail.com>
This commit is contained in:
Mathias Agopian
2020-05-12 17:55:39 -07:00
committed by GitHub
parent d08a4e8bd9
commit ee3c3d0965
3 changed files with 65 additions and 2 deletions

View File

@@ -14,6 +14,8 @@
* limitations under the License.
*/
#include <utils/EntityManager.h>
#include "EntityManagerImpl.h"
namespace utils {
@@ -28,6 +30,8 @@ EntityManager::~EntityManager() {
delete [] mGens;
}
EntityManager::Listener::~Listener() noexcept = default;
EntityManager& EntityManager::get() noexcept {
// note: we leak the EntityManager because it's more important that it survives everything else
// the leak is really not a problem because the process is terminating anyways.
@@ -51,4 +55,15 @@ void EntityManager::unregisterListener(EntityManager::Listener* l) noexcept {
static_cast<EntityManagerImpl *>(this)->unregisterListener(l);
}
#if FILAMENT_UTILS_TRACK_ENTITIES
std::vector<Entity> EntityManager::getActiveEntities() const {
return static_cast<EntityManagerImpl const *>(this)->getActiveEntities();
}
void EntityManager::dumpActiveEntities(utils::io::ostream& out) const {
static_cast<EntityManagerImpl const *>(this)->dumpActiveEntities(out);
}
#endif
} // namespace utils