Stupid STUPID newbie question - DDraw buffer error

Started by
5 comments, last by The_Minister 24 years ago
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
[email=mwronen@mweb.co.za" onmouseOver="window.status='Mail The_Minister'; return true" onmouseOut="window.status=' '; return true]The_Minister[/email]1C3-D3M0N Interactive
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)
Sorry forgot to mention that this function is just to see if it works.
The final version of it will be far more optimised.


The_Minister
[email=mwronen@mweb.co.za" onmouseOver="window.status='Mail The_Minister'; return true" onmouseOut="window.status=' '; return true]The_Minister[/email]1C3-D3M0N Interactive
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
[email=mwronen@mweb.co.za" onmouseOver="window.status='Mail The_Minister'; return true" onmouseOut="window.status=' '; return true]The_Minister[/email]1C3-D3M0N Interactive
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
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
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
Thanks guys.


The_Minister
[email=mwronen@mweb.co.za" onmouseOver="window.status='Mail The_Minister'; return true" onmouseOut="window.status=' '; return true]The_Minister[/email]1C3-D3M0N Interactive

This topic is closed to new replies.

Advertisement