Sign in to follow this  
Matthew Shockley

Why does this error?

Recommended Posts

I have this code:
static int __index(lua_State* L) {
	int *Ptr = (int*)lua_topointer(L, -2);
	const char *ind = lua_tostring(L, -1);
	Triangle O = GetPointerObject(Ptr);
	if (ind == "Name") { // This line is what I think errors
		lua_pushstring(L, O.Name.c_str());
	}
	else {
		lua_pushnil(L);
	}
	return 1;
}
And when I run the program in debug I get an error like this: invalid null pointer

Share this post


Link to post
Share on other sites
if(ind == "Name") compares pointers, not "strings." You are almost certainly going to take the false branch every time, because it's not doing what you want it to do.

There are several places you could be dereferencing a null pointer, but it's impossible to say without more information. Step through the code in your debugger.

Share this post


Link to post
Share on other sites
Well I think you have to use string operator there not directly string there. The another thing is that you have not mention that which error message you are getting. If you got the error in that line than it should be proper to use string operator there.

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