I set out to fix them tonight, but I'm pretty sure I'm going out of my fucking mind. All of my reported leaks are D3D handles, which is especially bad, but I can't for the life of me figure out why they're still getting reported.
For example, most of my leaks appear to be from my textures. I have my out wrapper around the D3D texture interface, which is as follows (this code has changed a bit in the past hour or two, so bear with all the commented out nonsense):
Texture.h
#ifndef TEXTURE_H#define TEXTURE_H#define D3D_DEBUG_INFO#include #include #include #include #include "../../Main/Header Files/Resource.h"namespace ISO{ namespace Graphics { class Texture { public: Texture(LPDIRECT3DDEVICE9 device = NULL, std::string filename = ""); /*Texture(const Texture& tex); const Texture& operator=(const Texture& tex);*/ ~Texture(); LPDIRECT3DTEXTURE9 GetTexturePointer() const; const std::string& GetFileName() const; ULONG Release(); private: std::string m_Filename;// Base::auto_resource m_Texture; mutable LPDIRECT3DTEXTURE9 m_Texture; }; }}#endif
Texture.cpp
#include #include "../Header Files/Texture.h"ISO::Graphics::Texture::Texture(LPDIRECT3DDEVICE9 device, std::string filename): m_Filename(filename),m_Texture(NULL){ if (!device) { return; } LPDIRECT3DTEXTURE9 texture; HRESULT hr = D3DXCreateTextureFromFile(device, filename.c_str(), &texture); if (FAILED(hr)) { return; } m_Texture = texture;}//ISO::Graphics::Texture::Texture(ISO::Graphics::Texture &tex)//{// //*m_Texture = *tex.GetTexturePointer();//}//ISO::Graphics::Texture::Texture(const Texture& tex)//: m_Texture(tex.m_Texture)//{// tex.m_Texture = NULL;//}////const ISO::Graphics::Texture& ISO::Graphics::Texture::operator=(const ISO::Graphics::Texture& tex)//{// m_Texture = tex.m_Texture;// tex.m_Texture = NULL;// return *this;//}ISO::Graphics::Texture::~Texture(){ /*if (m_Texture) { m_Texture->Release(); }*/}LPDIRECT3DTEXTURE9 ISO::Graphics::Texture::GetTexturePointer() const{ return m_Texture;//.Get();}const std::string& ISO::Graphics::Texture::GetFileName() const{ return m_Filename;}ULONG ISO::Graphics::Texture::Release(){ assert(m_Texture); return m_Texture->Release();}
Simple enough, unless (as is highly possible) I'm missing something obvious. I keep a std::vector of these Textures in my renderer, which theoretically get released when the renderer is destroyed:
Renderer.cpp
ISO::Graphics::Renderer::~Renderer(){ for (unsigned i = 0; i < m_Tiles.size(); ++i) { delete m_Tiles.Geometry; } for (unsigned i = 0; i < m_UIBuffers.size(); ++i) { delete m_UIBuffers.first; } for (unsigned i = 0; i < m_TextureBuffer.size(); ++i) { //delete m_TextureBuffer; m_TextureBuffer.Release(); } //m_TextureBuffer.clear(); if (m_D3DDevice) { m_D3DDevice->Release(); //m_D3DDevice = NULL; } if (m_D3D) { m_D3D->Release(); //m_D3D = NULL; } delete m_Selector; delete m_MasterGeometry;}
I've set breakpoints in the Renderer destructor, and it is indeed getting called. Texture->Release is returning 0, so it doesn't appear that I have any dangling references out there. Why, then, do I still get a ton of leaks reported coming from my textures?
I am confused and tired. Little help [grin]?
Although if you're seeing Release() return 0 for all texture anyway, it should be fine.
Have you tried commenting out chunks of code till the leak goes away? That should at least help narrow it down (Although I appreciate that "commenting out chunks of code" can be a bit difficult in complex engines).