Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Мультимедия, OpenGL/DirectX > IDirect3DIndexBuffer9::Lock()


Автор: Lightwave 17.2.2007, 21:47
Не комп. вот такая штука. Ошибка : 0xC0000005: Access violation reading location 0x00000000.

Код


IDirect3DVertexBuffer9* _VB;
IDirect3DIndexBuffer9*  _IB;    

//Structures

typedef struct _Vertex 
{
    _Vertex(){};
    _Vertex(float x, float y, float z)
    {
        _x = x;    _y = y; _z = z;
    };
    float _x, _y, _z;    // местоположение
    DWORD _color;     // цвет
    static const DWORD FVF;
} VERTEX;
const DWORD _Vertex::FVF = D3DFVF_XYZ;

bool Setup()
{    
    g_d3device->CreateVertexBuffer(8*sizeof(VERTEX), D3DUSAGE_WRITEONLY, VERTEX::FVF, 
                                                D3DPOOL_MANAGED, &_VB, 0);
    g_d3device->CreateIndexBuffer(36*sizeof(VERTEX), D3DUSAGE_WRITEONLY, D3DFMT_D16, 
                                            D3DPOOL_MANAGED, &_IB, 0);
    VERTEX*    Vertices = NULL;

    _VB->Lock(0, sizeof(VERTEX), (void**) &Vertices, 0);

    Vertices[0] = VERTEX(-1.0f, -1.0f, -1.0f);
    Vertices[1] = VERTEX(-1.0f,  1.0f, -1.0f);
    Vertices[2] = VERTEX( 1.0f,  1.0f, -1.0f);
    Vertices[3] = VERTEX( 1.0f, -1.0f, -1.0f);
    Vertices[4] = VERTEX(-1.0f, -1.0f,  1.0f);
    Vertices[5] = VERTEX(-1.0f,  1.0f,  1.0f);
    Vertices[6] = VERTEX( 1.0f,  1.0f,  1.0f);
    Vertices[7] = VERTEX( 1.0f, -1.0f,  1.0f);

    _VB->Unlock();
    
    WORD* Indeces = NULL;

    _IB->Lock(0, 0,(void**) &Indeces,D3DLOCK_READONLY); //На этом месте всё и заканчивается 0xC0000005: Access violation reading location 0x00000000.

    // передняя грань
    Indeces[0]  = 0; Indeces[1]  = 1; Indeces[2]  = 2;
    Indeces[3]  = 0; Indeces[4]  = 2; Indeces[5]  = 3;

    // задняя грань
    Indeces[6]  = 4; Indeces[7]  = 6; Indeces[8]  = 5;
    Indeces[9]  = 4; Indeces[10] = 7; Indeces[11] = 6;

    // левая грань
    Indeces[12] = 4; Indeces[13] = 5; Indeces[14] = 1;
    Indeces[15] = 4; Indeces[16] = 1; Indeces[17] = 0;

    // правая грань
    Indeces[18] = 3; Indeces[19] = 2; Indeces[20] = 6;
    Indeces[21] = 3; Indeces[22] = 6; Indeces[23] = 7;

    // верх
    Indeces[24] = 1; Indeces[25] = 5; Indeces[26] = 6;
    Indeces[27] = 1; Indeces[28] = 6; Indeces[29] = 2;

    // низ
    Indeces[30] = 4; Indeces[31] = 0; Indeces[32] = 3;
    Indeces[33] = 4; Indeces[34] = 3; Indeces[35] = 7;

    _IB->Unlock();
    
    D3DXVECTOR3     position(0, 0, -5);
    D3DXVECTOR3    target(0, 0, 0);
    D3DXVECTOR3     up(0, 1, 0);
    D3DXMATRIX      v;

    D3DXMatrixLookAtLH(&v, &position, &target, &up);
    g_d3device->SetTransform(D3DTS_VIEW, &v);

    D3DXMATRIX    project;
    D3DXMatrixPerspectiveFovLH(&project, D3DX_PI * 0.5f, (FLOAT)WINDOW_WIDTH/(FLOAT)WINDOW_HEIGHT,
                                                1, 1000);
    g_d3device->SetTransform(D3DTS_PROJECTION, &project);
    g_d3device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);

    return TRUE;
}

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)