Sign in to follow this  
SiS-Shadowman

Error when accessing class variable

Recommended Posts

i really don't know what *** **** is wrong here... i've written a simple class with some variables but no matter what i do, i can't access any of it from a function inside this class, i always get error messages, but WHY?!?!
class CScriptEngine
{
public:

	int maxpointers;
	int anzahlpointers;

... some more code ...

void ParseLine(char *line)
	{
		maxpointers = 5;


the debugger always gives me an error message, saying that i am violating memory when accessing this variable, i really don't know what is wrong, it's like c++ doesn't work anymore -.- the really funny thing is, that
void RegisterVariable(char *name, int *ptr)
	{
... some more code ...
		anzahlpointers += 1;
	}

DOES work, both functions are inside the 'class CScriptEngine' definition. please help me, this is driving me crazy -.-

Share this post


Link to post
Share on other sites
Normally that kind of error depicts that you're accessing a member variable w/o having a valid object (i.e. the "this" pointer is invalid). Are you sure that you access an allocated instance of the class?

Share this post


Link to post
Share on other sites
Fire up the debugger and take a look at your this pointer when you get an access violation. It sounds like you're trying to call functions on an invalid object, either NULL or an already deleted object, most likely.

Share this post


Link to post
Share on other sites
@EasilyConfused
i also can't see anything wrong, that is my code.
a friend of mine just told me that he thinks i might have a memory hole in my app, perhaps a buffer overrun or something else, i need to figure out, what is wrong, and where it happens, because my variables are filled with certain data, i didn't fill them with...

Share this post


Link to post
Share on other sites
Well then there is obviously something amiss outside of the class declaration. I meant, could you post the code where you instantiate, or use, the ScriptEngine class.

Share this post


Link to post
Share on other sites
well, i've rewritten the hole class, because i really got mad at the error.
the class was initialized at game startup ( and i checked this via debugger and my debug system ).
the funny thing is that on runtime, i got error when accessing any variable, declared in this class, although the class isn deleted ( i didn't find any call of the destructor..

but i've got new problems with some variables, because they aren't filled properly...

***edit*** ok, now i have it...
i use some global char *buffer to store data temporary. i also stored a value of a variable in it and gave it's pointer to my element. and because the buffer is also filled with other data, the value of my element changed

sometimes i really get confused with these pointers ~~

[Edited by - SiS-Shadowman on April 4, 2006 1:19:07 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by SiS-Shadowman
well, i've rewritten the hole class, because i really got mad at the error.
the class was initialized at game startup ( and i checked this via debugger and my debug system ).
the funny thing is that on runtime, i got error when accessing any variable, declared in this class, although the class isn deleted ( i didn't find any call of the destructor..

but i've got new problems with some variables, because they aren't filled properly...

***edit*** ok, now i have it...
i use some global char *buffer to store data temporary. i also stored a value of a variable in it and gave it's pointer to my element. and because the buffer is also filled with other data, the value of my element changed

sometimes i really get confused with these pointers ~~


If that's text data, you should be using std::string. :)

Oh, and I didn't know "the" is a curse word :)

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