Sign in to follow this  
InvalidPointer

Gaaah! Index out of bounds?! Why?

Recommended Posts

InvalidPointer    1842
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
InvalidPointer    1842
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
CmpDev    100
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
InvalidPointer    1842
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this