Results 1 to 4 of 4

Thread: [D3D] Acces violation when game terminates

  1. #1

    [D3D] Acces violation when game terminates

    Hi!

    I'm playing a bit with Clooties DX8.1 SDK. I am new to Direct3d, and i'm exploring a bit.
    I already know how to create device and render some colored vertices. Now i want to draw a texture on a Vertex quad, and thats were the problems appear.

    Every time i exit the program i get an AV at adress 004190FE and a Runtime error 216 at BF7CCF45.

    Okay... my code:
    [pascal]
    //Global vars
    var
    Mainform: TMainform;
    //Direct3d object
    D3D: IDirect3d8 = nil;
    //Direct3d device
    D3DDevice: IDirect3dDevice8 = nil;
    VertexBuffer: IDirect3dVertexBuffer8 = nil;
    Texture: IDirect3DTexture8 = nil;

    ............

    //Initalize Direct3d
    function InitD3D(hWnd: HWND): ErrorCode;
    var
    d3ddm: TD3DDisplayMode;
    d3dpp: TD3DPresentParameters;
    begin
    //Creating the device
    //etc etc etc.........
    //...........

    // Turn off culling, and lighting
    D3DDevice.SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
    D3DDevice.SetRenderState(D3DRS_LIGHTING, iFalse);
    D3DDevice.SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
    D3DDevice.SetRenderState(D3DRS_SRCBLEND,D3DBLEND_S RCALPHA);
    D3DDevice.SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ INVSRCALPHA);
    D3DDevice.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
    Result:= E_SUCCES;
    end;

    function InitVertexBuffer;
    var Vertices: array [0..4] of CUSTOMVERTEX;
    pVertices: pByte;
    SrcInfo: PD3DXIMAGE_INFO;
    const
    Transparant: D3DCOLOR = $000000ff;
    begin
    Result := E_FAILED;

    //Create the texture
    if FAILED(D3DXCreateTextureFromFileEx(D3DDevice,'c:/frame.bmp',64,64,1,0,
    D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_NONE,
    D3DX_DEFAULT, transparant, srcInfo, nil, Texture)) then
    begin
    Result := E_TEXTURE_CANNOTMAKE;
    Exit;
    end;

    //Initalizing Vertex array
    //etc etc....
    //....

    //create vertex buffer
    if FAILED(D3DDevice.CreateVertexBuffer(4*SizeOf(CUSTO MVERTEX),
    0, D3DFVF_CUSTOMVERTEX,
    D3DPOOL_DEFAULT, VertexBuffer)) then
    begin
    Result:= E_VB_CREATE_FAILED;
    Exit;
    end;

    //lock vertex buffer
    if FAILED(VertexBuffer.Lock(0, SizeOf(Vertices), pVertices, 0)) then
    begin
    Result:= E_VB_LOCK_FAILED;
    Exit;
    end;

    Move(Vertices, pVertices^, SizeOf(Vertices));

    VertexBuffer.Unlock;

    Result:= E_SUCCES;
    end;

    //Release all direct3d objects
    procedure Release3d;
    begin
    if (Texture <> nil) then Texture := nil;
    if (VertexBuffer <> nil) then VertexBuffer:= nil;
    if (D3DDevice <> nil) then D3DDevice:= nil;
    if (D3D <> nil) then D3D:= nil;
    end;[/pascal]

    It might has something to do with the release order, but i am not sure.
    My texture is a 64x64 bitmap with 24 bpp.

    Does anyone know a solution, or a good textured-quad drawing example

    Thanx in advance... Chronozphere.

    Edit->> changed code tags form [code] to [pascal]
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  2. #2

    [D3D] Acces violation when game terminates

    I didn't see any device releasing or creating calls...

    This code could propably be called as a memory leak
    You are disposing of pointers but leaving the objects in memory.
    [pascal] if (Texture <> nil) then Texture := nil;
    if (VertexBuffer <> nil) then VertexBuffer:= nil;
    if (D3DDevice <> nil) then D3DDevice:= nil;
    if (D3D <> nil) then D3D:= nil;[/pascal]

  3. #3

    [D3D] Acces violation when game terminates

    In Delphi, all you need to do to release a COM object is set the pointer to nil. This automatically calls Release in the background.

  4. #4

    [D3D] Acces violation when game terminates

    Okay.... looks like i found the bug (i think)

    The parameters i send to the D3DCreateTextureFromFileEx function are wrong.
    This is the way it should be called:

    [pascal]
    if FAILED(D3DXCreateTextureFromFileEx(D3DDevice,'c:/texture.bmp',0,0,0,0,
    D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_NONE,
    D3DX_DEFAULT, transparant, nil, nil, Texture)) then
    begin
    Result := E_TEXTURE_CANNOTMAKE;
    Exit;
    end;
    [/pascal]

    The Miplevels and Usage parameters must be zero. (in this case)

    Thanx Everyone. [/pascal]
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •