1.7.0 cgDestroyContext crash on DX

I’m experiencing a crash on DX when I close the app.

It happens here, on dxShaderContext9.cxx

void CLP(ShaderContext)::
release_resources() {
#ifdef HAVE_CG
  if (_cg_context) {
    cgDestroyContext(_cg_context); //crash

I tried building against a new CG toolkit (Panda uses 2.1.7 and 2.2 is available) and same thing. Any clues why this could be happening now? Actually I don’t know if it didn’t happen before because I’m using another PC temporarily with a crappy 8400GS, and maybe it only happens here.

EDIT: I tried the following:

    if (cgIsContext(_cg_context) == CG_TRUE){

But it still goes inside and crashes on cgDestroyContext.

Hm, under what circumstances exactly? Only when you have a Cg shader? Did it fail to compile, perhaps?

I noticed that _cg_context is never initialized. It only gets set when it has a Cg shader that compiles correctly. I’ve just checked in a fix for that - it might be the solution to your problem.
The latest daily build contains this fix.

It still crashes, because the problem occurs after using a shader.

Btw, if I comment the cgDestroyContext call, it still crashes but I can’t debug there, I’m trying to find out.