Sign in to follow this  

[DX9] pink/green fullscreen flashing

This topic is 2545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm implementing my DX9 rendering path and ran into a problem when using CEGUI. Basically I had models/textures rendering fine, and I tried to implement a CEGUI element.

However if I ever call the cegui render function it somehow screws up the state of my d3d device such that I get the pink/green flickering on subsequent frames. I saw in an old post that this happens when you're rendering to an uninitialized buffer?

I'm clearing my main buffer each frame, and this loop is sufficient to produce the problem:




bool onlyonce = true;

void renderloop () {

_d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);
_d3dDevice->BeginScene();

if(onlyonce){
_ceguiSystem->renderGUI();
onlyonce = false;
}

_d3dDevice->EndScene();
_d3dDevice->Present(NULL, NULL, NULL, NULL);

}







Am I missing some other directx function needed to correctly clear/setup my main buffer? Calling renderGUI only a single time is enough to break the program until it exits. If I don't call it at all than I just get plain blue screen like I would expect.

Share this post


Link to post
Share on other sites
in
_d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);

you use D3DCOLOR_XRGB(0, 40, 100) to clean your back buffer. Th is color is not black. try D3DCOLOR_XRGB(0, 0, 0) to see what happened.

Share this post


Link to post
Share on other sites
I didn't say it was black, it's a deep blue color.

However when I get the problem it's very apparent that it's flashing between RGB (255,0,255) and (0,255,0), which is apparently the debug runtime's way of alerting you that your screen is not being cleared. I just don't understand why it's not being cleared when I call the clear function.

Share this post


Link to post
Share on other sites
The one thing I could think of is that CEGUI somehow drops the depth/stencil buffer, so your clear with D3DCLEAR_ZBUFFER fails. But that's a very blind shot. I'd have a look at what the DX debug runtimes have to say. And in PIX you can check the states before and after the CEGUI call and compare (or read them yourself if your device is not pure).

A solution (workaround?) could be to use DX 9 state blocks. Never used them myself, so I can't say if they even would work here or if they have some drawbacks (e.g. performance).

Hope that helps

Share this post


Link to post
Share on other sites
I looked at the debug runtime output, but I didn't see anything. Just a bunch of warnings about redundant state bindings. The clear method itself returns S_OK.


Direct3D9: (INFO) :======================= Hal HWVP device selected

Direct3D9: (INFO) :HalDevice Driver Style b

Direct3D9: :DoneExclusiveMode
Direct3D9: (INFO) :Using FF to VS converter

Direct3D9: (INFO) :Using FF to PS converter

Direct3D9: (INFO) :Enabling multi-processor optimizations
Direct3D9: (WARN) :Ignoring redundant SetRenderState - 7

'Water.exe': Loaded 'C:\Windows\System32\D3DCompiler_43.dll', Cannot find or open the PDB file
'Water.exe': Unloaded 'C:\Windows\System32\D3DCompiler_43.dll'
'Water.exe': Loaded 'C:\Windows\System32\D3DCompiler_43.dll', Cannot find or open the PDB file
'Water.exe': Unloaded 'C:\Windows\System32\D3DCompiler_43.dll'
'Water.exe': Loaded 'C:\Windows\System32\D3DCompiler_43.dll', Cannot find or open the PDB file
'Water.exe': Unloaded 'C:\Windows\System32\D3DCompiler_43.dll'
'Water.exe': Loaded 'C:\Windows\System32\D3DCompiler_43.dll', Cannot find or open the PDB file
'Water.exe': Unloaded 'C:\Windows\System32\D3DCompiler_43.dll'
'Water.exe': Loaded 'C:\Users\Tim\Code\Water\CEGUIExpatParser_d.dll', Cannot find or open the PDB file
'Water.exe': Loaded 'C:\Users\Tim\Code\Water\CEGUISILLYImageCodec_d.dll', Cannot find or open the PDB file
'Water.exe': Loaded 'C:\Users\Tim\Code\Water\SILLY_d.dll', Cannot find or open the PDB file
'Water.exe': Loaded 'C:\Users\Tim\Code\Water\CEGUIFalagardWRBase_d.dll', Cannot find or open the PDB file
'Water.exe': Loaded 'C:\Windows\System32\clbcatq.dll', Cannot find or open the PDB file
Direct3D9: (WARN) :SetVertexDeclaration: NULL declaration pointer

Direct3D9: (WARN) :SetVertexDeclaration: NULL declaration pointer

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 28

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 15

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 22

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 8

Direct3D9: (WARN) :Ignoring redundant SetTextureStageState. Stage: 0, State: 2

Direct3D9: (WARN) :Ignoring redundant SetTextureStageState. Stage: 0, State: 1

Direct3D9: (WARN) :Ignoring redundant SetTextureStageState. Stage: 0, State: 5

Direct3D9: (WARN) :Ignoring redundant SetTextureStageState. Stage: 1, State: 1

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 137

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 28

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 7

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 15

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 22

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 8

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 174

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 14

Direct3D9: (WARN) :Ignoring redundant SetSamplerState. Sampler: 0, State: 1

Direct3D9: (WARN) :Ignoring redundant SetSamplerState. Sampler: 0, State: 2

Direct3D9: (WARN) :Ignoring redundant SetTextureStageState. Stage: 0, State: 2

Direct3D9: (WARN) :Ignoring redundant SetTextureStageState. Stage: 0, State: 3

Direct3D9: (WARN) :Ignoring redundant SetTextureStageState. Stage: 0, State: 1

Direct3D9: (WARN) :Ignoring redundant SetTextureStageState. Stage: 0, State: 5

Direct3D9: (WARN) :Ignoring redundant SetTextureStageState. Stage: 0, State: 6

Direct3D9: (WARN) :Ignoring redundant SetTextureStageState. Stage: 0, State: 4

Direct3D9: (WARN) :Ignoring redundant SetSamplerState. Sampler: 0, State: 6

Direct3D9: (WARN) :Ignoring redundant SetSamplerState. Sampler: 0, State: 5

Direct3D9: (WARN) :Ignoring redundant SetTextureStageState. Stage: 1, State: 1

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 27

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 206

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 19

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 20

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 207

Direct3D9: (WARN) :Ignoring redundant SetRenderState - 208

D3DX: (INFO) Using SSE2 optimizations
D3DX: Matrix should be 16-byte aligned for better performance
Direct3D9: (WARN) :SetVertexDeclaration: NULL declaration pointer

Direct3D9: (WARN) :SetVertexDeclaration: NULL declaration pointer

The program '[3216] Water.exe: Native' has exited with code 0 (0x0).


Share this post


Link to post
Share on other sites
That log is indeed not conclusive. Looks like you have to dig deeper using PIX.
Hmmm, maybe different viewport/clipping/render target ? I'm shooting in the dark, sorry.

Edit: Maybe I'm looking at it from the wrong side. Since this is a library you are using can be that either there's actually a bug or you are using it wrong (e.g. missing some begin/end call).

Share this post


Link to post
Share on other sites
Yeah it's possible that there either is a bug or I'm using it incorrectly. Though I'm just trying to think of what it could possibly do that would cause the problem.

If I unroll my loop my program runs like this:

_d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);
_d3dDevice->BeginScene();
_ceguiSystem->renderGUI();
_d3dDevice->EndScene();
_d3dDevice->Present(NULL, NULL, NULL, NULL); //frame is correct

_d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);
_d3dDevice->BeginScene();
_d3dDevice->EndScene();
_d3dDevice->Present(NULL, NULL, NULL, NULL); //green frame

_d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);
_d3dDevice->BeginScene();
_d3dDevice->EndScene();
_d3dDevice->Present(NULL, NULL, NULL, NULL); //magenta frame

_d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);
_d3dDevice->BeginScene();
_d3dDevice->EndScene();
_d3dDevice->Present(NULL, NULL, NULL, NULL); //green frame


etc..

So I'm just trying to figure out what it might be changing that is causing all my subsequent frames to fail which don't even call the library.

I'll take a look at PIX, haven't used it yet and not really sure how it can help me here, but I'll check it out.

Share this post


Link to post
Share on other sites
Weirdly enough it works properly when running in pix, though if I launch the executable directly it still has the problem.

Here's a log of the frame, which doesn't seem to have anything out of the ordinary:


4 <0x078A6150> IDirect3DDevice9::Clear(0x00000000, NULL, 0x00000003, D3DCOLOR_ARGB(0xff,0x00,0x28,0x64), 1.000f, 0x00000000) 5291568640
5 <0x078A6150> IDirect3DDevice9::BeginScene() 5291598848
6 <0x078A6150> IDirect3DDevice9::SetVertexShader(NULL) 5291604480
7 <0x078A6150> IDirect3DDevice9::SetPixelShader(NULL) 5291608576
8 <0x078A6150> IDirect3DDevice9::SetTexture(0, NULL) 5291611648
9 <0x078A6150> IDirect3DDevice9::SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1) 5291616768
10 <0x078A6150> IDirect3DDevice9::SetVertexShader(NULL) 5291620352
11 <0x078A6150> IDirect3DDevice9::SetPixelShader(NULL) 5291622400
12 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_LIGHTING, FALSE) 5291624960
13 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_FOGENABLE, FALSE) 5291665408
14 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE) 5291689472
15 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_ALPHATESTENABLE, FALSE) 5291713024
16 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE) 5291735552
17 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID) 5291759104
18 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE) 5291781632
19 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_ZWRITEENABLE, FALSE) 5291804672
20 <0x078A6150> IDirect3DDevice9::SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP) 5291827712
21 <0x078A6150> IDirect3DDevice9::SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP) 5291852288
22 <0x078A6150> IDirect3DDevice9::SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE) 5291875328
23 <0x078A6150> IDirect3DDevice9::SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE) 5291899392
24 <0x078A6150> IDirect3DDevice9::SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE) 5291922944
25 <0x078A6150> IDirect3DDevice9::SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE) 5291947008
26 <0x078A6150> IDirect3DDevice9::SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE) 5291970560
27 <0x078A6150> IDirect3DDevice9::SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE) 5291993600
28 <0x078A6150> IDirect3DDevice9::SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR) 5292017152
29 <0x078A6150> IDirect3DDevice9::SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR) 5292040704
30 <0x078A6150> IDirect3DDevice9::SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE) 5292064256
31 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE) 5292087808
32 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE) 5292110848
33 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA) 5292133888
34 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA) 5292156928
35 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_SRCBLENDALPHA, D3DBLEND_INVDESTALPHA) 5292179968
36 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_ONE) 5292202496
37 <0x078A6150> IDirect3DDevice9::SetTransform(D3DTS_VIEW, 0x5C291B10) 5292225536
38 <0x078A6150> IDirect3DDevice9::SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1) 5292230656
39 <0x078A6150> IDirect3DDevice9::SetVertexShader(NULL) 5292233216
40 <0x078A6150> IDirect3DDevice9::SetPixelShader(NULL) 5292235776
41 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_LIGHTING, FALSE) 5292238336
42 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_FOGENABLE, FALSE) 5292261888
43 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE) 5292284416
44 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_ALPHATESTENABLE, FALSE) 5292307456
45 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE) 5292329984
46 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID) 5292353024
47 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE) 5292375552
48 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_ZWRITEENABLE, FALSE) 5292398592
49 <0x078A6150> IDirect3DDevice9::SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP) 5292421120
50 <0x078A6150> IDirect3DDevice9::SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP) 5292445184
51 <0x078A6150> IDirect3DDevice9::SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE) 5292468224
52 <0x078A6150> IDirect3DDevice9::SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE) 5292496384
53 <0x078A6150> IDirect3DDevice9::SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE) 5292520448
54 <0x078A6150> IDirect3DDevice9::SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE) 5292544000
55 <0x078A6150> IDirect3DDevice9::SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE) 5292567552
56 <0x078A6150> IDirect3DDevice9::SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE) 5292591104
57 <0x078A6150> IDirect3DDevice9::SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR) 5292614656
58 <0x078A6150> IDirect3DDevice9::SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR) 5292641280
59 <0x078A6150> IDirect3DDevice9::SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE) 5292713472
60 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE) 5292738560
61 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE) 5292762112
62 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA) 5292785664
63 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA) 5292808704
64 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_SRCBLENDALPHA, D3DBLEND_INVDESTALPHA) 5292832256
65 <0x078A6150> IDirect3DDevice9::SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_ONE) 5292855296
66 <0x078A6150> IDirect3DDevice9::SetTransform(D3DTS_VIEW, 0x5C291B10) 5292878336
67 <0x078A6150> IDirect3DDevice9::SetViewport(0x00C7EF00) 5292887552
68 <0x078A6150> IDirect3DDevice9::SetTransform(D3DTS_PROJECTION, 0x03C560EC) 5292892672
69 <0x078A6150> IDirect3DDevice9::SetScissorRect(0x00C7EC04) 5292932608
70 <0x078A6150> IDirect3DDevice9::SetTransform(D3DTS_WORLD, 0x09F01C5C) 5292936704
71 <0x078A6150> IDirect3DDevice9::SetScissorRect(0x00C7EC04) 5292945408
72 <0x078A6150> IDirect3DDevice9::SetTransform(D3DTS_WORLD, 0x09F01604) 5292947968
73 <0x078A6150> IDirect3DDevice9::SetTexture(0, 0x078977F0) 5292953088
74 <0x078A6150> IDirect3DDevice9::DrawPrimitiveUP(D3DPT_TRIANGLELIST, 18, 0x03D1CE68, 24) 5292957696
75 <0x078A6150> IDirect3DDevice9::SetScissorRect(0x00C7EC04) 5292997632
76 <0x078A6150> IDirect3DDevice9::SetTransform(D3DTS_WORLD, 0x09F01E2C) 5293000704
77 <0x078A6150> IDirect3DDevice9::SetTexture(0, 0x078977F0) 5293005312
78 <0x078A6150> IDirect3DDevice9::DrawPrimitiveUP(D3DPT_TRIANGLELIST, 12, 0x03D1CA48, 24) 5293008384
79 <0x078A6150> IDirect3DDevice9::EndScene() 5293061632
80 <0x078A6150> IDirect3DDevice9::Present(NULL, NULL, NULL, NULL) 5293871616


Share this post


Link to post
Share on other sites
Simple, it has to do with your runtime/drivers. I'm assuming that you are using DX9 debug runtime or NVIDIA's PerfHud or some other debug driver, correct? It happens to me when I have it on as well.

It's been a long time, so I can't remember the details. IIRC, I think it has something to do with when you clear the screen and if something is being rendered. Sorry, I wish I could remember exactly :(

Share this post


Link to post
Share on other sites
Quote:
Weirdly enough it works properly when running in pix, though if I launch the executable directly it still has the problem.

device::Begin() , device::End(), check position of clear() call, is it between the pair? out of pair? is it called once per this pair?

Share this post


Link to post
Share on other sites
You probably mean BeginScene()/EndScene(). AFAIR Clear can be called anytime (several times even). karvosts calls it once before the pair, and if that did not work, he'd got a fail and a error in the debug log.

Sorry guys, I misunderstood. I just haven't had such "race condition" effects myself yet. Could really be something like that. On the other hand: The one CEGUI call triggers the behavior, so karwosts guess about screwed states sounds more like it IMHO.

Edit: Scissors don't seem to have an influence on Clear.
Oh, boy, I was so wrong:


Pseudo code:
set full viewport
clear(gray)
set viewport to left upper rectangle
clear(red)
set full viewport
set scissor rect to center rectangle and enable scissoring
clear(blue)


[Edited by - unbird on December 30, 2010 5:42:06 PM]

Share this post


Link to post
Share on other sites
Ah got it, it was the scissor operation. CEGUI doesn't reset the scissor rect when it exits, so it was only clearing a very tiny square of the background.

Have to reset the scissor myself before clearing.

Thanks all!

Share this post


Link to post
Share on other sites

This topic is 2545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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