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

Drawing Pixels causes illegal operation in windows?!

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

Hi, I sat back and pondered at this code. I wrote it myself and it seemed to work absolutely brilliently and then when I got back into Windows it spat out an ugly "This Program has Performed an Illegal Operation" message at me - and I didn''t like it one bit Anyway - here''s the source... HRESULT Draw_Random_Pixels(LPDIRECTDRAWSURFACE7 lpddsurface, RECT rectofpixels, bool entiresurface, int startcolor, int endcolor) { UCHAR palindex; int x; int y; DDRAW_INIT_STRUCT(g_ddsd) g_ddsd.dwSize = sizeof(g_ddsd); g_ddsd.dwFlags = DDSD_PITCH; lpddsurface->Lock(NULL,&g_ddsd,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); UCHAR *pixbuffer = (UCHAR *)g_ddsd.lpSurface; if(entiresurface == TRUE) { x = rand()%WINDOW_WIDTH; y = rand()%WINDOW_HEIGHT; } else { x = rand()%(rectofpixels.left - rectofpixels.right); y = rand()%( - rectofpixels.bottom); } if((startcolor == 0) && (endcolor == 0)) { palindex = rand()%256; } else { palindex = startcolor + rand()%endcolor; } pixbuffer[x+y*g_ddsd.lPitch] = palindex; lpddsurface->Unlock(NULL); return g_ddrval; } Remember this plots only 8 bit pixels to the screen... it works completely fine except when I went to debug the computer had a hard time swollowing this line: pixbuffer[x+y*g_ddsd.lPitch] = palindex; Why that one - I don''t know... Why windows does an illegal operation as well - I don''t know! Any help? Thanks, Destroyer

Share this post

Link to post
Share on other sites
I''m guessing you have this problem when entiresurface is FALSE?

x = rand()%(rectofpixels.left - rectofpixels.right);
y = rand()%( - rectofpixels.bottom);

Both x and y will be negative. You are accessing your array out of bounds. (This is probably the cause of most "Illegal Operations". Be sure to check your array indices!)

Share this post

Link to post
Share on other sites
Well thanks for telling me that - oops
How it worked in the first place in beyond my comprehension

But it's still performing an illegal operation! Here's the main thing that's been bugging me though - it's this...

pixbuffer[x+y*g_ddsd.lPitch] = palindex;

Whenever I go to debug it says it has an acess violation with this line! But WHY!?
When I also went to debug it showed this...
CXX0030: Error: expression cannot be evaluated on that one line shown above !?!

Any other ideas ?



Edited by - Destroyer on June 8, 2001 8:15:23 AM

Share this post

Link to post
Share on other sites