From: Isaac Waldron Newsgroups: comp.os.msdos.djgpp Subject: Re: I'm going slightly mad!! Date: Mon, 02 Mar 1998 19:38:48 -0500 Organization: The Computer Nerd Lines: 72 Message-ID: <34FB5118.2A79F66E@lr.net> References: Reply-To: waldroni AT lr DOT net NNTP-Posting-Host: plym2-2.worldpath.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Andy Maddison wrote: > I've been using DJGPP for a while now, just basic C++ 3d graphics > programming, and everything has been going quite well. But now I've run > into some strange problems: > > When I execute my current piece of work I sometimes get a General > Protection Fault or Floating Point Error, but not everytime! > So why does an unchanged program crash periodically? > > Stranger still: I've had the above errors occur when I've simply invoked > gcc to compile my program (for the first time), i.e. gcc crashed without > compiling, but on subsequent attempts all went well with compilation and > linking (gxx). But then my program crashed again. > > I've used gdb which imforms me where the error occurs but I've checked > the code and there shouldn't be a problem, I've called the same function > many times before with the same argument types and all went as expected. > > I've also had an older program crash (with similar errors) when I > executed it during the same session, but it has always worked with no > problems. > > The current program reads some tri-mesh data from a text file, i.e. > vertex and face information, and creates new instances of vertices (200+) > and polygons (400+). The number of vertices and faces is read at the > beginning of the file. So the code looks something like this: > > read number of vertices and faces from file > (code snipped) > I've inserted statements within the loop to print out the data as it is > read just to double check that it is being read correctly - and it is! > > Could the problem be memory related? > > I'm running Windows95 and I've got 32Mb in my machine, is this automatically > used by my program? > > Due to the use of edge lists for storing the polygon's data, each polygon > takes up in excess of 3k. But I'm freeing this memory when each > polygon is destroyed. > > The funny thing is that I've tried commenting out various different parts of > the code and recompiling, but I can't seem to narrow the error down to a > specific line of code. I've also tried using hard coded values for the > vertices and polygons, i.e. not reading from the file at all. > > If you can throw some light on this situation, then please do. > > Thanks. Andy, I am too working on a 3D graphics engine with DJGPP (or, more accurately, I've completed it except for one feature, texture mapping). In the late testing stages, I came up against this type of problem (eg. GPF or FPE). What I ended up doing was single stepping my code by hand and checking for errors in mathematics. I found that in my Vector class, which has a magnitude() member function that returns the "length" of a vector, and a normalize() member function which changes the length of the vector to 1, but leaves the direction alone. It does this by dividing each of the x, y, z values in the Vector by the magnitude. This will, of course, wreak havoc if the magnitude of the Vector is 0, because it tries to divide by 0. This causes an FPE to be thrown, and the app crashes. In any case, I would suggest single stepping by hand all of your code for one object being display, and pay particular attention to places where division occurs. -- Isaac Waldron http://www.geocities.com/SiliconValley/Lakes/3574/index.html