Vanishing BUFFERS!!! HELP PLEASE!!

Started by
8 comments, last by zebes 24 years ago
Now that I have screamed for help, here is my problem I have finally got a 16-bit engine (well, just plotting some pixels) and I *thought* I had page-flipping (using DirectX Flip) but now I am running into the same problem I had before. It seems that my primary buffer disappears after about 10 seconds of page flipping??? I have a command called bpixel16: void bpixel16(int x, int y, char r, char g, char b){ back_buffer[x + (y*ddsd.lPitch >> 1)]=_RGB(r,g,b); } This command simply draws a colored dot onto the backbuffer. I *never* write to the primary. And the command works great. I check for 555 and 565. Once again, the pixel is great. Below I have posted my main loop (just a small test). What it does is draw a bunch of red pixels, flip the surfaces, then draw a bunch of green pixels. Now, I have two surfaces (primary and secondary) one red and one green. The rest of the program simply flips the two surfaces ever so often until the ESC is pressed. Everything works great for about 10 seconds and then the *GREEN* surface disappears!! Turns to black! Now, I have a red and black surface flipping. What''s going on? Is the primary being erased or something? Below is my main loop and the source for the flip(); If this is not enough code to debug then I will gladly post the rest or even the whole thing (nothing to hide) Thanks for your help.... ******************************************************** int Game_Main(void *parms){ lockbackbuffer(); for(unsigned int count=0;count<1000000;count++){ bpixel16(rand()%SCREEN_WIDTH, rand()%SCREEN_HEIGHT, 31,0,0); } unlockbackbuffer(); flip(); lockbackbuffer(); for(count=0;count<1000000;count++){ bpixel16(rand()%SCREEN_WIDTH, rand()%SCREEN_HEIGHT, 0,63,0); } unlockbackbuffer(); while(!(KEY_DOWN(VK_ESCAPE))) { Sleep(500); flip(); } SendMessage(main_window_handle, WM_DESTROY,0,0); return(1); } // end Game_Main **************** FLIP void flip(void){ while(lpddsprimary->Flip(NULL, DDFLIP_WAIT)!=DD_OK); } ********************************** This might help out too: //------------------------------------------------------------ // CREATE PRIMARY AND SECONDARY SURFACE //------------------------------------------------------------ // Create the primary surface memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS / DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE / DDSCAPS_FLIP / DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; if (lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL)!=DD_OK){ log("\n**** ERROR ****\nCOULD NOT CREATE PRIMARY SURFACE\n"); MessageBox(main_window_handle, "ERROR - PRIMARY BUFFER", "", MB_OK); return(0); } else { log("\n-Created Primary Surface..."); } // Get the pointer to the back buffer ddscaps.dwCaps = DDSCAPS_BACKBUFFER; if(lpddsprimary->GetAttachedSurface(&ddscaps, &lpddsback)!=DD_OK){ log("\n**** ERROR ****\nCOULD NOT CREATE BACK SURFACE\n"); MessageBox(main_window_handle, "ERROR - BACK BUFFER", "", MB_OK); lpdd->Release(); return(false); } else { log("\n-Created Secondary Surface (backbuffer)..."); } //------------------------------------------------------------ // GET PIXEL FORMAT AND SETUP GBITS (8,15,16,24,32 bits) //------------------------------------------------------------ DDPIXELFORMAT ddpf; ZeroMemory (&ddpf,sizeof(ddpf)); ddpf.dwSize = sizeof(ddpf); lpddsprimary->GetPixelFormat (&ddpf); color_depth = ddpf.dwRGBBitCount; //INIT GBITS (for 555,565,etc...) if(color_depth=16){ GBITS=6; //565 } else { GBITS=5; //555 } **************************** Sorry for such a long post but this is REALLY starting to bother me! Thanks again! -zebes zebes@mindspring.com
zebes@mindspring.com
Advertisement
AFAIK you will have to repaint the whole buffer before you flip it. No guarentees are made as to the state of the buffers.

Hope this helps.
Zebes,

Don''t be discouraged. You are not going insane - i am seeing this problem also.

I only discovered it because i started using a clipper on my surfaces, and the part that was not being written to every frame disappeared. It is for this reason that i disagree with ikklit - i do not believe that you are expected to remove the clipper, refresh the surface, and then reattach it every frame. Also, i used the DirectX diagnostic tool (in the DX utilities) to disable DDraw hardware acceleration and found that the problem went away. It seems that the hardware is doing something that the HEL does not do and in terms of correct behaviour i would tend to trust the software emulation (which is of course slower).

BTW i have also found that it is the surface that starts out as the PRIMARY surface that goes missing - EVERY TIME. Never the (initial) backbuffer.

Anyway, if you have solved this problem then please let me know - otherwise i would be interested to know what kind of graphics card you have (mine''s a TNT2 Ultra).

Piers


Wow...I thought I was the only one with this problem

Well, I have also noticed that it seems like the primary too.

I also disabled hardware acceleration but it actually stopped the flipping.. wierd.

I also tried to force a refresh rate of 60hz and still the same problems.

I am still frustrated because it seems that noone else has had these problems.

I ALSO have a TNT Ultra 2 (16 meg) AGP
That is really wierd...I hope it isn''t some bug and just something I am doing wrong.

If I find out anything I will let you know...if you solve it then please tell me

Thanks
-zebes

zebes@mindspring.com
zebes@mindspring.com
Zebes,

I am now using the drivers published by nVidia rather than by the maker of my card (Guillemot) and everything is fine. I think it IS a bug, although the bit that is annoying me the most is that i have never seen this in a game i have bought. What is it that the developers are doing/not doing that we are/aren''t? Is there a way of detecting this situation and correcting it?

I have spoken to someone else who has a TNT2 and he told me that he had heard about problems like this but he wasn''t very specific - anyway he has a generic card and has been using the nVidia drivers all along.

As far as noone else having the problem - virtually all of the DirectX samples i have seen redraw everything every frame, so i think most people do that and so would never know. I have been using DX for about two years now and never had this problem before, and would never have found it if i had not started using the clippper for anything other than the whole screen area (so leaving bits that were not refreshed).

I am going to move on as before and keep this in the back of my mind - i think you should try changing drivers.

Good Luck

Piers

You can also use the DirectSurface function, IsLost(), to determin if the surface is lost, and if so using the Restore() funktion...
quote:Original post by Pellebert

You can also use the DirectSurface function, IsLost(), to determin if the surface is lost, and if so using the Restore() funktion...


The buffers wouldn''t be lost because there is no application switching. They''re just getting erased.

___________________________Freeware development:ruinedsoft.com
by the way to increase speed (a little) change your function to plot into a macro and you can usualy get a 3% boost in pixel plot speed (with the buffer pointer as a global).


-------------------------
I am imortal.
Heaven won''t have me, and hell is afraid I will take over
you might want to think about useing a macro instead of a function this will give you a 3% boost in pixel plot speed (every little bit helps).


_________________________
I am immortal.
Heaven won''t have me and Hell is afraid I will take over.
They keep sending me back!!!!
sorry about the double reply thing tweeked!!

This topic is closed to new replies.

Advertisement