# Dereferencing null pointer deep within D3DX

This topic is 3749 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm working with an application which I believe was still linking against a really old local copy of the DirectX 9.0b SDK (D3D_SDK_VERSION was defined as 31)... I dropped in the libs and headers from the Nov. 2007 SDK, made the few code changes I needed to get up and running (which really only meant passing D3DXSHADER_USE_LEGACY_D3DX9_31_DLL to the effects framework in a few places), and everything seems fine, except... Now when my application is shutting down, during the destruction of the objects which make the Release call on the D3DX effects, I'm getting a crash with a call stack that runs pretty far into (and ends on) D3DX. This only happens when linked against D3DX9D.
(f40.1498): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=0ca8a9e0 ebx=0c989338 ecx=00000000 edx=0c75739c esi=0ca8aa00 edi=6060c0b0
eip=603043d4 esp=0012f658 ebp=0012f660 iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00210246
d3dx9d_36!delete_helper+0x20:
603043d4 3901            cmp     dword ptr [ecx],eax  ds:0023:00000000=????????
Here's the call stack from WinDbg...
0:000> KP
0012f660 60304429 d3dx9d_36!delete_helper+0x20
0012f66c 603e2dd3 d3dx9d_36!operator delete+0xd
0012f678 603e2dfe d3dx9d_36!D3DXEffects::CEffectPool::~CEffectPool+0x13
0012f684 603e3e0b d3dx9d_36!D3DXEffects::CEffectPool::scalar deleting destructor'+0xd
0012f690 0b4bb22a d3dx9d_36!D3DXEffects::CEffectPool::Release+0x17
0012f6a4 0b4bb27d d3dx9_31!D3DXEffects::CEffect::~CEffect+0x186
0012f6b0 0b4bb2ad d3dx9_31!D3DXEffects::CEffect::scalar deleting destructor'+0xd
0012f6bc 012feb81 d3dx9_31!D3DXEffects::CEffect::Release+0x17
0012f750 01301bb5 MyDebugExe!DXEffect::~DXEffect(void)+0x111
I'm also working on adding effect pooling at the same time, so there's a problem as far as isolating that... but while I notice the references to the effect pool destructor in that call stack, I'm not sure why that would be happening, let alone causing problems. All I do is call D3DXCreateEffectPool at the beginning of the application, pass it to all the effect creation calls, then release the pool pointer at the end of the app. Any thoughts? I'm not sure what to make of this. Again, keep in mind, there doesn't appear to be any problem when I run the application linked against the release D3DX lib... and I don't see any relevant warnings or errors, even with the D3D debug output set to 4/5. Thanks in advance.

##### Share on other sites
Addendum: my bad, I was releasing the pool in certain cases before I released the effects...however, now that I've moved the offending pool->Release() call, it crashes there, instead of upon trying to release the effects themselves. Similar call stack...

D3DX9d_36.dll!delete_helper()  + 0x20	D3DX9d_36.dll!operator delete()  + 0xd	D3DX9d_36.dll!D3DXEffects::CEffectPool::~CEffectPool()  + 0x13	D3DX9d_36.dll!D3DXEffects::CEffectPool::scalar deleting destructor'()  + 0xd	D3DX9d_36.dll!D3DXEffects::CEffectPool::Release()  + 0x17`

• 10
• 16
• 9
• 13
• 41