Different results when parsing files with sscanf on Windows and Linux
#1

Hello. I develop a gamemode I'm working on on my own computer, a windows machine.
However, I host the actual gamemode on my linux server. I took a lot of inspiration from the gl_property filterscript and made my own property system. However, the results seems to differ when I host on linux and on windows, just look:

Parsed on Windows:
Код:
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.53 1108.31 10.81 101.11 2261.09 -1137.88 1050.63 266.88]
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.42 1118.33 10.81 93.27 2261.09 -1137.88 1050.63 266.88]
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.43 1098.18 10.81 88.26 2261.09 -1137.88 1050.63 266.88]
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.52 1088.30 10.81 103.93 2261.09 -1137.88 1050.63 266.88]
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.47 1078.18 10.81 93.91 2261.09 -1137.88 1050.63 266.88]
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.42 1068.13 10.81 95.16 2261.09 -1137.88 1050.63 266.88]
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.59 1058.18 10.81 96.73 2261.09 -1137.88 1050.63 266.88]
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.48 1048.13 10.81 91.40 2261.09 -1137.88 1050.63 266.88]
[17, 1272, 32, 24/7, 2, 1, , 0, 0, 2247.92 2396.56 10.81 9.22 -25.72 -187.82 1003.54 5.07]
[10, 1272, 32, 24/7, 2, 1, , 0, 0, 2193.68 1991.04 12.28 92.43 6.08 -28.89 1003.54 5.03]
[3, 1239, 61, Planning Department, 3, 0, , 0, 0, 2413.53 1124.18 10.81 279.17 386.52 173.63 1008.38 63.73]
[10, 1274, 52, Bank, 3, 0, , 0, 0, 2577.79 1323.39 10.81 6.65 246.06 108.97 1003.21 0.29]
[3, 1247, 30, Police Department, 3, 0, , 0, 0, 2289.82 2430.84 10.81 177.94 288.47 170.06 1007.17 22.04]
Parsed on Linux:
Код:
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 0.00 1857.53 1108.31 10.81 101.11 2261.09 -1137.88 1050.63]
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 0.00 1857.42 1118.33 10.81 93.27 2261.09 -1137.88 1050.63]
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 266.88 1857.43 1098.18 10.81 88.26 2261.09 -1137.88 1050.63]
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 266.88 1857.52 1088.30 10.81 103.93 2261.09 -1137.88 1050.63]
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 266.88 1857.47 1078.18 10.81 93.91 2261.09 -1137.88 1050.63]
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 266.88 1857.42 1068.13 10.81 95.16 2261.09 -1137.88 1050.63]
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 266.88 1857.59 1058.18 10.81 96.73 2261.09 -1137.88 1050.63]
[10, 1273, 31, Apartment, 1, 1, , 0, 0, 266.88 1857.48 1048.13 10.81 91.40 2261.09 -1137.88 1050.63]
[17, 1272, 32, 24/7, 2, 1, , 0, 0, -1.59 2247.92 2396.56 10.81 9.22 -25.72 -187.82 1003.54]
[10, 1272, 32, 24/7, 2, 1, , 0, 0, 5.07 2193.68 1991.04 12.28 92.43 6.08 -28.89 1003.54]
[3, 1239, 61, Planning Department, 3, 0, , 0, 0, 2.31 2413.53 1124.18 10.81 279.17 386.52 173.63 1008.38]
[10, 1274, 52, Bank, 3, 0, , 0, 0, -1.59 2577.79 1323.39 10.81 6.65 246.06 108.97 1003.21]
[3, 1247, 30, Police Department, 3, 0, , 0, 0, 1.64 2289.82 2430.84 10.81 177.94 288.47 170.06 1007.17]
Original data:
Код:
10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.530029, 1108.319946, 10.819993, 101.110000, 2261.097656, -1137.883300, 1050.632812, 266.880004
10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.420043, 1118.339965, 10.819993, 93.279998, 2261.097656, -1137.883300, 1050.632812, 266.880004
10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.430053, 1098.189941, 10.810000, 88.269996, 2261.097656, -1137.883300, 1050.632812, 266.880004
10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.520019, 1088.300048, 10.810000, 103.930000, 2261.097656, -1137.883300, 1050.632812, 266.880004
10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.479980, 1078.189941, 10.819993, 93.910003, 2261.097656, -1137.883300, 1050.632812, 266.880004
10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.420043, 1068.130004, 10.810000, 95.160003, 2261.097656, -1137.883300, 1050.632812, 266.880004
10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.599975, 1058.189941, 10.819993, 96.730003, 2261.097656, -1137.883300, 1050.632812, 266.880004
10, 1273, 31, Apartment, 1, 1, , 0, 0, 1857.489990, 1048.130004, 10.819993, 91.400001, 2261.097656, -1137.883300, 1050.632812, 266.880004
17, 1272, 32, 24/7, 2, 1, , 0, 0, 2247.929931, 2396.560058, 10.819993, 9.229990, -25.722000, -187.821594, 1003.546875, 5.076000
10, 1272, 32, 24/7, 2, 1, , 0, 0, 2193.689941, 1991.040039, 12.289999, 92.430000, 6.085597, -28.896600, 1003.549377, 5.036499
3, 1239, 61, Planning Department, 3, 0, , 0, 0, 2413.530029, 1124.189941, 10.819993, 279.179992, 386.525909, 173.638107, 1008.382812, 63.739898
10, 1274, 52, Bank, 3, 0, , 0, 0, 2577.790039, 1323.390014, 10.819993, 6.650000, 246.068801, 108.970298, 1003.218811, 0.292198
3, 1247, 30, Police Department, 3, 0, , 0, 0, 2289.820068, 2430.840087, 10.819993, 177.949996, 288.472290, 170.064697, 1007.179382, 22.047700
Notice the line 1 on both debug dumps. It seems to set the coordinate to the wrong variable. If you look a few lines down, you'll see that the first coordinate is supposed to be the last:
On linux:
266.88 1857.43 1098.18 10.81 88.26 2261.09 -1137.88 1050.63
1857.43 1098.18 10.81 88.26 2261.09 -1137.88 1050.63 266.88
How it should be:


Lets dig deeper into the code!

Here's the eProperties enum and the Properties array:
Код:
enum eProperties
{
	eInterior,
	ePickup,
	eIcon,
	eName[64],
	eType,
	eVWorld,
	eOwner[MAX_PLAYER_NAME],
	ePrice,
	eRent,
	Float:eEntX,
	Float:eEntY,
	Float:eEntZ,
	Float:eEntA,
	Float:eExitX,
	Float:eExitY,
	Float:eExitZ,
	Float:eExitA,
};
new Properties[MAX_PROPERTIES][eProperties];
Here's the class where I read from the file (also where the debugging above is taken from):
Код:
stock ReadProperties(filename[], &idx)
{
	new File:pFile = fopen(filename);
	if (pFile)
	{
	  new buffer[512], props = 0;
	  while (fread(pFile, buffer, sizeof(buffer)) > 0)
	  {
	    if (sscanf(buffer, "p<,>e<iiis[64]iis[24]iiffffffff>", Properties[idx])) { printf("Property #%d has an invalid format", idx); }
	    else
			{
				printf("Cached property #%d: %s", idx, Properties[idx][eName]);
				printf("[%d, %d, %d, %s, %d, %d, %s, %d, %d, %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f]",
				Properties[idx][eInterior], Properties[idx][ePickup], Properties[idx][eIcon], Properties[idx][eName], Properties[idx][eType], Properties[idx][eVWorld], Properties[idx][eOwner], Properties[idx][ePrice], Properties[idx][eRent],
				Properties[idx][eEntX], Properties[idx][eEntY], Properties[idx][eEntZ], Properties[idx][eEntA], Properties[idx][eExitX], Properties[idx][eExitY], Properties[idx][eExitZ], Properties[idx][eExitA]);
				props++;
			}
	    idx++;
	  }
	  printf("Read %d properties from %s", props, filename);
	}
	else { print("Could not open properties file"); }
	fclose(pFile);
}
Here's where the ReadProperties function is called:
Код:
stock LoadProperties()
{
	for (new i = 0; i < MAX_PROPERTIES; i++)
	{
		Properties[i][eType] = TYPE_EMPTY;
	}
	
	new idx = 0;
	for (new i = 1; i < MAX_TYPES; i++)
	{
	  ReadProperties(PropertyFiles[i], idx);
	}
	
	for (new i = 0; i < MAX_PROPERTIES; i++)
	{
    if (Properties[i][eType] != TYPE_EMPTY)
    {
		  new id = CreatePickup(Properties[i][ePickup], 23, Properties[i][eEntX], Properties[i][eEntY], Properties[i][eEntZ], 0);
		  PropertyPickups[id] = i;

		  PropertyInfo[i] = Text3D:INVALID_3DTEXT_ID;
		  switch (Properties[i][eType]) // LabelText
		  {
		    case TYPE_PROPERTY:
					PropertyInfo[i] = Create3DTextLabel("[Property]", 0x88EE88FF, Properties[i][eEntX], Properties[i][eEntY], Properties[i][eEntZ] + 0.75, 20.0, 0, 1);
					
		    case TYPE_BUSINESS:
					PropertyInfo[i] = Create3DTextLabel("[Business]", 0xAAAAFFFF, Properties[i][eEntX], Properties[i][eEntY], Properties[i][eEntZ] + 0.75, 20.0, 0, 1);
					
		    case TYPE_GOVERMENT:
		    {
		      new name[64];
		      format(name, sizeof(name), "[%s]", Properties[i][eName]);
					PropertyInfo[i] = Create3DTextLabel(name, 0xEEEE88FF, Properties[i][eEntX], Properties[i][eEntY], Properties[i][eEntZ] + 0.75, 20.0, 0, 1);
				}
		  }

			switch (Properties[i][eType]) // MapIcon
			{
			  case TYPE_PROPERTY:
					Properties[i][eIcon] = 31;
			  case TYPE_BUSINESS:
					Properties[i][eIcon] = 32;
		  }
	  }
	}
}
Reply
#2

I would really appreciate some help here
Reply
#3

I assume you're using the sscanf plugin, judging by the format specifiers.
Try asking in the sscanf topic for help
http://forum.sa-mp.com/index.php?topic=145539.0


Or try with the old sscanf
https://sampwiki.blast.hk/wiki/Sscanf_code
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)