Sign in to follow this  
nickolas1011

Need help with weird d3d9 BeginScene failed

Recommended Posts

Hi, there. I'm a newbie, I have gotten D3DERR_INVALIDCALL [i]sometimes [/i]and [i]at some computers [/i]when render to surface. The Directx debug output show that BeginScene already in BeginScene/EndScene pair. I've done some research but got nothing. I know that I cannot call BeginScene in BeginScene/EndScene pair. But obviously I didn't.
My code looks like this:
[code]
while(running)
{
DoSomePrepare();
RenderToSurface(pASurface); // both RT surface are in D3DPOOL_SYSTEMMEM
DoOthrePrepare();
RenderToSurface(pAnotherSurface);
}

RenderToSurface(IDirect3DSurface9 *pSurface)
{
pRenderToASurface->BeginScene(pSurface, NULL); // BeginScene already in Begin/End pair
RenderScene();
pRenderToSurface->EndScene(D3DX_FILTER_NONE);
}
RenderScene()
{
// Use critical section lock resource
for_each(primitiveInScene)
{
DoCPUApplicationWork();
UpdateShaderParas();
BeginPass();
Render();
EndPass();
}
// Unlock critical section
}
[/code]
Another question:
Which is more efficient:
1. Begin/End effect for each primitive, just like what I do.
2. Begin/End effect one/several time(s) and use CommitChanges.

Any reply will be appreciated.

Share this post


Link to post
Share on other sites
I don't really see the cause of the invalid call for sure, however it would be interesting what exactly pRenderToASurface is, as the normal Direct3DDevice doesn't have any parameters in the BeginScene or EndScene-calls. This is pseudo-code, isn't it? It would be helpful to see your full code. Aside, how did you check for the invald calls? Using the debugger or with some debug-output with files or messageboxes? Did you use debug or release-mode? I experienced random invalid calls too, using the debugger in release mode.

[quote]Another question:
Which is more efficient:
1. Begin/End effect for each primitive, just like what I do.
2. Begin/End effect one/several time(s) and use CommitChanges.

Any reply will be appreciated. [/quote]

2. should be more efficient. What your 1. approach does is basically load and unload a vertex and pixelshader for every primitive. This is very expensive. Your main goal to get good performance is having as less shader switches as possible. Also, the effect framework restores the old renderstates from before the begin-call after every end-call, so this will be even more slow. To sum up: Sort your primitves for effects and draw them using as less begin/end as possible.

Share this post


Link to post
Share on other sites
pRenderToASurface is obviously an instance of ID3DXRenderToSurface.

What the OP should do is run the program under PIX; that will confirm where the other BeginScene call is coming from - a lot of D3DX calls for example will make standard D3D calls behind your back, so you really need to watch what they're doing.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this