Jump to content
  • Advertisement
Sign in to follow this  
InvalidPointer

Gaaah! Index out of bounds?! Why?

This topic is 3625 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'm working on a quick-and-dirty debug console for my pet engine/software engineering testbed and for some rather peculiar reason std::string::at() keeps throwing out-of-bounds excpetions in this little code segment. Would anyone have any tips or help in determining where the problem is? I suspect it's in the delimiting conditional, but some debug work by me yielded that temp always shows up as a whitespace even when the character it *should* be isn't. I can confirm that the passed-in command string is valid.
GMForceInline SupernaturalString ParseCommandLine(SupernaturalString cmdString) // tokenizes a string and executes the associated commands
	{
		// TODO: Do some search optimization, maybe figure out a means of generating a 'position' value for the std::map ops
		SupernaturalString cmd;
		bool keepGoing = true;
		CVarDBIter iter;
		size_t i = 0;
		do
		{
			char temp = cmd.at(i);
			if((temp != '\n') && (temp != ' '))
			{
				std::cout << temp << std::endl;
				cmd.push_back(temp);
				std::cout << cmd;
				++i;
			}
			else
			{
				keepGoing = false;
				break;
			}
		} while(keepGoing);
		iter = mappedVars.find(cmd);
		if(iter != mappedVars.end())
		{
			return mappedVars[cmd].AsString();
		}
		return string("Unknown variable " + cmdString);
	}
And on a side note, if anyone has any useful articles or design advice for debug consoles as a whole I'd love to get my hands on 'em :)

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by SiCrane
Well the obvious reason would be if the string doesn't contain a '\n' or a ' '.

Quote:
I can confirm that the passed-in command string is valid.


I did think of that one, but I also would agree that the problem is probably something really stupidly simple XD

Share this post


Link to post
Share on other sites
What is a "SupernaturalString" and why are you checking a locally created string rather than the parameter string? which is empty and causing the error.

Share this post


Link to post
Share on other sites
Quote:
Original post by CmpDev
What is a "SupernaturalString" and why are you checking a locally created string rather than the parameter string? which is empty and causing the error.


I knew it was stupid. Thanks!

(That's my string wrapper and extension class, created mostly for portability)

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!