Jump to content
  • Advertisement
Sign in to follow this  
rsborl

[Visual C++ 2008 Express] Porting issues

This topic is 3412 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 made a game using Dev-C++, and currently transferred it over to Visual C++ 2008 Express. The code worked fine before. How I transferred it was to simply move over all the files and include them to the VC++ project. For some reason, I am getting a "Access violation writing location 0x00000000" error, even when that part of my program does not use pointers. VC++ pointed the error in a low-level system function, so I moved up the stack frame and traced the cause to my program: EventList.h
class EventList
{
public:
protected:

  static void post(string sSource, string sMessage, string sEventLabel);
  static list<string> s_events;
};
EventList.cpp (holds the offending function)
#include "EventList.h"

list<string> EventList::s_events;

void EventList::post(string sSource, string sMessage, string sEventLabel)
{
  s_events.push_back(sSource + sEventLabel + sMessage);
}
The post function causes the error. If I comment out that line, the program continues to execute, but runs into another similar error in another function. I am wondering, is the problem in the code or a setting in VC++?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by SiCrane
When you get the access violation is it before or after main() begins?


Before, in the global namespace, above the main function.

Share this post


Link to post
Share on other sites
It sounds like your program relied on s_events being initialized before being used by other static objects. Unfortunately, C++ gives no guarantee as to the order of initialization of objects of static storage duration in different translation units. So basically, it sounds like it's a problem with your code.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
It sounds like your program relied on s_events being initialized before being used by other static objects. Unfortunately, C++ gives no guarantee as to the order of initialization of objects of static storage duration in different translation units. So basically, it sounds like it's a problem with your code.


Hmm, so the program might have been attempting to use s_events before it was even placed in memory? Because, in my case, s_events doesn't need any initialization; it just needs to be created and its constructor called.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Having its constructor called is initialization.


I see. Thanks very much for the help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!