visual studio 2003 MFC/SDI help drawing
-
ok I have made a program that simulates a petrol station (comming of cars etc..) it is a single MFC /SDI app in witch I made 2 functions first one delets the screen and the second one draws someting on the screen. I call this functions whit a timer (every 100ms) but there is a problem sometimes my program crashes and this is all that I get as help why it crashed Unhandled exception at 0x7c28af6a (mfc71d.dll) in seminarska.exe: 0xC0000005: Access violation reading location 0x00000004. So I'm sure that the problem is in this 2 functions : becouse if I run the program whit no drawing the program never crashes: ok here is the code for deleteing the screen: void CseminarskaView::brisi_ekran(void) { CDC*tabla=GetDC(); RECT Okno; GetClientRect(&Okno); CBrush copic(0xffffff); tabla->FillRect(&Okno,&copic); } and the code for drawing : void CseminarskaView::risi(Bencinska postaja[]) { //tukaj moram risati sproti CDC* tabla=GetDC(); RECT ena; ena.top=20; ena.left=20; ena.right=60; ena.bottom=60; int x1=0; int x2=0; int x3=255; int y=25; CString nizi; int i ; for (i=0;i<5;i++) { CString out; out.Format("%i",i+1); tabla->TextOut(10,y,out); CBrush pisalo(RGB(x1,x2,x3)); tabla->FillRect(&ena,&pisalo); ena.top=ena.top+60; ena.bottom=ena.bottom+60; x1=x1+60; x2=x2+60; x3=x3-60; y=y+60; //delete pisalo; } CString uu; y=25;int y1=500; for( i=0;i<5;i++) { for(int j=0;j { nizi=nizi+" I "; } tabla->TextOut(80,y,nizi); y=y+60; nizi=" "; uu.Format("postaja %i: %f",i,postaja[i].rezervar); tabla->TextOut(10,y1,uu); y1=y1+20; } } can someone please help me ? I think that the problem is CBrush but I'm not sure becouse sometimes the program finishes Ok sometimes not ///---there is no hope for you---\\\
-
ok I have made a program that simulates a petrol station (comming of cars etc..) it is a single MFC /SDI app in witch I made 2 functions first one delets the screen and the second one draws someting on the screen. I call this functions whit a timer (every 100ms) but there is a problem sometimes my program crashes and this is all that I get as help why it crashed Unhandled exception at 0x7c28af6a (mfc71d.dll) in seminarska.exe: 0xC0000005: Access violation reading location 0x00000004. So I'm sure that the problem is in this 2 functions : becouse if I run the program whit no drawing the program never crashes: ok here is the code for deleteing the screen: void CseminarskaView::brisi_ekran(void) { CDC*tabla=GetDC(); RECT Okno; GetClientRect(&Okno); CBrush copic(0xffffff); tabla->FillRect(&Okno,&copic); } and the code for drawing : void CseminarskaView::risi(Bencinska postaja[]) { //tukaj moram risati sproti CDC* tabla=GetDC(); RECT ena; ena.top=20; ena.left=20; ena.right=60; ena.bottom=60; int x1=0; int x2=0; int x3=255; int y=25; CString nizi; int i ; for (i=0;i<5;i++) { CString out; out.Format("%i",i+1); tabla->TextOut(10,y,out); CBrush pisalo(RGB(x1,x2,x3)); tabla->FillRect(&ena,&pisalo); ena.top=ena.top+60; ena.bottom=ena.bottom+60; x1=x1+60; x2=x2+60; x3=x3-60; y=y+60; //delete pisalo; } CString uu; y=25;int y1=500; for( i=0;i<5;i++) { for(int j=0;j { nizi=nizi+" I "; } tabla->TextOut(80,y,nizi); y=y+60; nizi=" "; uu.Format("postaja %i: %f",i,postaja[i].rezervar); tabla->TextOut(10,y1,uu); y1=y1+20; } } can someone please help me ? I think that the problem is CBrush but I'm not sure becouse sometimes the program finishes Ok sometimes not ///---there is no hope for you---\\\
when access the NULL pointer ,the ERROR would appeal .
ALTF4 wrote:
Unhandled exception at 0x7c28af6a (mfc71d.dll) in seminarska.exe: 0xC0000005: Access violation reading location 0x00000004.
the variable CBrush pisalo in the funtion risi() is abuse when for-loop run . so you should define a ptr outside for-loop like this ... CBrush* pBrush ; ... for(..) { pBrush= new CBrush(...) tabla->FillRect(..); delete pBrush; } 路漫漫其修远兮,吾将上下而求索。
-
when access the NULL pointer ,the ERROR would appeal .
ALTF4 wrote:
Unhandled exception at 0x7c28af6a (mfc71d.dll) in seminarska.exe: 0xC0000005: Access violation reading location 0x00000004.
the variable CBrush pisalo in the funtion risi() is abuse when for-loop run . so you should define a ptr outside for-loop like this ... CBrush* pBrush ; ... for(..) { pBrush= new CBrush(...) tabla->FillRect(..); delete pBrush; } 路漫漫其修远兮,吾将上下而求索。