Jump to content
  • Advertisement

Archived

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

The_Minister

Stupid STUPID newbie question - DDraw buffer error

This topic is 6697 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

The solution to this must be so simple. I feel like an idiot posting this. Anyways, I have primary and backbuffer surfaces in a flipping chain, now it''s time to mess with the surface by drawing pixels all over the place. Here is the code I have:
int
qDXInterface::DrawPixel (POS position)
{
	DDSURFACEDESC2	ddsd;
	UCHAR			color = rand()%256;

	ZeroMemory (&ddsd, sizeof(ddsd));

	lpBack->Lock( NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR / DDLOCK_WAIT, NULL );

	UCHAR	*buffer	= (UCHAR *)ddsd.lpSurface;
	int	lpitch	= (int)ddsd.lPitch;

	buffer[position.x + position.y * lpitch] = color; // error occurs here

	lpBack->Unlock( NULL );

	return 1;
}
The problem with the above code is that when it hits the line marked ''Error occurs here'', it shoves an access violation error in my face. Please tell me if this code snippet looks perfect, because then the problem causing the error is somewhere before this. Thanks guys. Oh yeah, the above code was written using LaMothe''s examples in Tricks of the Windows Game Programming Gurus as reference. The_Minister

Share this post


Link to post
Share on other sites
Advertisement
1) Don''t lock the surface for each pixel.
Lock surface -> draw all pixels -> unlock surface.

2) Don''t assume your surface lock is successful. Check its return value, and write pixels only when you know the lpSurface value is valid. (DD_OK)

Share this post


Link to post
Share on other sites
Well I'll be damned.
After ZeroMemory() I added:

ddsd.dwSize = sizeof(ddsd)

And it worked *gasp*.

I also added a primitive error handler. Very primitive.
BTW how do you intergrate them smiley faces into these posts?


The_Minister

Edited by - The_Minister on 4/16/00 6:28:39 AM

Share this post


Link to post
Share on other sites
All you have to do is type(without spaces and quotes) ": )" for a happy smiley, ": (" for a sad smiley, ": P" for a smiley with his tongue sticking out, "; )" for a smiley that's blinking with one eye. And of course there are other smileys, but these are the ones that come to mind right now.







/. Muzzafarath

Edited by - Muzzafarath on 4/16/00 6:59:09 AM

Share this post


Link to post
Share on other sites
Thats right Minister, DirectX tends to have size fields as the first 32bits of all it''s structs, so it knows what it is getting. It''s good practice, apparently.
If you don''t specify the size field, then it thinks its getting a zero size structure.

-Mezz

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!