3D Game Engine Design Souce Code Problem

Started by
1 comment, last by hplus0603 18 years, 3 months ago
I was trying to comple some souce code from this book and I got the following runtime error: Unhandled exception at 0x004d5724 in Pandoras Legacy.exe: 0xC0000005: Access violation reading location 0x04974308. The error points to a line of code that says - m_NumPolys = m_NumPolys + 1; Any ideas on what the problem is and how to fix it.
Advertisement
Well that is definately not enough information to solve the problem. Most of the times these things are caused by out of bounds memory access.here is an example:



char array[200];
int index;
char data;

index = 199;
data = array[index]; // no error
index = 200;
data = array[index]; // error (off by one.. must be 0-199)
index = -1;
data = array[index]; // error, must be positive



the snippet you provide is increasing your global (m_ prefix) variable for a poly count by one. Since this is a global variable it could be affecting many possible peices of data calculation. Basically look for anything that uses this variable and double check the code logic. The easiest way would probably bug the author of the book with the error report. They might even have a website, that already contains a bugfix. But one line of code for a program failure is not really going to help us identify your problem.
If you call into a deleted or clobbered object, or with a bad object pointer, then an access to a member variable may cause a crash.

For example:

class Foo {  public:    Foo() : mem_( 4 ) {}    int func() {      return 3;    }    int crash() {      return mem_;    }    int mem_;};void main() {  Foo * f = NULL;  std::cout << f->func() << std::endl;  // works (!)  std::cout << f->crash() << std::endl; // crashes}

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement