Problem with DrawIndexedPrimitive in D3D9

Started by
8 comments, last by raklar 20 years, 9 months ago
Hello, I''ve encountered a weird problem in DX9 with the DrawIndexed primitive function. for some reason when I''m calling this function to draw a cube I get a E_OUTOFMEMORY from the method. I have traced through the code and this is definitly where the error is comming from, now the weird thing is according to the DX documentation DrawIndexedPrimitive is not supposed to be able to return a outofmemory error. I know my index and vertex buffer are setup right (basically I''m using a function that worked with DX8 and converting it to DX9). Anyone have any ideas? Here is my call to DIP : hr = g_d3d_device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,8,0,12); thanks
Richard S. Bezemer
Advertisement
Don''t know if this will help get more replies or not but here is my rending code. This problem is really frustrating me, I can''t find any doc. anywhere on why this error keeps poping up.

LPDIRECT3DINDEXBUFFER9 pIB = 0;
hr = g_d3d_device->CreateIndexBuffer(sizeof(short)*36, D3DUSAGE_WRITEONLY,D3DFMT_INDEX16, D3DPOOL_DEFAULT, &pIB, NULL);

short indices[36] = {...};
void* pIndexData;
hr = pIB->Lock(0,sizeof(pIB),&pIndexData,0);
CopyMemory(pIndexData,(void*)&indices,sizeof(indices));
pIB->Unlock();

LPDIRECT3DVERTEXBUFFER9 pVB = 0;
hr = g_d3d_device->CreateVertexBuffer(sizeof(CRDXVertex), D3DUSAGE_WRITEONLY,RVERTEX_TYPE, D3DPOOL_MANAGED, &pVB, NULL);

void* pVertexData;
hr = pVB->Lock(0,0,&pVertexData,0);
CopyMemory(pVertexData,(void*)m_vertices,sizeof(m_vertices));
pVB->Unlock();

hr = g_d3d_device->SetStreamSource(0,pVB,0,sizeof(CRDXVertex));
hr = g_d3d_device->SetIndices(pIB);
hr = g_d3d_device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0,0,8,0,12);

pVB->Release();
pIB->Release();
return D3D_OK;
Richard S. Bezemer
Looks good from what I can see. (Except you dont want to necessarly create that index/vertex buffer every time you render, only once at the beginning unless the data is changing.)

Aside from that, I had this error once along time ago. Do you by chance have a dual processor CPU (or 1 CPU with hyper threading)?

If so, you need to CreateDevice() (where you initialize and create the device) using the flag which indicates 2 or more CPUS. It''s D3DCREATE_MULTITHREADED or something. In the docs the flag indicates "has more critical sections." I don''t have the SDK installed at work, so I can''t give exact details, but hopefully this is enough for you to go on. Hopefully thats it.
No dual processors here. and as far as I know hyperthreading isn''t turned on. It''s a weird problem, and I''ve checked all the system resources while the program is running (including the video card) and there seems to be plenty of memory on both the system and video card.
Richard S. Bezemer
Have you tried running under the debug runtime and watching the debug spew? This may give you a better idea as to where and why it is failing.
Does the debug Direct3D runtime tell you anything interesting in its debug output when the output level slider in the DirectX control panel applet is set to maximum ?

Out of interest, try putting "hr = g_d3d_device->SetIndices(NULL);" after your DrawIndexedPrimitive() call [remember SetIndices() AddRef''s, if you''re creating VBs and IBs every frame, there could be references still set]. To check this, for debugging purposes you can check the return values from the Release() calls to see if there are any other refs.


BTW: if that code is being executed as-is, it may actually be better for you to use DrawIndexedPrimitiveUP(). A much better option all round is to not create vertex and index buffers every frame/render.

--
Simon O''Connor
ex -Creative Asylum
Programmer &
Microsoft MVP

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

I having some other weird issues as well, I''m wondering if something else is going on in my system. DX doesn''t seem to want to install the debug version on my pc. I went to check the debug settings and to my surprize it was the retail version installed. This kind of surprized me, but ok whatever maybe I was half asleep when I installed DX. So an uninstall and reinstall later I still can''t select the debug version. I choose debug in the DX9 setup program, but it still seems to only install the retail version.It has some debug files (10 I think)but not all of them. I downloaded the DX9 control panel(since it wasn''t installed), but all the options to select debug version are greyed out (which makes sense if the debug version will not install).
Richard S. Bezemer
Try installing the debug runtime while in safe mode. I had an issue with installing directx at one point. Running in safe mode seems to help allow the install to run - don''t know if that will help you though?
Found it. Downloaded the DX9A sdk and was finally able to install debug mode. Now that I can see the proper error messages here''s what''s happening. Basically my viewport was drawing outside the main render target and this causes the drawprimitive to fail. Now why can''t microsoft just say something like that in the documentation and return codes instead of having undocumented errors?
Richard S. Bezemer
quote:LPDIRECT3DVERTEXBUFFER9 pVB = 0;
hr = g_d3d_device->CreateVertexBuffer(sizeof(CRDXVertex), D3DUSAGE_WRITEONLY,RVERTEX_TYPE, D3DPOOL_MANAGED, &pVB, NULL);


You created the vertexbuffer for 1 vertex.


.lick


[edited by - Pipo DeClown on July 8, 2003 6:32:38 AM]

This topic is closed to new replies.

Advertisement