Archived

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

tscott1213

CreateSurface Not Setting lPitch Correctly

Recommended Posts

tscott1213    151
I am loading a bitmap onto a DirectDraw surface. The call to CreateSurface()is not setting the lPitch parameter correctly for one of the bitmap files. I am calling CreateSurface() in the following manner: ZeroMemory( &ddsd, sizeof(ddsd) ); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = bmp.bmWidth; ddsd.dwHeight = bmp.bmHeight; if(FAILED(hr = pDD->CreateSurface(pddsd, &m_pdds, NULL))) return hr; The surface created for most of the bitmaps has an lPitch of 8192, but one of the bitmaps has a bmWidthBytes of 8196. Depending on the order with which I load the bitmaps the call to CreateSurface() either 1) creates a surface with an lPitch of 8192 (which is obviously too small) or 2) creates a surface with an lPitch of 10928 (in which case everything is fine). Thanks Todd

Share this post


Link to post
Share on other sites
tscott1213    151
I am using DirectX 8.1b.

I have figured out a work-around but I don''t understand why this was happening.

If I force the surface to be in System Memory the bitmap loads fine, if I either force it into Video Memory or don''t specify then the lPitch is set incorrectly.

I believe that the program works when I change the order in which the bitmaps are loaded because I run out of Video Memory and it ends up in System Memory.

What is scary here, is that I am not getting an error message when the CreateSurface() function is called. So right now my program is putting all bitmaps into System Memory which is very inefficient.

Thanks for the help
Todd

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
This is a driver bug. If you don''t specify the memory type for the surface, the video driver gets first crack at trying to create it. If it fails, then the DDraw will allocate the surface in system memory. From what you''ve described, the video driver isn''t failing the creation of the surface, even though it''s unable to create an offscreen plain surface with a pitch greater than 8K bytes.

What display hardware exhibits this problem? I''m assuming you''ve got the latest driver from the manufacturer''s website?

Does the driver report DDCAPS2_WIDESURFACES support?

Share this post


Link to post
Share on other sites
tscott1213    151
I am getting the error on an IBM T20 laptop.

I will check the WIDESURFACES flag. I scanned through the emails on this web site and someone else (addressing a similiar problem) pointed out that some older video cards aren''table to generate offscreen surfaces that were larger than the primary surface.

I will check for the newest drivers and in the future will check this flag in my code!

Thanks alot for helping me with this. Its taken me a some time to get to the heart of this one!

Todd

Share this post


Link to post
Share on other sites