Jump to content
  • Advertisement
Sign in to follow this  
the-beast

Release build from Windows explorer problems (C++)

This topic is 3940 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

Hi I've created a small C++ program in VS 2005 Express and I have a very annoying problem. First off here is some code (I will explain the code and problem below). CCSVParser.h
...
private:
struct Mod
	{
		wchar_t szName[MAX_PATH];
		int intApp;
		wchar_t szArgs[MAX_PATH];
		bool boolEnabled;
	};

	Mod *Mods[];
CCSVParser.cpp
...

bool CCSVParser::addToCSV(wchar_t szName[], int intApp, wchar_t szArgs[])
{
	Mods[intTotalMods] = new Mod();
	StringCbCopy(Mods[intTotalMods]->szName, MAX_PATH, szName);
	Mods[intTotalMods]->intApp = intApp;
	StringCbCopy(Mods[intTotalMods]->szArgs, MAX_PATH, szArgs);

	Mods[intTotalMods]->boolEnabled = true;

	intTotalMods++;

	return true;
}

bool CCSVParser::loadCSV(wchar_t szFileName[], int intListId, HWND hWnd)
{
... //In here we read the settings from a file, for each valid setting we do
addToCSV(szName, intApp, szArgs);
...
}
OK, what we have here is part of a class that parses a CSV file. Once it parses a valid line it calls the addToCSV() function, the array Mods is extended and is populated. This continues until the whole file has been dealt with. This works fine in Debug and Release mode when launched from the VS IDE, and the debug exe works fine when launched from Windows Explorer. The problems start when the release exe is launched from Windows Explorer. It hangs. I.e. it sits there doing nothing. After going through the code I have determined that it can call the addToCSV() function 3 times (It does not matter what data is used to populate the array, it hangs with any sort of data) before it hangs and it hangs on the
Mods[intTotalMods] = new Mod();
line. No exception is thrown and if I add a line below the above to see if the memory assignment was successfully it does not get executed. I've tried replacing 'Mod *Mods[];' with 'vector<Mod> Mods' but the compiler complains that I have not specified the size of the array and when I specify an initial size it says I can not do that. So in summary my question is simple, what have I done wrong that stops the program from running in release mode from Windows Explorer but works fine in any other build? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Nitage
Here you declare an array:
Mod *Mods[];

But I can't see where you're initializing it.


In the addToCSV() function every time I need a new element, or am I missing something?

Share this post


Link to post
Share on other sites
You declare a zero-size array of pointers. I didn't even think that was valid C++ but you learn something new every day. Either way, at no point do you ever allocate memory for that array so you can't safely add anything to it. Use a std::vector instead - that's what it's there for.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kylotan
You declare a zero-size array of pointers. I didn't even think that was valid C++ but you learn something new every day. Either way, at no point do you ever allocate memory for that array so you can't safely add anything to it. Use a std::vector instead - that's what it's there for.


I thought that because the compiler accepted it and the debug build worked that it had sorted out the memory itself. At least I know to avoid that sort of thing in future now.

I've done a quick change over to std::vector and it looks like it has solved the problem. I'll do a more thorough check tonight. Do I need to release the memory used by std::vector when I quit the application or will it do it for me?

Thanks

Share this post


Link to post
Share on other sites
A vector filled with Pointers does not free the memory if it leaves the scope. You have to do it yourself.

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!