Hello,
i have a pointer-understanding problem:
I wanted to write a little console,
but if i want to remove a string that should be displayed,
there is something strange:
It doesn't get removed, it simply stays,
and if i test with "if (currentString == NULL)" or
"if (!currentString)", the programm tells me the
string is still there.
I have also a problem with that on other places
of my programm, where i get errors because
i am accessing removed entitis,the problem there
is the same: a check on "Entity==NULL" doesn't success,
it tells me the entity was there and then crashes when
i access them!
(I won't list up all the code because thats the same problem, only in bigger!)
So how exactly do i get rid of a pointer and its content ?
Do i have to use ptr_remove, and additionally
set the variable to null by "variable = NULL" ?
I know it works if i set the variable on Null manually for strings, but this leads to the problem that i'm filling up my memory with Garbage.
Please, someone gimme an explanation here.
(I read the manual about that and i have some programming experience, but not in c-like languages)
STRING* currentString;
var consoleLifetime;
void print(STRING* str)
{
consoleLifetime = 100;
currentString = str;
}
void showConsole()
{
if (!currentString)
{
return;
}
consoleLifetime--;
draw_text(currentString,10,10, vector(255,255,255));
if (consoleLifetime < 0)
{
ptr_remove(currentString);
}
}
Spoken precisely,
i would need a function that removes an object,
and sets any pointer pointing to it to NULL,
not to an undefined state.
Unfortunately, the following had no effect,
because it only removes the local given pointer inside the function, not the pointers outside the function that i
really wanted to hit with that (like "currentString" in my previous example)
but i need something in the style of this:
void delete (ENTITY* ent)
{
ptr_remove (ent);
ent = NULL;
}