• Advertisement

Archived

This topic is now archived and is closed to further replies.

Access Violations and Hardware

This topic is 5036 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I recently had to start using an older computer to do my devoplment work on, ever since I did and started working on my current project I have had a great deal of problems with access violation errors. From my experince these are caused by pointers point to invalid data or not initilized. However as far as I can tell all the pointers I'm using are properly initilized and I'm not doing anything I haven't done a hundred times in fact major parts of the code are from previous projects I've done and worked fine. I can get the code I'm using to work properly without pointers but that means the project I'm working on will be less efficent. So I'm wondering if the problem could be the computer I'm working on. Its the only thing I can think of that could be causing the problem. Heres some code snippets to show and example of the problem.
class ContextHandler
{
   public:
      ContextHandler();
      bool display();
   private:
       RenderContext* screen_;
};

ContextHandler::ContextHandler()
{
   screen_= new MainScreen();
}

bool ContextHandler::display()
{
   screen_->display();
}


class MainScreen
{
   public:
      MainScreen();
      bool display();
   private:
       TextHandler* th_;
};

ContextHandler::MainScreen()
{
   th_= TextHandler::getInstance()}

bool ContextHandler::display()
{
   th_->displayAt(.5f,.5f);  // ***Causes Access Violation

ERROR**
  
}

class TextHandler
{
  public:
     static TextHandler* getInstance();
     void displayAt(float x, float y);
  private:
    static TextHandler* th_;
    float x_;
    float y_;
};

TextHandler* TextHandler::getInstance()
{
   static TextHandler* th_ = new TextHandler();
   return th_;
}

void TextHandler::displayAt(float x, float y)
{
   x_=x;
   y_=y;
}
As you can see I'm not doing anything out of the ordinary and I have done similar things many times without problems. So does anyone have any ide why now I'm getting access violations? ----------------------------------------------------- "Fate and Destiny only give you the opportunity the rest you have to do on your own." Current Design project: Ambitions Slave [edited by - TechnoGoth on May 7, 2004 6:40:25 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
This isn''t your actual code, right? Or am I missing somehing?

Your constructor "bool ContextHandler::ContextHandler()" has a return value? I bet this code won''t compile.

As it''s not possible to copy/paste from the code-tagged code I wasn''t able to try. Maybe you can post some compilable code, without using the code tag.

HW problems don''t cause access violations. HW problems will give you completely other type of problems, such as blue screens randomly occuring and will appear differently every time.

Your problem on the other hand seem fully reproducable, so it''s most certainly a bug in your code.

Why don''t you use a debugger and step it through to see what happens?

Share this post


Link to post
Share on other sites
While I can''t relate to this directly, maybe it could be caused by your operating system. Once I had written some stuff on a Win98 comp, then upgraded it to Win2K. The program caused error handling code in the project to trigger, even when the code still worked (turning off the error handler stuff made the program work fine).

I don''t really see how this could be a problem with access violations, even if you went from XP to 95. Could be a lot of stuff I guess. Have you got any other possible examples of stuff that causes the violations, or show us the code in action?

----------------------------------------------------------
You know, I might as well go ahead and say I can''t fix the problem... because that''s when I figure out how.

Share this post


Link to post
Share on other sites

  • Advertisement