((*(IUnknown*)(&(*(IDirect3DResource9*)(&*vb))))).__vfptr 

__vfptr CXX0030: Error: Unable to evaluate expression

WTF !? Help me please!]

 dev->CreateVertexBuffer( 4, D3DUSAGE_WRITEONLY, D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &vb, NULL); 

When debugging on this method is stuck. Writes this:

Unhandled exception in "0x002c1602" in "tutorial.exe": 0xC0000005: Access violation when reading "0x00000000".

 IDirect3D9* d3d = NULL; IDirect3DDevice9* dev = NULL; IDirect3DVertexBuffer9* vb = NULL; d3d = Direct3DCreate9(D3D_SDK_VERSION); D3DPRESENT_PARAMETERS pp; ZeroMemory(&pp,sizeof(pp)); //тут заполнение pp d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF,hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &pp, &dev); dev->CreateVertexBuffer( 4, D3DUSAGE_WRITEONLY, D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &vb, NULL); 
  • But you can get more code, do not be stingy - perfect
  • Moved to the question. - Max Kozhanov
  • ((*(IUnknown*)(&(*(IDirect3DResource9*)(&*vb))))).__vfptr And what can these ampersands mean? Of course, I understand that everything in Windows is not like people, but not so much. What can they mean? (Preferably with words) - alexlz
  • CreateDevice () normally completed? In dev not null? If OK, then what is the result of CreateVertexBuffer ()? - avp
  • alexlz, an ampersand is essentially a variable address operator - Max Kozhanov

2 answers 2

All figured out! The problem turns out to be very easy to solve. And I paid attention to this section of the code when I read the lesson from which I took this code. Generally:

 d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &pp, &dev); 

So, I had D3DDEVTYPE_REF , replaced by D3DDEVTYPE_HAL

    I would venture to suggest that you specified a buffer size that is too small, after which you try to write outside it. Try not to write

     dev->CreateVertexBuffer( 4 ..... 

    and something like

     dev->CreateVertexBuffer(4*sizeof(Vertex) .... 
    • oh, sorry. When the code was dropped, I accidentally erased this expression ... when you write 4 * sizeof (Vertex), or 6 * sizeof (Vertex), all the same garbage - Max Kozhanov
    • I agree it is necessary to revise the function on which it crashes. - perfect
    • yes everything seems to be correctly stated. I tried different examples. - Max Kozhanov
    • see what this and previous functions return. For this there are FAILED (function) and SUCCEEDED (function) macros - perfect
    • Please give an example of how to use these macros. I tried it myself - nothing happens. - Max Kozhanov