enemynode is not a local variable, and is also not a member variable, so it must be a global variable. But it has to be initialised or you get a "segmentation violation".
I.e. you should not execute that part of Check() if enemynode is NULL.
Of course it doesn't seem like a good idea to have just one pointer to an "enemy node" in the first place - because you're likely to want multiple enemies at some point.
Actually - don't disregard the "scope" remark either.
The term scope is confusing - but all pointers have to be valid.
It just seems more likely that you forgot to initialise enemynode than l1driver, l1env, l1smgr or l1statustext
I don't find the term scope confusing, I imagine most other programmers don't either, if someone wants it explaining I will tell them, but it should be something as a programmer knows. No disrespect...
Its a good point that enemyNode might not be initialised, must have had my eyes closed!!!
Store it what a temp variable that will get over written every frame??? I would imagine something like:
cartoonit wrote:I don't find the term scope confusing, I imagine most other programmers don't either, if someone wants it explaining I will tell them, but it should be something as a programmer knows. No disrespect...
Its a good point that enemyNode might not be initialised, must have had my eyes closed!!!
Store it what a temp variable that will get over written every frame??? I would imagine something like:
OK, here's why I think the term "scope" is confusing here:
it refers to which functions have access to which variable, not to whether a variable has valid contents.
Say you have 3 variables, all named SomeVar:
char *SomeVar;
void func1()
{
int SomeVar;
...
}
void func2()
{
float SomeVar;
...
}
All three have the same name, but depending on scope, a different actual variable is used. That is called scope, and it is checked by the compiler. If a variable name is not in scope, you get a compiler error (something along the lines of "SomeVar not defined").
In a situation such as above, you may initialise a local variable while thinking you've initialised a global variable, so it CAN case the problem of dereferencing an invalid pointer, but scope is not the only possible cause of it.
Anyway, databandit, if your code crashes when it accesses camera->..., then perhaps the camera variable is not initialised properly.
Anonymous wrote:OK, here's why I think the term "scope" is confusing here:
it refers to which functions have access to which variable, not to whether a variable has valid contents.
Say you have 3 variables, all named SomeVar:
char *SomeVar;
void func1()
{
int SomeVar;
...
}
void func2()
{
float SomeVar;
...
}
All three have the same name, but depending on scope, a different actual variable is used. That is called scope, and it is checked by the compiler. If a variable name is not in scope, you get a compiler error (something along the lines of "SomeVar not defined").
In a situation such as above, you may initialise a local variable while thinking you've initialised a global variable, so it CAN case the problem of dereferencing an invalid pointer, but scope is not the only possible cause of it.
Anyway, databandit, if your code crashes when it accesses camera->..., then perhaps the camera variable is not initialised properly.
the variable is a global variable defined as core::vector3df . . .. the error i get is not a normal VC++ error . . . . it's an application error where it says send the info to microsoft or dont send it (i hope u get what i mean)
Well, assuming something goes wrong in DirectX, (which might prompt a "send to microsoft" dialog): it might still be caused by an error in your code - after all, in order for something to be fast, you'll want to do as little error-checking as you can get away with.
So if I were you, I'd make absolutely sure to ASSERT all my pointers while trying to find where it goes wrong.
If they're all valid, then maybe there's a problem with one of your drivers.
i've got another function which is almost the same except that it does not get the camera position every frame, but it get the camera position every time i press space...