Okay, here i am...
As i see, post is long, so please, read carefully, its not hard
So, i have a struct
typedef struct {
var s;
var i;
var j;
var step_max;
var step_left;
} CHARACTER;
Then, i have a text file, where info about CHARACTERs is stored..
For example, i have info about 2 characters:
first with
s=1; i=4; j=2;,
second one with
s=1; i=5; j=5; But, as character model are not created immideately, i need to store that info in vector. So i read my file:
players_number = file_var_read(fhandle);
vPlayers = createGSVector();
CHARACTER* tempChar = (CHARACTER*)malloc(sizeof(CHARACTER));
var i;
for (i=0; i<players_number; i++)
{
tempChar.s = file_var_read(fhandle);
tempChar.i = file_var_read(fhandle);
tempChar.j = file_var_read(fhandle);
tempChar.step_max = file_var_read(fhandle);
tempChar.step_left = file_var_read(fhandle);
insertIntoGSVector(vPlayers,tempChar);
}
On this step everything looking okay, and debugger shows that vector vPlayers consist of 2 elements, thats right
Next, i create 2 players models (first, in coordinate s=1; i=4; j=2; , second - in s=1; i=5; j=5;) and i want to load info about their step_left from vector
So, i add function
void GetPlayerInfo(var s,var i, var j)
{
ENTITY* tempEnt;
int num;
CHARACTER* tempChar = (CHARACTER*)malloc(sizeof(CHARACTER));
while(sizeOfGSVector(vPlayers)==0) {wait(1);}
very_very_temp = sizeOfGSVector(vPlayers);
wait(1);
for(num=0; num<sizeOfGSVector(vPlayers); num++) {
very_very_temp = num;
tempChar = (CHARACTER*)(getFromGSVector(vPlayers,num));
if ((tempChar.s == s) && (tempChar.i == i) && (tempChar.j == j))
{
tempEnt = ReturnModelPointer (TypeModel,s,i,j);
tempEnt.sPlayerStepsMax = tempChar.step_max;
tempEnt.sPlayerStepsLeft = tempChar.step_left;
very_very_temp = tempEnt.sPlayerStepsLeft;
// eraseFromGSVector(vPlayers,num);
tempChar = NULL;
break;
}
tempChar = NULL;
}
}
In this function i go through vector, take elements one-by-one and compare element's s,i,j with models s,i,j.
If true, then i load step_max to entity's skill, if not, i'm proceeding to next element.
Now,
the problem:
If i have first entity with coordinates 1,5,5, and first element of vector has 1,5,5, then everything works okay.
BUT, if i compare first entity's 1,4,2 with first element with 1,5,5, then i come to the second vector's element (1,4,2) and in string
tempChar = (CHARACTER*)(getFromGSVector(vPlayers,num));
i got a crash
I tried to say it as simple as possible