Skip to main content
gamedev.net
🔒 Locked

Unhandled Exception Error

Started by Dave12 Jan 27, 2004 at 10:14 PM 1 replies 550+ views
Original Post
Dave12
Dave12
Strange thing happened to me when I tried to run just a little program to plot random pixels on the screen, I compiled and got no errors, but when I ran it it freezes up. When I debug it, it says that I have an unhandled exception. The culprit is somewhere in this area.
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);

if(FAILED(lpddsprimary->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))
	return (0);


int mempitch = (int)ddsd.lPitch;
UCHAR *video_buffer = (UCHAR *)ddsd.lpSurface;


//plot 1000 random pixels

for(int index=0; index<1000; index++)
{
	UCHAR color = rand()%256;
	int x = rand()%640;
	int y = rand()%480;

	video_buffer[x+y*mempitch] = color;
}

if(FAILED(lpddsprimary->Unlock(NULL)))
Raloth
Raloth
Isn't pitch the # of bytes to get to the next row of data? Check your value for pitch. I'm guessing it's way larger than you think it is.

[edited by - Raloth on January 27, 2004 11:22:15 PM]
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
jacklin
jacklin
It looks like your code is not taking into account of pixel size. It works if your are using 8 bits per pixel, but it will probably break for 16/24/32 bits per pixel.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.