   Problem with DepthStencil when creating shadows
  Hi everyone,I'd like to thank anyone for their help in advance. I've already searched forums and found a common solution but that doesn't seem to work.I'm receiving the following warningsD3D10: WARNING: ID3D10Device::OMSetRenderTargets: Resource being set to OM DepthStencil is still bound on input! [ STATE_SETTING WARNING #9: DEVICE_OMSETRENDERTARGETS_HAZARD ]D3D10: WARNING: ID3D10Device::OMSetRenderTargets: Forcing PS shader resource slot 2 to NULL. [ STATE_SETTING WARNING #7: DEVICE_PSSETSHADERRESOURCES_HAZARD ]I know the second warning is caused by the first warning, and is causing my shadows not to be drawn. I also think I understand why this is happening, I just don't know how to fix it.Here is my main draw functionvoid SereneShoreLine::drawScene(){D3DApp::drawScene();//restore defaults due to D3DApp::drawScene();md3dDevice->OMSetDepthStencilState(0, 0);float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);md3dDevice->IASetInputLayout(vertexLayout);//building shadow mapshadows.begin();buildShadows();shadows.end();resetOMTargetsAndViewport();//draw trees with there own effectstrees.draw(spotLight,eyePos,viewMatrix*projectionMatrix);md3dDevice->RSSetState(0); //restore defaultsmd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);md3dDevice->IASetInputLayout(vertexLayout);titan.draw(spotLight,eyePos,viewMatrix*projectionMatrix);md3dDevice->RSSetState(0);//scalling tex cords by 5D3DXMATRIX texMatrix;//for both water and sandD3DXMatrixScaling(&texMatrix, 5.0f, 5.0f, 1.0f);D3DXMATRIX T;D3DXMatrixTranslation(&T, waterOffset.x, waterOffset.y, 0.0f);D3DXMATRIX waterTexMatrix = texMatrix*T;md3dDevice->IASetInputLayout(vertexLayout);    md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);//effects varsfxEyePos->SetRawValue(&eyePos, 0, sizeof(D3DXVECTOR3));fxLight->SetRawValue(&spotLight, 0, sizeof(Light));fxShadowMapVar->SetResource(shadows.depthMap());D3D10_TECHNIQUE_DESC techDesc;    tech->GetDesc( &techDesc );    for(UINT i = 0; i < techDesc.Passes; ++i)    {   ID3D10EffectPass* pass = tech->GetPassByIndex(i);//drawing the beachbottomworldViewProjectionMatrix = sandBottomWorld*viewMatrix*projectionMatrix;fxWorldViewProjection->SetMatrix((float*)&worldViewProjectionMatrix);fxWorld->SetMatrix((float*)&sandBottomWorld);fxTexMatrix->SetMatrix((float*)&texMatrix);fxDiffuseMap->SetResource(sandRV);fxSpecMap->SetResource(sandSpecRV);fxLightWVPVar->SetMatrix(sandBottomWorld*lightViewMatrix*lightVolumeMatrix);pass->Apply(0);sandBottom.draw();//drawing wavesworldViewProjectionMatrix = wavesWorld*viewMatrix*projectionMatrix;fxWorldViewProjection->SetMatrix((float*)&worldViewProjectionMatrix);fxWorld->SetMatrix((float*)&wavesWorld);fxTexMatrix->SetMatrix((float*)&waterTexMatrix);fxDiffuseMap->SetResource(waterRV);fxSpecMap->SetResource(waterSpecRV);fxLightWVPVar->SetMatrix(wavesWorld*lightViewMatrix*lightVolumeMatrix);pass->Apply(0);md3dDevice->OMSetBlendState(waterBlendState, blendFactors, 0xffffffff);waves.draw();}md3dDevice->RSSetState(0);md3dDevice->IASetInputLayout(vertexLayout);skyBox.draw(eyePos,viewMatrix,projectionMatrix);// We specify DT_NOCLIPRECT R = {5, 5, 0, 0};md3dDevice->RSSetState(0);mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);mSwapChain->Present(0, 0);}This is the build shadows function.void SereneShoreLine::buildShadows(){D3D10_TECHNIQUE_DESC techDesc;    shadowBuildTech->GetDesc( &techDesc );    for(UINT i = 0; i < techDesc.Passes; ++i)    {   ID3D10EffectPass* pass = shadowBuildTech->GetPassByIndex(i);fxShadowBuild_LightWVPVar->SetMatrix(titan.getWorldMatrix()*lightViewMatrix*lightVolumeMatrix);fxShadowBuild_DiffuseMapVar->SetResource(titan.getDiffuse());pass->Apply(0);titan.getSphere()->draw();fxShadowBuild_LightWVPVar->SetMatrix(sandBottomWorld*lightViewMatrix*lightVolumeMatrix);fxShadowBuild_DiffuseMapVar->SetResource(sandRV);pass->Apply(0);sandBottom.draw();}}Everything I found just said to put the following in my update function (not shown)fxShadowMapVar->SetResource(0);tech->GetPassByIndex(0)->apply(0);but then i get the following when i move the windowD3D10: INFO: ID3D10Device::OMSetRenderTargets: A currently bound RenderTargetView is being deleted; so naturally, will no longer be bound. [ STATE_SETTING INFO #49: OMSETRENDERTARGETS_UNBINDDELETINGOBJECT ]D3D10: INFO: ID3D10Device::OMSetRenderTargets: A currently bound DepthStencilView is being deleted; so naturally, will no longer be bound. [ STATE_SETTING INFO #49: OMSETRENDERTARGETS_UNBINDDELETINGOBJECT ]and my shadows still don't draw, or if i lose focus of the window i get the original warningsThis has been driving me crazy for over a week now. If anyone has any idea please lend me a hand.Thanks   
  Seems like the resource you bind with fxShadowMapVar->SetResource(shadows.depthMap()) is also bound as the depth stencil. You need a separate depth buffer when you're drawing the scene if you want to use that one for shadows.   ;  I am reseting the depthbuffer with resetOMTargetsAndViewport();defined herevoid D3DApp::resetOMTargetsAndViewport(){md3dDevice->OMSetRenderTargets(1, &mRenderTargetView, mDepthStencilView);D3D10_VIEWPORT vp;vp.TopLeftX = 0;vp.TopLeftY = 0;vp.Width    = mClientWidth;vp.Height   = mClientHeight;vp.MinDepth = 0.0f;vp.MaxDepth = 1.0f;md3dDevice->RSSetViewports(1, &vp);}