Advertisement Jump to content


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


Stupid STUPID newbie question - DDraw buffer error

This topic is 6857 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:
qDXInterface::DrawPixel (POS position)
	UCHAR			color = rand()%256;

	ZeroMemory (&ddsd, sizeof(ddsd));


	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
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?


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.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!