Archived

This topic is now archived and is closed to further replies.

malyskolacek

Please help!!!

Recommended Posts

malyskolacek    121
Hi everybody! I have this problem: I''m locking a backbuffer and reading a pixel from it. But when I call IDirect3DSurface8::LockRect the program EXITS. In debug output is nothing. Some code: LPDIRECT3DSURFACE8 pSurf; if (FAILED(m_pd3dDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pSurf))) AfxMessageBox("Chyba v GetBackBuffer", NULL, MB_OK); pSurf->LockRect(&lRect, NULL, D3DLOCK_READONLY); //the program exits now, sometimes(I don''t know exactly when) occurs an exception in MSVCRTD.DLL offset=m_pPoint.y*lRect.Pitch+m_pPoint.x*2; memcpy(&pixel, (BYTE*)lRect.pBits + offset, 2); pSurf->UnlockRect(); VERY VERY please help me!! Thank you very much in advance

Share this post


Link to post
Share on other sites
invective    118
"If a RECT was provided to the LockRect call, pBits will be appropriately offset from the start of the surface"

How is your offset computed? Is this from the beginning of the buffer (wrong way) or beginning of the rect (right way)? If you want to specify ofset from start of surface, just pass NULL as the rect to lock the whole thing.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
I don''t think you can lock the backbuffer unless you specify some flag when creating that backbuffer. There is some kind of surface flag that is something like D3DFMT_D16_LOCKABLE. Read the docs on this.

Hope this helps,
/jk

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
I don''t think you can lock the backbuffer unless you specify some flag when creating that backbuffer. There is some kind of surface flag that is something like D3DFMT_D16_LOCKABLE. Read the docs on this.

Hope this helps,
/jk

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
I don''t think you can lock the backbuffer unless you specify some flag when creating that backbuffer. There is some kind of surface flag that is something like D3DFMT_D16_LOCKABLE. Read the docs on this.

Hope this helps,
/jk

Share this post


Link to post
Share on other sites
malyskolacek    121
The process of rendering in my app is more complicated. I'm making mouse selections this way: I render all meshes in color, then I lock the BackBuffer surface, get pixel information from it and compare with the meshes.Then I render again, this time with textures/lights/... and present it. First render is performed on an additional swap chain, the second on the default device chain. The selections don't work this way... If I try to debug the app, it exits on the line I showed in above post. Mouse selections are working only if in the second rendering are meshes rendered also in color. I can't figure the solution out of it.

Edited by - malyskolacek on November 8, 2001 9:22:28 AM

Share this post


Link to post
Share on other sites
malyskolacek    121
If it helps, I post the rendering code:

At the beginning:
LPDIRECT3DSWAPCHAIN8 m_chain;
LPDIRECT3DSURFACE8 m_chainsurf, m_renderchainsurf, m_dssurf;
m_pd3dDevice->GetDepthStencilSurface(&m_dssurf);
m_pd3dDevice->GetRenderTarget(&m_renderchainsurf);
m_pd3dDevice->CreateAdditionalSwapChain(&m_d3dpp, &m_chain);
m_chain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_chainsurf);


HRESULT CWeditDoc::Render()
{
SetupMatrices();
//m_bNeedFill is true when user has clicked
if (!m_bNeedFill) {
m_pd3dDevice->SetRenderTarget(m_chainsurf, m_dssurf);
if (FAILED(m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 )))
return E_FAIL;
if (FAILED(m_pd3dDevice->BeginScene())) return E_FAIL;
m_pd3dDevice->SetRenderState(D3DRS_AMBIENT,0xffffffff);
m_pd3dDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT);
for (int hh=0;hh //m_bRenderColor tells, if the mesh should be rendered in color rather than with texture
m_oMeshes[hh].m_bRenderColor=TRUE;
m_oMeshes[hh].Render(m_pd3dDevice);
}
if (FAILED(m_pd3dDevice->EndScene())) return E_FAIL;
D3DLOCKED_RECT lRect;
int offset;
unsigned int pixel=0;
m_chainsurf->LockRect(&lRect, NULL, D3DLOCK_READONLY);
offset=m_pPoint.y*lRect.Pitch+m_pPoint.x*2;
memcpy(&pixel, (BYTE*)lRect.pBits + offset, 2);
m_chainsurf->UnlockRect();
unsigned int pixel2=0;
for (int c=0; c int r=m_oMeshes[c].m_color.r*255;
int g=m_oMeshes[c].m_color.g*255;
int b=m_oMeshes[c].m_color.b*255;
pixel2=((r/8)<<11) | ((g/4)<<5) | (b/8);
if (pixel==pixel2) break;
pixel2=0;
}
if (c FillToolBar(c, 0);
}else{
for (int a=0;a m_oMeshes[c].m_bRenderColor=FALSE;
SetCurMeshSelected(-1);
g_dMeshBar->ShowWindow(SW_HIDE);
g_fWnd->RecalcLayout();
}
m_bNeedFill=FALSE;
}else{
m_pd3dDevice->SetRenderTarget(m_renderchainsurf, m_dssurf);
if (FAILED(m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 )))
return E_FAIL;
if (FAILED(m_pd3dDevice->BeginScene())) return E_FAIL;
m_pd3dDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
m_pd3dDevice->SetRenderState(D3DRS_AMBIENT,0xffffffff);
m_pd3dDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
m_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
m_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
for (int g=0;g m_oMeshes[g].Transform(); m_oMeshes[g].m_bRenderColor=FALSE;
m_oMeshes[g].Render(m_pd3dDevice);
}
m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
for (int a=0;a if (m_iNumLights>0) {
for (int i=0;i m_pd3dDevice->LightEnable(i, TRUE);
m_pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
}
}
//FPS
ShowFPS(1,1);
if (FAILED(m_pd3dDevice->EndScene())) return E_FAIL;
if (FAILED(Render3d())) return E_FAIL; //does Present()
}
return S_OK;
}

Sorry, but this forum destroys all fors
Can you take a look at this??? thank you very very much

Edited by - malyskolacek on November 8, 2001 3:12:44 PM

Share this post


Link to post
Share on other sites