   VB->CreateVertexBuffer() causing an access violation.
  Heres my problem:if I run my program with an array having only 2 elements, it runs fine, but if I add a 3rd element to it, the call causes an access violation.If I split the array into different veriables it still acts the same: 2 variables work, 3 doesn''t.I think this might have something to do with memory usage, but I''m afraid I can''t understand what causes this.This isn''t the first time I''ve encountered this kind of problem.I really need that memory.Help please . 
  We need much more detailed info (whch DirectX version, which "array", which "variables" etc)Ideally, please post the relevent source code.   --Simon O''Connorex  -Creative AsylumProgrammer &Microsoft MVP;Yes, we require more code.  There is always the possibility you didn''t lock the buffer correctly before accessing it - or perhaps you passed in a pointer, rather than a pointer to a pointer etc.  Anyway, paste some code. ;  Not that I mind posting code, I just think it's something much more complex than passing a pointer instead of a pointer to a pointer.However, when I encountered the problem, I'd gone ahead and changed the code to use a pointer to an array, and using new and delete. Anyways heres what the code was (more or less). bool cObject::Load(LPDIRECT3DDEVICE9 d3dDevice){CUSTOMVERTEX Vertices[2154];FILE *m_FilePointer = fopen("cannon1.OBJ", "r");short indices[20000];short CurrVertex = 0;short CurrIndex = 0;char strLine[255] = {0};char ch= 0;while(!feof(m_FilePointer)){float x = 0.0f, y = 0.0f, z = 0.0f;short tmp1, tmp2, tmp3;ch = fgetc(m_FilePointer);switch(ch){case 'v':ch = fgetc(m_FilePointer);if(ch == ' ') {fscanf(m_FilePointer, "%f %f %f", &x, &y, &z);fgets(strLine, 100, m_FilePointer);Vertices[CurrVertex].x = x;Vertices[CurrVertex].y = y;Vertices[CurrVertex].z = z;Vertices[CurrVertex].color = D3DCOLOR_XRGB((int)(x * 256), (int)(y  * 256), (int)(z * 256));CurrVertex++;}break;case 'f':fscanf(m_FilePointer, "%i/%i %i/%i %i/%i", &indices[CurrIndex], &tmp1, &indices[CurrIndex + 1], &tmp2, &indices[CurrIndex + 2], &tmp3);CurrIndex = CurrIndex + 3;fgets(strLine, 100, m_FilePointer);break;default:fgets(strLine, 100, m_FilePointer);break;}}m_FilePointer = NULL;CurrVertex--;CurrIndex--;m_NumIndices = CurrIndex;// start of re-written part./////////////////////////////for(short i=0; i<m_NumIndices; i++){D3DXVECTOR3 vn[3]; // this is the problem array. If I set it to 2, it works, if it's 3 it fails.vn[0].x = //.... vertex normal datavn[0].y = //.... vertex normal datavn[0].z = //.... vertex normal datavn[1].x = //.... vertex normal datavn[1].y = //.... vertex normal datavn[1].z = //.... vertex normal datavn[2].x = //.... vertex normal datavn[2].y = //.... vertex normal datavn[2].z = //.... vertex normal dataD3DXVECTOR3 TmpVec1, TmpVec2;D3DXVECTORSUBTRACT(&TmpVec1, &vn[1], &vn[0]);D3DXVECTORSUBTRACT(&TmpVec2, &vn[2], &vn[1]);D3DXVECTOR3 TmpVec3;D3DXVECTORCROSS(&TmpVec3, &TmpVec2, &TmpVec1);Vertices[Indices[i]].nx += vn[0].x;Vertices[Indices[i]].nx += vn[0].x;Vertices[Indices[i]].nx += vn[0].x;Vertices[Indices[i+1]].nx += vn[1].x;Vertices[Indices[i+1]].nx += vn[1].x;Vertices[Indices[i+1]].nx += vn[1].x;Vertices[Indices[i+2]].nx += vn[2].x;Vertices[Indices[i+2]].nx += vn[2].x;Vertices[Indices[i+2]].nx += vn[2].x;}/////////////////////////////// End of re-written part.d3dDevice->CreateVertexBuffer((sizeof(CUSTOMVERTEX) * 2154), 0,D3DFVF_VERTEX, D3DPOOL_DEFAULT, &m_VB, NULL);// Program fails here (Access Violation).VOID* pVertices;m_VB->Lock(0, sizeof(Vertices), (void**)&pVertices, 0);memcpy( pVertices, Vertices, sizeof(Vertices) );m_VB->Unlock();VOID* pIndices;assert(SUCCEEDED(d3dDevice->CreateIndexBuffer(sizeof(indices), 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &m_IB, NULL)));m_IB->Lock(0, sizeof(indices), (void**)&pIndices, 0);memcpy( pIndices, indices, sizeof(indices) );m_IB->Unlock();return true;}[EDIT]This is more or less what it was like, but it isn't exactly the same. What I was trying to do was calculate vertex normals at load time, and while my calculations were wrong, I wasn't doing anything illegal.Hope this helps more, though theres far less pressure on finding this out since I found a work around with "New" and "Delete" calls.   [edited by - sirob on August 1, 2003 6:11:25 PM];  This might be your problem.  Im not sure tho... vn[0].x = //.... vertex normal datavn[0].y = //.... vertex normal datavn[0].z = //.... vertex normal datavn[1].x = //.... vertex normal datavn[1].y = //.... vertex normal datavn[1].z = //.... vertex normal datavn[2].x = //.... vertex normal datavn[2].y = //.... vertex normal datavn[2].z = //.... vertex normal dataYou dont assign those too anything!  If im wrong dont be mad :-s  Im new at this too   Quantum ;  Well, since I had redone my code, I lost all that part, and had to rewrite it. Since I''m lazy I didn''t write it all.The lines should be: vn[0].x = Vertices[Indices[i]].x;vn[0].y = Vertices[Indices[i]].y;vn[0].z = Vertices[Indices[i]].z;vn[1].x = Vertices[Indices[i+1]].x;vn[1].y = Vertices[Indices[i+1]].y;vn[1].z = Vertices[Indices[i+1]].z;vn[2].x = Vertices[Indices[i+2]].x;vn[2].y = Vertices[Indices[i+2]].y;vn[2].z = Vertices[Indices[i+2]].z;;  Your parameter should be ( LPDIRECT3DDEVICE9* device ). A pointer.   [edit] Forgot the 9..lick   [edited by - Pipo DeClown on August 2, 2003 3:56:52 AM];  I can see the reason behind that, but I just can''t implement the change in my code.Using "bool cObject::Load(LPDIRECT3DDEVICE9 d3dDevice)"  works, and I can''t get "bool cObject::Load(LPDIRECT3DDEVICE9* d3dDevice)"   to work.When I try something like "d3dDevice->SetStreamSource( 0, m_VB, 0, sizeof(CUSTOMVERTEX));   I get an error.   Sirob Yes.»Footman, at large. ;quote:Original post by Pipo DeClown  Your parameter should be ( LPDIRECT3DDEVICE9* device ). A pointer.   [edit] Forgot the 9.Doesn''t ''LP'' mean ''long pointer'', in other words, LPDIRECT3DDEVICE9 == pointer? And LPDIRECT3DDEVICE9* == pointer to a pointer? ;quote:Original post by sirob  Using "bool cObject::Load(LPDIRECT3DDEVICE9 d3dDevice)"   works, and I can''t get "bool cObject::Load(LPDIRECT3DDEVICE9* d3dDevice)"to work.When I try something like "d3dDevice->SetStreamSource( 0, m_VB, 0, sizeof(CUSTOMVERTEX));I get an error.   When accepting an "IDirect3DDevice9**", you have to dereference it before you use it: void SomeFunction( IDirect3DDevice9 **ppDevice ){    (*ppDevice)->SetRenderState( D3DRS_LIGHTING, FALSE );} Peace,Muhammad Haggag 