   [DX9]ID3DXMesh::LockVertexBuffer always Failure.
  I wan't to create a sphere mesh, so I Create a ID3DXMesh and Lock vertex buffer, but it alwasy return E_FAIL. this is the code( work with DXUT):struct CUSTOMVERTEX{D3DXVECTOR3 position;   //D3DXVECTOR3 normal;//D3DXVECTOR3 tangent;float tu, tv;};HRESULT CreateVertex( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ){static const unsigned sc_uRings = 20;static const unsigned sc_uSegments = 20;g_uVerticesNum = 2 * sc_uRings * ( sc_uSegments + 1 );HRESULT hr;D3DVERTEXELEMENT9 Decl[]={{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},{0, 24, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0},{0, 36, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},D3DDECL_END()};V_RETURN(D3DXCreateMesh( sc_uRings * (sc_uSegments+1)-2, sc_uRings * (sc_uSegments+1), D3DXMESH_VB_DYNAMIC, Decl, pd3dDevice, &g_pMesh ) );CUSTOMVERTEX* pVertices = NULL;if( FAILED(g_pMesh->LockVertexBuffer( D3DLOCK_READONLY/*D3DLOCK_DISCARD*/, (LPVOID*)pVertices )) ){return E_FAIL;}else{FLOAT fDeltaRingAngle = ( D3DX_PI / sc_uRings );FLOAT fDeltaSegAngle = ( 2.0f * D3DX_PI / sc_uSegments );for( unsigned uRing = 0; uRing < sc_uRings; ++uRing ){FLOAT r0 = sinf ( (uRing+0) * fDeltaRingAngle );FLOAT r1 = sinf ( (uRing+1) * fDeltaRingAngle );FLOAT y0 = cosf ( (uRing+0) * fDeltaRingAngle );FLOAT y1 = cosf ( (uRing+1) * fDeltaRingAngle );for( unsigned uSeg = 0; uSeg < ( sc_uSegments + 1 ); ++uSeg ){FLOAT x0 = r0 * sinf( uSeg * fDeltaSegAngle );FLOAT z0 = r0 * cosf( uSeg * fDeltaSegAngle );FLOAT x1 = r1 * sinf( uSeg * fDeltaSegAngle );FLOAT z1 = r1 * cosf( uSeg * fDeltaSegAngle );pVertices->position = D3DXVECTOR3( x0, y0, z0 );D3DXVec3Normalize( &pVertices->normal, &pVertices->position);pVertices->tu = -((FLOAT)uSeg) / sc_uSegments;pVertices->tv = (uRing) / (FLOAT) sc_uRings;++pVertices;pVertices->position = D3DXVECTOR3( x1, y1, z1 );D3DXVec3Normalize( &pVertices->normal, &pVertices->position);pVertices->tu = -((FLOAT)uSeg) / sc_uSegments;pVertices->tv = (uRing+1) / (FLOAT) sc_uRings;++pVertices;  }}g_pMesh->UnlockVertexBuffer();}return S_OK;} the most important is this :if( FAILED(g_pMesh->LockVertexBuffer( D3DLOCK_READONLY/*D3DLOCK_DISCARD*/, (LPVOID*)pVertices )) ) it always FAILED...no matter I provide Flags. Thanks every friend. yesterday, I use D3DXCreateSphere to create a temporary mesh, use CloneMesh to set g_pMesh, but when I lockVertexBuffer, It Return E_FAIL too. I create sphere dynamically because I never have a sphere mesh, but I wan't to use it work with a texture and a normal texture, to implement Norma Mapping. If I use D3DXCreateSphere, the generated mesh does not have a texture coordinates. So I wan't to create a blank mesh, and fill it myself, and the use D3DXComputeNormals and D3DXComputeTangent to compute the normals and tangent value.Thanks..   
  I'd suggest turning on the debug runtime (through the DirectX Control Panel app that comes with the SDK) and seeing what it prints to the output panel.   ;Quote:Original post by ET3DI'd suggest turning on the debug runtime (through the DirectX Control Panel app that comes with the SDK) and seeing what it prints to the output panel.   thanks a lot, your msg is very helpful. I turn on the debug mode, and it occurs a strange error, when it run to  "if( FAILED(g_pMesh->LockVertexBuffer( D3DLOCK_READONLY/*D3DLOCK_DISCARD*/, (LPVOID*)pVertices )) )".   it block by extern "C" _CRTIMP void * __cdecl _realloc_dbg(   void * pUserData,   size_t nNewSize,   int nBlockUse,   const char * szFileName,   int nLine   ){   void * pvBlk;   _mlock(_HEAP_LOCK);    /* block other threads */   __try {   /* allocate the block    */   pvBlk = realloc_help(pUserData,    &nNewSize,    nBlockUse,    szFileName,    nLine,    TRUE);   }   __finally {  _munlock(_HEAP_LOCK);   /* release other threads */   }   if (pvBlk)   {  RTCCALLBACK(_RTC_Allocate_hook, (pvBlk, nNewSize, 0));   }   return pvBlk;} // __finally,call stack say it called from CGrowableArray template class which implemented in DXUTmisc.h. so eerie.    and then I wrote a simple class to get whole call stack. it say:callstack log:  DebugBreakModule: C:\Windows\system32\KERNELBASE.dll  DebugSetLevelModule: C:\Windows\system32\d3d9d.dll  Direct3DShaderValidatorCreate9Module: C:\Windows\system32\d3d9d.dll  D3DXGetDeclLengthModule: C:\Windows\system32\d3dx9d_42.dll  CreateVertex    File:d:\planet\planet.cpp,   Line：318Module: d:\Planet\Debug\Planet.exe  OnD3D9CreateDevice    File:d:\planet\planet.cpp,   Line：434Module: d:\Planet\Debug\Planet.exe  DXUTCreate3DEnvironment9    File:d:\planet\dxut\core\dxut.cpp,   Line：3000Module: d:\Planet\Debug\Planet.exe  DXUTChangeDevice    File:d:\planet\dxut\core\dxut.cpp,   Line：2363Module: d:\Planet\Debug\Planet.exe  DXUTCreateDevice    File:d:\planet\dxut\core\dxut.cpp,   Line：2027Module: d:\Planet\Debug\Planet.exe  wWinMain    File:d:\planet\planet.cpp,   Line：771Module: d:\Planet\Debug\Planet.exe  __tmainCRTStartup    File:f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c,   Line：578Module: d:\Planet\Debug\Planet.exe  wWinMainCRTStartup    File:f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c,   Line：403Module: d:\Planet\Debug\Planet.exe  BaseThreadInitThunkModule: C:\Windows\system32\kernel32.dll  RtlInitializeExceptionChainModule: C:\Windows\SYSTEM32\ntdll.dll  RtlInitializeExceptionChainModule: C:\Windows\SYSTEM32\ntdll.dll  RtlInitializeExceptionChainModule: C:\Windows\SYSTEM32\ntdll.dll    SEH Error msg is: System can't find the appoint path.  another question is I don't know whether it is the corresponding call stack. ⊙﹏⊙b because when I run it with F5, it always block at that place, so I run it with Ctrl + F5, this call stack info is wrote to file.__try{if( FAILED( CreateVertex( pd3dDevice, pBackBufferSurfaceDesc, pUserContext ) ) ){return E_FAIL;}}__except( SEH_HANDLE ){}#define SEH_HANDLE log_system::getSingletonPtr()->WriteSEHLog( __FILE__, __LINE__, __FUNCTION__, GetExceptionInformation() )   