I have a DLL that hooks D3D EndScene call to draw an overlay; to do so, it creates a few textures to avoid re-creating the image on every frame. However, I need to detect when I should release the textures. If I don't do so, I get the "has non-zero reference count" errors from the SDK samples and certain games.
I was able to fix errors on resizing by simply hooking Reset; however, that did not fix the errors when the target application is closed. I suppose the only way to fix that would be to hook Release, but then I would not know whether the device is actually being released or its reference count is simply decreased - as my own textures also store references to the device and I have no clean way of counting them. I could try releasing the textures on every call to Release and then re-creating them if needed, but I'm afraid that my hook will be called even when D3D code implicitly calls Release, e.g. when releasing a resource associated with that device. So if the app creates and releases some objects on every frame, this will cause my textures to get destroyed and re-created on every frame, defeating the purpose of storing them.
Is there a way to know how many times my objects reference the device, other than simply calling AddRef, creating them, then Release and calculate the difference between return values?