From: "Tan" Newsgroups: comp.os.msdos.djgpp Subject: General Protection Fault After 2000 movedata(); Date: 17 Jan 1997 05:54:14 GMT Organization: Home Lines: 111 Message-ID: <01bc0384$26a2c860$8713c2cf@586> NNTP-Posting-Host: vanc07m02-135.bctel.ca To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp I was doing a graphics rotine, copying bitmap from one virtual memory to linear buffer frame. I used movedata() to move memory, but after about 2000 movedata()'s, I got General Protection Fault at eip=000a161 eax=000000df ebx=000520e0 ecx=fff8848c edx=0000fa64 esi=00082b82 edi=00097000 ebp=000507dc esp=000507cc program=F:\GRA\TEST1.EXE cs: sel=00af base=82ca2000 limit=0005ffff ds: sel=00df base=83086000 limit=00096fff es: sel=00d7 base=c2afa000 limit=00096fff fs: sel=00df base=83086000 limit=00096fff gs: sel=00c7 base=00000000 limit=ffffffff ss: sel=00b7 base=82ca2000 limit=0005ffff Call frame traceback EIPs: 0x0000a161 0x00001e60 0x00002fd9 0x00003766 The function I used was: typedef struct { int id; int x1; int y1; int x2; int y2; int clip_flag; int clip_x1; int clip_y1; int clip_x2; int clip_y2; int bytes_per_pixel; unsigned int pal_id; unsigned long linear; unsigned long handle; unsigned long size; int segment; } bitmap; AFTER I USE THIS FUNCTION FOR 146 TIMES, I WILL GET PROBLEM FOR SURE!! I have no idea why. int CopyBMP(bitmap s_BMP, int s_x1, int s_y1, int s_x2, int s_y2, bitmap d_BMP, int d_x, int d_y) { int length, height, i; unsigned int s_offset, d_offset; int temp; ********************************************************************** Below is the clipping part which shouldn't be wrong ********************************************************************** if(s_x1 > s_x2) { temp = s_x1; s_x1 = s_x2; s_x2 = temp; }; if(s_y1 > s_y2) { temp = s_y1; s_y1 = s_y2; s_y2 = temp; }; if((s_x1 >= s_BMP.x2) || (s_y1 >= s_BMP.y2) || (d_x >= d_BMP.clip_x2) || (d_y >=d_BMP.clip_y2) || (s_x1 == s_x2) || (s_y1 == s_y2)) return; if(s_x1 < 0) { d_x = d_x - s_x1; s_x1 = 0; } if(s_y1 < 0) { d_y = d_y - s_y1; s_y1 = 0; } if(s_x2 > s_BMP.x2) { s_x2 = s_BMP.x2; } if(s_y2 > s_BMP.y2) { s_y2 = s_BMP.y2; } if (d_x < d_BMP.clip_x1) { s_x1 = s_x1 + (d_BMP.clip_x1 - d_x); d_x = d_BMP.clip_x1; } if (d_y < d_BMP.clip_y1) { s_y1 = s_y1 + (d_BMP.clip_y1 - d_y); d_y = d_BMP.clip_y1; } if( (s_x2 - s_x1) > (d_BMP.clip_x2 - d_x) ) s_x2 = d_BMP.clip_x2 - d_x + s_x1 + 1; if( (s_y2 - s_y1) > (d_BMP.clip_y2 - d_y) ) s_y2 = d_BMP.clip_y2 - d_y + s_y1 + 1; s_offset = (s_BMP.x2 * s_y1 + s_x1) * s_BMP.bytes_per_pixel; d_offset = (d_BMP.x2 * d_y + d_x) * d_BMP.bytes_per_pixel; length = (s_x2 - s_x1) * s_BMP.bytes_per_pixel; height = s_y2 - s_y1; ********************************************************************** The problem after here; but I dont know why ********************************************************************** for (i=0; i