PDA

View Full Version : [D3D] non-zero reference count. what's the sollution??



chronozphere
11-05-2007, 05:09 PM
Hello everyone..

OS: Vista Ultimate
IDE: Delphi 7
API: Clooites DirectX SDK April 2007

I've installed Clootie's DX 9 SDK and i am trying to run a sample.
But it keeps saying that the D3D Device has a non-zero reference count.

This might be because i had tried that sample before but it failed because a DLL was not found (wich i have downloaded now). The D3D device refcount has probably been increased and now i cant run the sample again.

Off course, when you reboot your PC and try again, it WILL run. but is there a easier way of fixing this?? When i'm debugging or playing with the samples, its very annoying to have to reboot your PC a couple of times. It's even more annoying when you are trying to download something big. :lol:

Does anyone knows an easy way to fix it?? :?

Thank you.

chronozphere
12-05-2007, 12:44 PM
Aarrrghh.... even rebooting doesn't help when using Vista. :x :(

Does someone know a way of resetting the whole thing so i can use the BasicHLSL sample. The problem only occures when using THAT sample so i guess vista keeps track of the D3D device refcount for each application. :? Is there a way to reset that?, because it's driving me mad.

Clootie
13-05-2007, 11:15 AM
I suppose you downloaded media files or placed Delphi samples in preinstalled MS DX SDK? So all DDS/X files required by sample are in place?

chronozphere
14-05-2007, 05:29 PM
AFAIK my media files are placed correctly. (Clootie DX 9/Samples/Samples/Media).
The other samples work correctly so i guess there is nothing wrong with the media.

I tried to debug the application and i found out the following.

The OncreateDevice callback in the BasicHLSL unit failed.
This is because following call failed too:


Result := CDXUTDirectionWidget.StaticOnCreateDevice(pd3dDevi ce);


I continued and found out the following:


class function CDXUTDirectionWidget.StaticOnCreateDevice(
pd3dDevice: IDirect3DDevice9): HRESULT;
var
rgdwAdjacency: PDWORD;
dwBufferSize: LongWord;
begin
s_pd3dDevice := pd3dDevice;

dwBufferSize := StrLen(g_strBuffer) + 1;

Result:= D3DXCreateEffect(s_pd3dDevice, g_strBuffer, dwBufferSize, nil, nil, D3DXFX_NOT_CLONEABLE, nil, s_pEffect, nil); //<<< THIS CALL FAILED
if V_Failed(Result) then Exit;


Result:= DXUTCreateArrowMeshFromInternalArray(s_pd3dDevice, s_pMesh);
if V_Failed(Result) then Exit;

try
GetMem(rgdwAdjacency, SizeOf(DWORD)*s_pMesh.GetNumFaces*3);
except
Result:= E_OUTOFMEMORY;
Exit;
end;
V(s_pMesh.GenerateAdjacency(1e-6, rgdwAdjacency));
V(s_pMesh.OptimizeInplace(D3DXMESHOPT_VERTEXCACHE, rgdwAdjacency, nil, nil, nil));
FreeMem(rgdwAdjacency);

Result:= S_OK;
end;


Because the callback failed, the DXUTCreate3DEnvironment failed too and then DXUTCleanup3DEnvironment is executed which contains the following:



// are unrelease objects.
GetDXUTState.D3DDevice:= nil;
if (pd3dDevice <nil> 0) then
begin
{$IFNDEF FPC} //todo: Remove this HACK after succesfull debugging of FPC port
DXUTDisplayErrorMessage(DXUTERR_NONZEROREFCOUNT);
DXUT_ERR('DXUTCleanup3DEnvironment', DXUTERR_NONZEROREFCOUNT);
{$IFDEF DEBUG}
// Forced clearing of D3DDevice references, so D3D debug level will show additional messages
OutputDebugString('DXUT.pas: releasing D3DDevice refcount until ZERO');
while (pd3dDevice._Release > 0) do;
{$ENDIF}
{$ENDIF}
end;
Pointer(pd3dDevice) := nil;
end;


DXUTDisplayErrorMessage(DXUTERR_NONZEROREFCOUNT); shows the message.

The weird thing is that {$IFNDEF FPC} shouldn't return true because i'm using Delphi 7. :?
I see that when {$IFDEF DEBUG} returns true, all devices will be freed to make refcount zero.

Can you tell me why exactly the OnCreateDevice callback is failing, and what the sollution is??
Is the {$IFDEF DEBUG} thing a way to make sure that all devices are properly terminated??

Realy hope you can solve this! ;)

EDIT: starting post fixed :) I initialy thought you would do that, because the thread was locked and i couldn't edit. i didn't have a look at it after you unlocked it. Thanx for reminding me. ;)