Advertisement

Help with a runtime error

Started by January 22, 2003 02:53 AM
4 comments, last by yckx 21 years, 9 months ago
In my camera class I have 4 vectors: pos, view, up, and right. In my camera''s movement function I can create and use local vectors all I want, but as soon as I try to access any of the 4 vectors owned by the class, my program crashes when I try to rum it. When I debug it I get a warning that reads: Access violation (Segmentation fault) raised in your program. and the debugger points to the line of code referring to the vector. I''m using Dev-C++. I''m fairly new to this, so I''m not real sure what the error is telling me, and even less sure how to solve it. Can somebody help me? Thanks. yckx
Hello,

A guess is: uninitialized variable!

Regards,
Deficite
Regards,
Deficte
Advertisement
Sounds like your code is trying to use uninitialised memory as though it were a camera instance. Can you show us the code where you create and use the camera?
That seems to be what it was, I managed to get it working.

Thsnks.

yckx
Ok, I fixed this problem in the camera with a hack, but I''ve now run into it again. Apparently I don''t know what I''m doing Here''s the code:


  struct Color3{     float r, g, b;};struct MazeSide{     // other stuff     Color3 color;          MazeSide();};MazeSide::MazeSide(){     color.r = 0;     color.g = 0;     color.b = 0;}Maze::Maze(){         renderCube = true;          for(int i = 0; i < 6; ++i)     {          mazeArray[i] = new MazeSide;          mazeArray[1]->color.r = 0.2;  //<- problem!          mazeArray[i]->color.g = 0.2;          mazeArray[i]->color.b = 1.0;     }}  


This code compiles, but I get the same Access Violation error I was getting before. I set the color components = 0 in the mazeSide constructor in an attempt to init the variable, but apparently that isn''t doing it?

How do I fix this properly?

Thanks

yckx
There's no need to initialize r, g and b to zero as long as you set them to something before you use them.

A more likely problem is that your loop writes outside the bounds of mazeArray.

EDIT: Or perhaps mazeArray is an uninitialized or previously deleted pointer to some space on the heap?


[edited by - micepick on January 25, 2003 12:46:32 PM]

This topic is closed to new replies.

Advertisement