delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/07/17/09:45:37

From: Jan Vanrie <Jan DOT Vanrie AT psy DOT kuleuven DOT ac DOT be>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: malloc/free blues - for Peter Claessens
Date: Thu, 17 Jul 2003 15:36:18 +0200
Organization: KULeuven
Lines: 237
Message-ID: <3F16A652.24B6FEA5@psy.kuleuven.ac.be>
References: <3F156434 DOT 3000508 AT psy DOT kuleuven DOT ac DOT be>
NNTP-Posting-Host: seven.kulnet.kuleuven.ac.be
Mime-Version: 1.0
X-Trace: naxos.belnet.be 1058448979 4687 134.58.127.12 (17 Jul 2003 13:36:19 GMT)
X-Complaints-To: abuse AT belnet DOT be
NNTP-Posting-Date: Thu, 17 Jul 2003 13:36:19 +0000 (UTC)
X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U)
X-Accept-Language: en
Cache-Post-Path: seven.kulnet.kuleuven.ac.be!unknown AT p100pw220 DOT psy DOT kuleuven DOT ac DOT be
X-Cache: nntpcache 2.4.0b5 (see http://www.nntpcache.org/)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

New (sometimes other) problems after restarting the comp. Here's another
crash dump + x/i .

Page Fault at eip=000c11dd, error=0004
eax=bc040400 ebx=0045e0dc ecx=0061ade4 edx=bc1a1a4c esi=0061ade4
edi=2f010100
ebp=002667f8 esp=002667ec program=C:\SRC\DOTS2002\DOTREAD.EXE
cs: sel=00af  base=83dde000  limit=ffaf1fff
ds: sel=00b7  base=83dde000  limit=ffaf1fff
es: sel=00b7  base=83dde000  limit=ffaf1fff
fs: sel=00c7  base=00000000  limit=0010ffff
gs: sel=00c7  base=00000000  limit=0010ffff
ss: sel=00b7  base=83dde000  limit=ffaf1fff
App stack: [002677c4..001677c4]  Exceptn stack: [00167718..001657d8]

Call frame traceback EIPs:
  0x000c11dd free+245, file malloc.c
  0x0006d30e destroy_bitmap+370, file c:/djgpp/allegro/src/graphics.c,
line 1165
  0x0001a04e sequence_trial2(trial*)+3626, file
c:/src/dots2002/sequencetrial.cp
  0x0005f98a .debug_pubnames+42821, file c:/src/dots2002/exp.cpp, line 730
  0x00033809 .debug_info+613, file c:/src/dots2002/irpreter.cpp, line 1006
  0x00024d51 .debug_line+817, file c:/src/dots2002/irpreter.cpp, line 211
  0x00023d59 interprete(std::string)+391, file
c:/src/dots2002/irpreter.cpp, lin
  0x0002366a cl()+250, file c:/src/dots2002/irface.cpp, line 74
  0x0002323e irface(int)+62, file c:/src/dots2002/irface.cpp, line 22
  0x00068a3a main+4576, file c:/src/dots2002/dotread.cpp, line 157
  0x000bc758 __crt1_startup+176, file crt1.c

0X0001a04e -> 117         destroy_bitmap(fixpage);  fixpage=NULL;

x/i 0xc11dd <free+245>:     mov    0x16164c(%eax),%eax

Peter Claessens wrote:

> Hey people,
>
> I have been chasing a bug in my program since a long time now. I am
> running out of both time and ideas.
> This is the problem:
> When I run the program, or at least the functions that I need, I
> encounter different types of runtime errors - either a segmentation
> fault, a page fault in both reading and writing, a freeze, and even a
> spontaneous reboot. And which is worse, the crashes occur at different
> points in the code. When I add statements meant for debugging, or run
> the program at different moments, the crash point often shifts.
>  From the types of errors, and form output of bfdsymify and gdb(5.3),  I
> learned that it had something to do with memory allocation or
> deallocation. Not surprising in a sense, since I have to allocate large
> chuncks of memory to create bitmaps (I am using allegro 4.0.3 -
> debugging version). Even using yamd (is it ok in combination with
> gcc3.2.3?) I can't figure out where I am making a mistake - also under
> yamd it crashes at different points. Btw, as to the allegro functions,
> you would expect them to return NULL when they are unable to allocate
> enough memory for a bitmap, for example, but they don't. Also here I
> simply get runtime errors in malloc/free functions, within the allegro
> library.
> The crashes occur in the environment that I usually run the program in
> (dos box in win98), but also in MS-DOS 6.22 with CWSDPMI, that's why I
> think it's not one of the win9x-related memory issues described in the FAQ.
> The program code is way too big to paste here, but at the bottom of this
> mail you will find a stripped-down version of the function that the
> program crashes in, without the actual drawing functions. I left in some
> crucial assignments. This function is embedded in a whole set of class
> declarations, so I am afraid that I can't send a readily compilable
> minimal code.
> Of course if anyone would feel like taking a look, I wouldn't mind
> sending the entire compilable source code of the program, together with
> the configuration files it needs to run, or an executable with debugging
> symbols.
> Maybe I am looking over something very simple. I wouldn't be surprised,
> I am autodidact in programming, and I miss some of the basis. Can
> someone tell me what I'm doing wrong, or what would be the next option
> in the debugging process?
>
> Thanks,
> Peter.
>
> The philosophy behind the code is the following. This program is meant
> to run, after an initial screen, sequences of image frames with brief
> exposure durations, followed by a response screen. The contents of the
> frames are a type of geometric objects (this is for a visual perception
> experiment).
> hierarchically: trial->sequence->frame (several, ordered)
> a frame 'contains' a dot lattice (or another type of geometric object)
> Typical values for the radius is 380, for dot radius something like 10,
> and a screen resolution of 1024*768 pixels.
>
> int sequence_trial2(trial* trialp) {
> /* INITIALIZING, PREPARING SEQUENCE */
>   sequence* seqP=trialp->seqp;
>   vector<frameinfo*>* frameinfovecptr;
>   frameinfovecptr=seqP->get_frameinfovecptr();
>   dotlattice* dltest=new dotlattice;
>   string latticeid=typeid(*dltest).name();
>   delete dltest;
>   double radius_, center_x, center_y;
>   if (initflag==false) {
>     frameinfo* frameinfoP=(*frameinfovecptr)[0];
>     void* frameP=frameinfoP->get_frameP();
>     if (frameinfoP->get_frametype()==latticeid) {
>       dotlattice* dotobjptr=reinterpret_cast<dotlattice*>(frameP);
>       radius_=dotobjptr->getbound().boundparam[0];
>       center_x=dotobjptr->getcenter().x;
>       center_y=dotobjptr->getcenter().y;
>     }
>     trials_init(round(radius_),round(center_x),round(center_y));
>     if (initflag==false) {
>       (*errlogp) << "Graphics mode not initialized." << endl;
>       return 1;
>     }
>     initflag=2;
>   }
>   // sometimes problems in next line
>   if (fixpage==NULL)
> fixpage=create_bitmap(round(2*radius+1),round(2*radius+1));
>   if (fixpage==NULL) {  cerr << "Problem acquring bitmap memory.";
> cin.get();  return 1;  }
>   double orienta=DBL_MAX;
>   double boa=1;
>   double gamma=M_PI/2.0;
>   int mirrorflag=0;
>   for (int i=frameinfovecptr->size()-1; i>=0;i--) {
>     frameinfo* frameinfoP=(*frameinfovecptr)[i];
>     void* frameP=frameinfoP->get_frameP();
>     if (frameinfoP->get_frametype()==latticeid) {
>       dotlattice* dotobjptr=reinterpret_cast<dotlattice*>(frameP);
>       orienta=dotobjptr->getorient();
>       boa=dotobjptr->getbea();
>       gamma=dotobjptr->getgamma();
>       mirrorflag=dotobjptr->getmirrorflag();
>       break;
>     }
>   }
>   int dotdiam=round(trialp->fixdotradius*2.0+1.0);
>   BITMAP* dot=create_bitmap(dotdiam,dotdiam);
>   if (dot==NULL) {  cerr << "Problem creating bitmap 'dot'." << endl;
> return 0;  }
>   dotcoint p01,p02;
>   p01.x=p01.y=round(trialp->fixdotradius);
>   double d;
>   for (p02.x=0; p02.x<dotdiam ; p02.x++) {
>     for (p02.y=0; p02.y<dotdiam; p02.y++) {
>       d=distancexy(p01,p02);
>       if (!(d>(trialp->fixdotradius+0.0))) putpixel(dot,p02.x,p02.y,red);
>     }
>   }
> // sometimes problems here
>   destroy_bitmap(fixpage);
> // sometimes problems here
>   if (resp_bmp==NULL) resp_bmp=create_bitmap(xmax,ymax);
>   if (resp_bmp==NULL) {  set_gfx_mode(GFX_TEXT,0,0,0,0);  cerr <<
> "Insufficient memory to create image."; cin.get();   return 1;  }
>   vector<dotco>* respvecptr=prepare_response(resp_bmp,5,orienta, boa,
> gamma, mirrorflag);
>   BITMAP* page;
> /* CREATE THE BITMAPS - problems!*/
>   for (int i=0; i<frameinfovecptr->size(); i++) {
>     frameinfo* frameinfoP=(*frameinfovecptr)[i];
>     if (frameinfoP->get_frametype()==latticeid) {
>       void* frameP=frameinfoP->get_frameP();
>       dotobject* dotobjptr=reinterpret_cast<dotlattice*>(frameP);
>       frameinfoP->set_lifetime(sequence_life);
>       if(dotobjptr->dotfill()!=0) { cerr << "Problem with field
> object."; return 1; }
>       page=NULL;
>       screenvec.clear();
>       dotcovector* dotarrptr=dotobjptr->getdotarrP();
>       int radius=round(dotobjptr->getbound().boundparam[0]);
>       int dotradius=round(dotobjptr->getdotradius());
>       dotcoint center, xy;
>       center.x=round(dotobjptr->getcenter().x);
>       center.y=ymax-round(dotobjptr->getcenter().y);
>       for (dotcovector::iterator
> i=(*dotarrptr).begin();i!=(*dotarrptr).end();i++) {
>         xy.x=round((*i).x);
>         xy.y=round(ymax-(*i).y);
>         screenvec.push_back(xy);
>       }
>       if (page==NULL) page=create_bitmap(2*radius+1,2*radius+1);
>       if (page==NULL) { set_gfx_mode(GFX_TEXT,0,0,0,0); cerr <<
> "Insufficient memory to create image."; cin.get(); return 1;   }
>       int xoffset=round((xmax-page->w)/2);
>       int yoffset=round((ymax-page->h)/2);
>       for(vector<dotcoint>::iterator i=screenvec.begin();
> i!=screenvec.end(); i++) {
>           if (((*i).x>-1)&&((*i).y>-1)&&((*i).x<xmax)&&((*i).y<ymax))
> circlefill(page,(*i).x-xoffset,(*i).y-yoffset,dotradius,fgcolor);
>       }
>       frameinfoP->set_framebmp_ptr(page);
>     }
>   }
>
> /* SHOW THE BITMAPS - no problem here*/
>   BITMAP* next_bmp=NULL;
>   frameinfo* nextframeinfoP=(*frameinfovecptr)[0];
>   next_bmp=nextframeinfoP->get_framebmp_ptr();
>   for (int i=0; i<frameinfovecptr->size(); i++) {
>     frameinfo* frameinfoP=(*frameinfovecptr)[i];
>     if (i!=frameinfovecptr->size()-1) {
>       nextframeinfoP=(*frameinfovecptr)[i+1];
>       next_bmp=nextframeinfoP->get_framebmp_ptr();
>     }
>     else {
>       next_bmp=resp_bmp;
>     }
>   }
>
> /* SHOW RESPONSE SCREEN - no problem here */
>   trialp->response=record_response(resp_bmp,respvecptr,dot);
>
> /* DESTROY THE BITMAPS - problems! */
>   destroy_bitmap(resp_bmp); resp_bmp=NULL;
>   if (fixpage!=NULL) {
>     destroy_bitmap(fixpage);  fixpage=NULL;
>   };
>   if (dot!=NULL) {
>     destroy_bitmap(dot);  dot=NULL;
>   };
>   if (respvecptr!=NULL) {
>     delete respvecptr;   respvecptr=NULL;
>   };
>   for (int i=0; i<frameinfovecptr->size(); i++) { // clean up the bitmaps
>     frameinfo* frameinfoP=(*frameinfovecptr)[i];
>     if (frameinfoP->get_framebmp_ptr()!=NULL) {
>       if (frameinfoP->get_lifetime()!=experiment_life) {
>         BITMAP* bmp_ptr=frameinfoP->get_framebmp_ptr();
>         destroy_bitmap(bmp_ptr);
>         frameinfoP->set_framebmp_ptr(NULL);
>       };
>     }
>   }
>   return 0;
> }

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019