Thread: Fixing bug in Quake 2 Engine!

  1. #1
    Registered User
    Join Date
    Jun 2007
    Location
    Rio de Janeiro, Brasil
    Posts
    48

    Question Fixing bug in Quake 2 Engine!

    Hello,

    I'm trying to fix the siamese twins bug in Quake 2, but I'm working with Quake 2 Evolved to be more precise...

    in resume mappers put the info_player entity a little below the surface to hide the spawn mark, so the map stay more pretty, but this cause this bug, which is 2 or more players spawned glued in the same spawnpoint without can move, aside can shot, look around, etc... here few pics:

    http://img182.imageshack.us/img182/9813/st01eo8.th.jpg http://img472.imageshack.us/img472/8829/st02ev3.th.jpg http://img475.imageshack.us/img475/2082/st03gl4.th.jpg

    Attention: this map have 7 spawnpoints, and was tested with only 4 players!

    http://img472.imageshack.us/img472/4278/st04fl4.th.jpg http://img182.imageshack.us/img182/1174/st05mj0.th.jpg http://img182.imageshack.us/img182/8939/st06ct5.th.jpg

    if you entered the map via DM, you will see this:

    http://img182.imageshack.us/img182/6...pfu1vf7.th.jpg http://img475.imageshack.us/img475/3...pfu2ol4.th.jpg

    after up the Z (+15) of the origin of the spawnpoints via hex and do the same, here is what we can see in DM

    http://img475.imageshack.us/img475/6...fix1hu0.th.jpg http://img182.imageshack.us/img182/9...fix2xi3.th.jpg

    I tested many many times for 1 hour, around 6 matches without one single problem.

    so I know exactly how to fix this problem, when game = arena is just add +15 to Z value in each info_player_deathmatch and info_player_start, and probally info_player_team1 and info_player_team2 too.

    Common Question

    Q: why not spawn a little higher?
    R: was my first thought, and work great in DM/TDM/CTF which I have the source, but I can NOT change the spawn or the killbox, because these functions are in DLL which are replaced with the ones at RA2 MOD, which I want to fix... but this source is NOT available."

    So theres only 2 options:

    1. Fix map by map, which we use more than 1500 maps, and probally around 1000 have this problem! a work for years...

    2. via code, when the game load the entities of the map, then add +15 in origin.z of the info_player classes...

    so, I'm working on #2.

    here the original function already with changes and my code to find the value change and comeback to the same string... the logic is done and will work, I only need a little help with C which I don't see for more than 8 years...

    here the code:

    Code:
    /*
     =================
     CM_LoadEntityString
     =================
    */
    static void CM_LoadEntityString (const byte *data, const lump_t *l){
    
        char   *game = Cvar_VariableString("fs_game");
    	int		i, j, Tam, TamNew;
    	int		PA, PB, PC, PD, PL, L1, Num, Espaco, Aspas;
    	char	*p, *ori, *HStr, *NewStr, *FinalStr;
    	char	*PartA, *PartB, *PartC, *PartD;
    
    	cm_numEntityChars = l->fileLen;
    	if (cm_numEntityChars < 1)
    		return;
    	if (cm_numEntityChars > MAX_MAP_ENTSTRING)
    		Com_Error(ERR_DROP, "CM_LoadMap: map '%s' has too large entity lump", cm_map);
    
    	cm_entityString = Hunk_Alloc(cm_numEntityChars + 1);
    	memcpy(cm_entityString, data + l->fileOfs, cm_numEntityChars);
    
    	// do string manipulation over cm_entityString if game = arena
    	if (!Q_stricmp(game, "arena")){
    		HStr = cm_entityString; // copy the original string to mine
    		Tam = strlen(HStr);
    		i=0;
    		j=0;
    	   while (j<Tam){
    		   while (HStr[j] != '}'){ // copy to NewStr each Class
    			   NewStr[i] = HStr[j];
    			   i++;j++;
    		   }
    		   NewStr[i] = HStr[j]; //add '}' to the end of the class
    		   p = strstr(NewStr, "info_player"); //see if is a spawn class
    		   if (!p){
    			   FinalStr = strcat( FinalStr, NewStr ); //if not, save and go to the next class
    		   }else{
    			   //if yes, start the hard work
                   ori = strstr(NewStr, "origin"); //find the origin position
    			   L1=atoi(ori); // converted to number
    			   L1 += 8; // than add +8 (origin" ") to that position, which will reach the numbers of the axis
    			   // find PartA from 0 to L1
    			   for (PA=0;PA==L1;PA++) //seta parte 1/4
    			   {
    					PartA[PA]=NewStr[PA];
    			   }
    			   PL=PA; //creat a new var to control the place in NewStr
    			   Espaco=0; //set to have zero spaces count
    			   // find PartB from start of numbers until 2nd space
    			   for (PB=0;Espaco!=2;PB++) //set part 2/4
    			   {
    					PL++;
    					PartB[PB]=NewStr[PL];
    					if (PartB[PB]==" ")
    						Espaco++;
    			   }
    			   Aspas=0; //set to plics to zero count
    			   // find PartC which is the Number, until reach next "
    			   for (PC=0;Aspas==1;PC++) //set part 3/4 = Num
    			   {
    				   PL++;
    					if (NewStr[PL]=='"')
    						Aspas = 1;
    					else
    						PartC[PC]=NewStr[PL];
    			   }
    			   TamNew = strlen(NewStr); //find the size of NewStr
    			   // find PartD from " after number until the end of class
    			   for (PD=0;PL==TamNew;PD++) //set part 4/4
    			   {
    				   PartD[PD]=NewStr[PL];
    				   PL++;
    			   }
    			   Num=atoi(PartC); // Convert to Number
    			   Num += 15; //add 15
    			   NewStr = strcat( PartA, PartB ); // make all 4 parts into one
    			   NewStr = strcat( NewStr, Num ); //------------------------------------------------- NEED TO CONVERT????!!!
    			   NewStr = strcat( NewStr, PartD );
    			   FinalStr = strcat( FinalStr, NewStr ); // add all NewStr to FinalStr
    		   }
    		i=0; //NewStr count to zero
    		j++;
    		NewStr=""; //erase NewStr
    	   }
    	cm_entityString = FinalStr; //replace the original by the new altered one
    	}
    }
    here's my doubts:

    HStr = cm_entityString;
    is this the right way to copy a string? then HStr will have the same value of cm_entityString??

    Tam = strlen(HStr);
    is this the right way to get the lenght of a string? Tam is a number right?

    ori = strstr(NewStr, "origin");
    is this the right way to receive the position of the NewStr that have origin??? in this case the position of "o"
    ori is a number or a pointer to the number that I want? or how can I get that number?

    NewStr="";
    is this the right way to empty a string?

    any other stuff made wrong in my code?

    thanks a lot!!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Yeah, there's quite a few problems with that code, mostly memory allocation problems.
    Some of your pointers would seem to be just small arrays used for copying short strings.

    One major problem not addressed at all is that your new string will be longer than your old string, say an input of "999" is 3 characters, but with 15 added, the result of "1014" needs 4 characters.

    Code:
    static void CM_LoadEntityString(const byte * data, const lump_t * l)
    {
        char *game = Cvar_VariableString("fs_game");
        int i, j, Tam, TamNew;
        int PA, PB, PC, PD, PL, L1, Num, Espaco, Aspas;
        char *p = NULL, *ori = NULL, *HStr = NULL, *NewStr = NULL, *FinalStr = NULL;
        char *PartA = NULL, *PartB = NULL, *PartC = NULL, *PartD = NULL;
        /*!! Set all pointers to NULL */
        /*!! It will tell you with more consistency if you're messing with */
        /*!! pointers before initialising them */
    
        cm_numEntityChars = l->fileLen;
        if (cm_numEntityChars < 1)
            return;
    
        if (cm_numEntityChars > MAX_MAP_ENTSTRING)
            Com_Error(ERR_DROP,
                      "CM_LoadMap: map '%s' has too large entity lump",
                      cm_map);
    
        cm_entityString = Hunk_Alloc(cm_numEntityChars + 1);
        memcpy(cm_entityString, data + l->fileOfs, cm_numEntityChars);
        /*!! If you need to make this a proper 'C' string, you need to add a \0 */
        /*!! cm_entityString[cm_numEntityChars] = '\0'; */
    
        // do string manipulation over cm_entityString if game = arena
        if (!Q_stricmp(game, "arena")) {
            HStr = cm_entityString;         // copy the original string to mine
            /*!! Not a copy, just another pointer to the same string */
            /*!! anything you do to HStr[i] will change cm_entityString[i] */
    
            Tam = strlen(HStr);
            i = 0;
            j = 0;
    
            while (j < Tam) {
                while ( HStr[j] != '}' ) {  // copy to NewStr each Class
                    NewStr[i] = HStr[j];
                    /*!! First pointer violation - where is NewStr pointing? */
                    i++;
                    j++;
                }
    
                NewStr[i] = HStr[j];  //add '}' to the end of the class
    
                p = strstr(NewStr, "info_player");  //see if is a spawn class
                if (!p) {
                    FinalStr = strcat(FinalStr, NewStr);  //if not, save and go to the next class
                    /*!! Second pointer violation - where is FinalStr pointing? */
                } else {
                    //if yes, start the hard work
                    ori = strstr(NewStr, "origin"); //find the origin position
                    L1 = atoi(ori); // converted to number
                    /*!! no, that's just atoi("origin"), which makes no sense */
                    L1 += 8;        // than add +8 (origin" ") to that position, which will reach the numbers of the axis
                    /*!! If you want to read the numbers, then it would be ori += 8 */
                    /*!! that is, 8 characters past the start of the word "origin" */
    
                    // find PartA from 0 to L1
                    for (PA = 0; PA == L1; PA++)  //seta parte 1/4
                    {
                        PartA[PA] = NewStr[PA];
                    }
                    PL = PA;        //creat a new var to control the place in NewStr
                    Espaco = 0;     //set to have zero spaces count
    
                    // find PartB from start of numbers until 2nd space
                    for (PB = 0; Espaco != 2; PB++) //set part 2/4
                    {
                        PL++;
                        PartB[PB] = NewStr[PL];
                        if (PartB[PB] == " ")
                            Espaco++;
                    }
                    Aspas = 0;      //set to plics to zero count
    
                    // find PartC which is the Number, until reach next "
                    for (PC = 0; Aspas == 1; PC++)  //set part 3/4 = Num
                    {
                        PL++;
                        if (NewStr[PL] == '"')
                            Aspas = 1;
                        else
                            PartC[PC] = NewStr[PL];
                    }
                    TamNew = strlen(NewStr);  //find the size of NewStr
    
                    // find PartD from " after number until the end of class
                    for (PD = 0; PL == TamNew; PD++)  //set part 4/4
                    {
                        PartD[PD] = NewStr[PL];
                        PL++;
                    }
    
                    Num = atoi(PartC);  // Convert to Number
                    Num += 15;      //add 15
    
                    NewStr = strcat(PartA, PartB);  // make all 4 parts into one
                    NewStr = strcat(NewStr, Num);   // -- NEED TO CONVERT????!!!
                    /*!! Yes you do need to convert, using say sprintf() */
                    NewStr = strcat(NewStr, PartD);
                    FinalStr = strcat(FinalStr, NewStr);  // add all NewStr to FinalStr
                }
                i = 0;              //NewStr count to zero
                j++;
                NewStr = "";        //erase NewStr
                /*!! This does not erase the string, it just makes it point somewhere else */
                /*!! But since it was never allocated in the first place.... */
            }
            cm_entityString = FinalStr; //replace the original by the new altered one
            /*!! As mentioned earlier, FinalStr was never allocated */
            /*!! Also, you would probably need to do Hunk_Free(cm_entityString) */
            /*!! before assigning it a new value */
        }
    }
    Here's my test code and results
    Code:
    void foo ( const char *msg ) {
        const char *p = msg;
    
        while ( p != NULL ) {
            char *origin = strstr( p, "origin" );   /* find origin */
            if ( origin != NULL ) {
                int x, y, z;
                int n, len;
    
                /* From the last position to the start of "origin" */
                printf("Head='%.*s'\n", origin - p, p );
    
                origin += 8;
                n = sscanf( origin, "%*[\"] %d %d %d %*[\"] %n", &x, &y, &z, &len );
                /* check n==3 for success */
                printf("Posn=%d,%d,%d; len=%d\n", x, y, z, len );
    
                /* Resume from the end of the processed origin */
                p = origin + len;
            } else {
                printf("Tail='%s'\n", p );
                p = NULL;
            }
        }
    }
    
    int main()
    {
        char test[] =
            "{\"classname\" \"worldspawn\"}"
            "{\"origin\" \"-256 248 16\"\"classname\" \"info_player_deathmatch\"}"
            "{\"classname\" \"info_player_deathmatch\"\"origin\" \"248 256 16\"}"
            "{\"origin\" \"248 -256 16\"\"classname\" \"info_player_deathmatch\"}"
            "{\"classname\" \"info_player_deathmatch\"\"origin\" \"-264 -256 16\"}"
            "{\"origin\" \"-176 -200 24\"\"classname\" \"weapon_rocketlauncher\"}"
            "{\"classname\" \"weapon_rocketlauncher\"\"origin\" \"-184 192 24\"}"
            "{\"origin\" \"168 184 24\"\"classname\" \"weapon_rocketlauncher\"}"
            "{\"origin\" \"-184 -264 24\"\"classname\" \"ammo_rockets\"}"
            "{\"classname\" \"ammo_rockets\"\"origin\" \"192 -256 24\"}"
            "{\"origin\" \"184 128 24\"\"classname\" \"ammo_rockets\"}"
            "{\"classname\" \"ammo_rockets\"\"origin\" \"-184 128 24\"}"
            "{\"origin\" \"216 -192 24\"\"classname\" \"weapon_rocketlauncher\"}"
            "{\"light\" \"400\"\"origin\" \"-8 0 208\"\"classname\" \"light\"}"
        ;
        foo(test);
        return 0;
    }
    
    $ gcc foo.c
    $ ./a.exe
    Head='{"classname" "worldspawn"}{"'
    Posn=-256,248,16, len=14
    Head='classname" "info_player_deathmatch"}{"classname" "info_player_deathmatch""'
    Posn=248,256,16, len=12
    Head='}{"'
    Posn=248,-256,16, len=14
    Head='classname" "info_player_deathmatch"}{"classname" "info_player_deathmatch""'
    Posn=-264,-256,16, len=14
    Head='}{"'
    Posn=-176,-200,24, len=15
    Head='classname" "weapon_rocketlauncher"}{"classname" "weapon_rocketlauncher""'
    Posn=-184,192,24, len=13
    Head='}{"'
    Posn=168,184,24, len=13
    Head='classname" "weapon_rocketlauncher"}{"'
    Posn=-184,-264,24, len=15
    Head='classname" "ammo_rockets"}{"classname" "ammo_rockets""'
    Posn=192,-256,24, len=13
    Head='}{"'
    Posn=184,128,24, len=13
    Head='classname" "ammo_rockets"}{"classname" "ammo_rockets""'
    Posn=-184,128,24, len=13
    Head='}{"'
    Posn=216,-192,24, len=14
    Head='classname" "weapon_rocketlauncher"}{"light" "400""'
    Posn=-8,0,208, len=11
    Tail='classname" "light"}'
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Location
    Rio de Janeiro, Brasil
    Posts
    48

    Thumbs up

    thanks for all the help... but few things I'm still in doubt....

    look:

    Code:
                while ( HStr[j] != '}' ) {  // copy to NewStr each Class
                    NewStr[i] = HStr[j];
                    /*!! First pointer violation - where is NewStr pointing? */
                    i++;
                    j++;
                }
    I was thinking that I was pointing to position 0 of NewStr...
    should I declare all these strings like below?

    Code:
    char NewStr[];
    and about this:

    Code:
                    ori = strstr(NewStr, "origin"); //find the origin position
                    L1 = atoi(ori); // converted to number
                    /*!! no, that's just atoi("origin"), which makes no sense */
                    L1 += 8;        // than add +8 (origin" ") to that position, which will reach the numbers of the axis
                    /*!! If you want to read the numbers, then it would be ori += 8 */
                    /*!! that is, 8 characters past the start of the word "origin" */
    funny! I did like that, but people said to use atoi to get the number.

    and about the Num->String convertion, can I do like this?

    Code:
    NewStr = strcat( NewStr, va("%i", Num) );
    here an update of the code to test in the game:

    Code:
    static void CM_LoadEntityString (const byte *data, const lump_t *l){
    
        char   *game = Cvar_VariableString("fs_game");
    	int		i, j, Tam, TamNew;
    	int		PA, PB, PC, PD, PL, L1, Num, Espaco, Aspas;
    	char	*p = NULL, *ori = NULL, *HStr = NULL, *NewStr = NULL, *FinalStr = NULL;
        char	*PartA = NULL, *PartB = NULL, *PartC = NULL, *PartD = NULL;
    
    
    	cm_numEntityChars = l->fileLen;
    	if (cm_numEntityChars < 1)
    		return;
    	if (cm_numEntityChars > MAX_MAP_ENTSTRING)
    		Com_Error(ERR_DROP, "CM_LoadMap: map '%s' has too large entity lump", cm_map);
    
    	cm_entityString = Hunk_Alloc(cm_numEntityChars + 1);
    	memcpy(cm_entityString, data + l->fileOfs, cm_numEntityChars);
    
    	// do string manipulation over cm_entityString if game = arena
    	if (!Q_stricmp(game, "arena")){
    		*NewStr = 0;
    		*FinalStr = 0;
    		strcpy(HStr, cm_entityString); // copy the original string to mine
    		Tam = strlen(HStr);
    		i=0;
    		j=0;
    	   while (j<Tam){
    		   while (HStr[j] != '}'){ // copy to NewStr each Class
    			   NewStr[i] = HStr[j];
    			   i++;j++;
    		   }
    		   NewStr[i] = HStr[j]; //add '}' to the end of the class
    		   p = strstr(NewStr, "info_player"); //see if is a spawn class
    		   if (!p){
    			   FinalStr = strcat( FinalStr, NewStr ); //if not, save and go to the next class
    		   }else{
    			   //if yes, start the hard work
                   ori = strstr(NewStr, "origin"); //find the origin position
    			   ori +=8; // then add +8 (origin" ") to that position, which will reach the numbers of the axis
    			   // find PartA from 0 to L1 // until ori now
    			   for (PA=0;PA==ori;PA++) //seta parte 1/4
    			   {
    					PartA[PA]=NewStr[PA];
    			   }
    			   PL=PA; //creat a new var to control the place in NewStr
    			   Espaco=0; //set to have zero spaces count
    			   // find PartB from start of numbers until 2nd space
    			   for (PB=0;Espaco!=2;PB++) //set part 2/4
    			   {
    					PL++;
    					PartB[PB]=NewStr[PL];
    					if (PartB[PB]==" ")
    						Espaco++;
    			   }
    			   Aspas=0; //set to plics to zero count
    			   // find PartC which is the Number, until reach next "
    			   for (PC=0;Aspas==1;PC++) //set part 3/4 = Num
    			   {
    				   PL++;
    					if (NewStr[PL]=='"')
    						Aspas = 1;
    					else
    						PartC[PC]=NewStr[PL];
    			   }
    			   TamNew = strlen(NewStr); //find the size of NewStr
    			   // find PartD from " after number until the end of class
    			   for (PD=0;PL==TamNew;PD++) //set part 4/4
    			   {
    				   PartD[PD]=NewStr[PL];
    				   PL++;
    			   }
    			   Num=atoi(PartC); // Convert to Number
    			   Num += 15; //add 15
                   NewStr = strcat( PartA, PartB ); // make all 4 parts into one
    			   NewStr = strcat( NewStr, va("%i", Num) ); // Num to String
    			   NewStr = strcat( NewStr, PartD );
    			   FinalStr = strcat( FinalStr, NewStr ); // add all NewStr to FinalStr
    		   }
    		i=0; //NewStr count to zero
    		j++;
    		*NewStr = 0; //erase NewStr
    	   }
    	// strcpy(cm_entityString, FinalStr); //replace the original by the new altered one
        Com_Printf(S_COLOR_YELLOW "Original Entity List: %s\n", cm_entityString); //print original string on log
        Com_Printf(S_COLOR_RED "Altered Entity List: %s\n", FinalStr); //print altered string on log
    	}
    }
    thanks again!!

  4. #4
    Registered User
    Join Date
    Jun 2007
    Location
    Rio de Janeiro, Brasil
    Posts
    48

    Exclamation Done!!!!

    Ok, I done everything that I could to fix the siamese twins bug, and I FIXED!!!!

    but I'm having a little problem.... when I quit the server the game abort, or when I change the map for the 3rd time the game abort... I still don't know why... the string was altered with perfection, but seams that I miss something, maybe I need to use memcpy too? or free the arrays?? I think is something with overflow...

    well, here the final code:

    I commented the file recording and the ARENA test to see the spawnpoints higher even in DM, and works really perfect! no one problem about that... attached you can find the files recorded to you see that manipulation was perfect!

    Code:
    static void CM_LoadEntityString (const byte *data, const lump_t *l){
    
    	char	*game = Cvar_VariableString("fs_game"); // declare game - Hajas
    	//FILE	*f;
    	char	*p, *loc, *origem;
    	char	*ptr = malloc(151);
    	int		i, j, k, Tam, TamNew, ori;
    	int		PA, PB, PC, PD, PL, Num, Space, Aspas;
    	char	HStr[MAX_MAP_ENTSTRING], FinalStr[MAX_MAP_ENTSTRING];
    	char	NewStr[150], PartA[150], PartB[150], PartC[20], PartD[150];
    
    	cm_numEntityChars = l->fileLen;
    	if (cm_numEntityChars < 1)
    		return;
    	if (cm_numEntityChars > MAX_MAP_ENTSTRING)
    		Com_Error(ERR_DROP, "CM_LoadMap: map '%s' has too large entity lump", cm_map);
    
    	cm_entityString = Hunk_Alloc(MAX_MAP_ENTSTRING);
    	memcpy(cm_entityString, data + l->fileOfs, cm_numEntityChars);
    
    	//f = fopen ("entityORI.cfg", "wb");
    	//fprintf(f, "%s\n", cm_entityString);
    	//fclose(f);
    
    	//if (!Q_stricmp(game, "arena")){
    		// do string manipulation over cm_entityString
    		strcpy(HStr, cm_entityString); // copy the original string to mine
            Tam = strlen(HStr);
            j=0;
           while (j < Tam){
    		   i=0;
               while ((HStr[j] != '}') && (j < Tam)){ // copy to NewStr each Class
                   NewStr[i] = HStr[j];
                   i++;j++;
               }
    		   if (HStr[j] == '}'){
    			NewStr[i] = HStr[j]; //add '}' close the class
    			NewStr[i+1] = '\0'; //add '\0' to the end of the class
    		   }
    		   TamNew = strlen(NewStr); //find the size of NewStr
    		   p = strstr(NewStr, "info_player");
               if (!p){ //test if is a spawn class
    			   strcat( FinalStr, NewStr ); //if not, save and go to the next class
               }else{
    			   i=0; //NewStr count to zero
                   //if yes, start the hard work
    			   strcpy(ptr,NewStr);
    			   origem = strstr(ptr, "origin"); //find the origin position
    			   loc = origem-ptr;
    			   free(ptr);
                   ori = loc + 8; // then add +8 (origin" ") to that position, which will reach the numbers of the axis
    			   free(loc);
    			   free(origem);
                   // find PartA from 0 to L1 // until ori now
                   for (PA=0;PA!=ori;PA++) //seta parte 1/4
                   {
                        PartA[PA]=NewStr[PA];
    			   }
    			   PartA[PA]='\0'; //close string
                   PL=PA; //create a new var to control the place in NewStr
                   Space=0; //set to have zero spaces count
    			   PB=0; //zera PB
    			   // find PartB from start of numbers until 2nd space
    			   while (Space!=2)
                   {
                        PartB[PB]=NewStr[PL];
    					if (PartB[PB]==' '){
    						Space++;
    					}
    					if(Space!=2){
    						PB++;PL++;
    					}
                   }
    			   PartB[PB+1]='\0'; //close string
                   Aspas=0; //set to plics to zero count
                   // find PartC which is the Number, until reach next "
                   for (PC=0;Aspas==0;PC++) //set part 3/4 = Num
                   {
                       PL++;
    				   if (NewStr[PL]=='"')
                            Aspas = 1;
    				   else
                            PartC[PC]=NewStr[PL];
                   }
    			   PartC[PC]='\0';
                   // find PartD from " after number until the end of class
                   for (PD=0;PL <= TamNew;PD++) //set part 4/4
                   {
                       PartD[PD]=NewStr[PL];
                       PL++;
                   }
                   Num=atoi(PartC); // Convert to Number
                   Num += 15; //add 15
                   strcat( FinalStr, PartA ); // make all 4 parts into one
    			   strcat( FinalStr, PartB);
    			   sprintf(PartC,"%d",Num); // Num to String
    			   strcat( FinalStr, PartC); 
    	           strcat( FinalStr, PartD );
               }
    		   for (k=0;k<=i;k++){ //clean NewStr
    				NewStr[k]='\0';
    		   }
    		   j++;
    	   }
    	  strcpy(cm_entityString, FinalStr);
    		/*f = fopen ("FinalStr.cfg", "wb");
    		fprintf(f, "%s\n", cm_entityString);
    		fclose(f);*/
    		free(p);
    	//}
    }
    with or without this line, we have the SAME behavior... abort when the third map is loaded.

    Code:
    strcpy(cm_entityString, FinalStr);
    so isn't when the cm_entityString is altered...

    anything that I must free that I didn't? any clues?

    thanks a lot to everyone that help me until now!

  5. #5
    Registered User
    Join Date
    Jun 2007
    Location
    Rio de Janeiro, Brasil
    Posts
    48
    I found the line that is killing the game:

    Code:
    free(ptr);
    if I remove this then no more abort... it's done!

    now, wth this make the game freeze? when I free per exemple p without problems?

    I rename all vars to hajas_var to make sure they are unique, and still the same...

    any clues?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In a game Engine...
    By Shamino in forum Game Programming
    Replies: 28
    Last Post: 02-19-2006, 11:30 AM
  2. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-26-2006, 12:14 AM
  3. Ultra chess engine contest
    By yodacpp in forum Projects and Job Recruitment
    Replies: 8
    Last Post: 11-21-2004, 07:58 AM
  4. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  5. What's a 3D engine?
    By Garfield in forum Game Programming
    Replies: 6
    Last Post: 12-18-2001, 04:06 PM