Commit 19900d6f by Nicolas Capens

Check for GL object leaks at termination.

Change-Id: I8215fabe92d11f0f28cae9ffadd8c48a3fbf1f27 Reviewed-on: https://swiftshader-review.googlesource.com/3890Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 78696bf0
...@@ -19,15 +19,27 @@ ...@@ -19,15 +19,27 @@
namespace gl namespace gl
{ {
#ifndef NDEBUG
std::set<Object*> Object::instances;
#endif
Object::Object() Object::Object()
{ {
referenceCount = 0; referenceCount = 0;
#ifndef NDEBUG
instances.insert(this);
#endif
} }
Object::~Object() Object::~Object()
{ {
ASSERT(referenceCount == 0); ASSERT(referenceCount == 0);
#ifndef NDEBUG
ASSERT(instances.find(this) != instances.end()); // Check for double deletion
instances.erase(this);
#endif
} }
void Object::addRef() void Object::addRef()
...@@ -58,4 +70,16 @@ NamedObject::~NamedObject() ...@@ -58,4 +70,16 @@ NamedObject::~NamedObject()
{ {
} }
#ifndef NDEBUG
struct ObjectLeakCheck
{
~ObjectLeakCheck()
{
ASSERT(Object::instances.empty()); // Check for GL object leak at termination
}
};
static ObjectLeakCheck objectLeakCheck;
#endif
} }
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "common/debug.h" #include "common/debug.h"
#include <set>
typedef unsigned int GLuint; typedef unsigned int GLuint;
namespace gl namespace gl
...@@ -34,6 +36,11 @@ public: ...@@ -34,6 +36,11 @@ public:
private: private:
volatile int referenceCount; volatile int referenceCount;
#ifndef NDEBUG
public:
static std::set<Object*> instances; // For leak checking
#endif
}; };
class NamedObject : public Object class NamedObject : public Object
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment