[TUTORIAL] How to find BUG that CRASHES your server?
#1

1st you need a part of script that gives you crashes...

Some can be found even at start.. OnGamemodeInit etc.
Others can be OnplayerConnect, or even when player uses simple command.

How to find that crasher bug?

It's simple.
1. Open .pwn of script
2. Find part of script that crashes
3. In part, put
Code:
print("<something to recognise, maybe numbers>");
after every line in this part
4. Run the server with edited script, and let it crash.
5. After crash open server_log.txt file
6. Go all way down and find what was the last thing what was logged
7. If you putted numbers and last number is '3' then command or function after
Code:
print("3");
is the thing that crashes
8. Fix the problem if you can
9. Remove
Code:
print("<something to recognise, maybe numbers>");
from script
10. Enjoy playing your server!


EXAMPLES:
Code:
dcmd_l(playerid,params[]) {
  if(LoggedIn[playerid] == 1) {
	  	new tmp[256], tmp2[256], Index;		tmp = strtok(params,Index), tmp2 = strtok(params,Index);
	  if(!strlen(params)) return SendClientMessage(playerid, red, "   Correct use: /l [text] - LOCAL");
		new str[128];
		new string[256];
		GetPlayerName(playerid, str, sizeof(str));
		format(string,sizeof(string),">  CHAT > LOCAL > %s > %s !",str,params);
		format(str, sizeof(str), "%s says '%s'", str, params);
		print(string);
		ApplyAnimation(playerid,"MISC","Idle_Chat_02",4.1,0,1,1,1,1);
    for(new i; i<MAX_PLAYERS; i++)
			{
				new Float:x,Float:y, Float:z;
 				GetPlayerPos(playerid,x,y,z);
				if (PlayerToPoint(7,i,x,y,z))
				{
 					return SendClientMessage(i,COLOR_WHITE, str);
  			}
				if (PlayerToPoint(15,i,x,y,z))
				{
 					return SendClientMessage(i,COLOR_GRAYDARK, str);
  			}
			}
  		return 1;
  }
  else return SendClientMessage(playerid,red,"   You must be logged in to use this command");
}
This makes us bug (not really)
so lets find it, put prints inside!
Code:
dcmd_l(playerid,params[]) {
	print("1");
  if(LoggedIn[playerid] == 1) {
	  	new tmp[256], tmp2[256], Index;		tmp = strtok(params,Index), tmp2 = strtok(params,Index);
		print("2");
	  if(!strlen(params)) return SendClientMessage(playerid, red, "   Correct use: /l [text] - LOCAL");
		print("3");
		new str[128];
		new string[256];
		GetPlayerName(playerid, str, sizeof(str));
		print("4");
		format(string,sizeof(string),">  CHAT > LOCAL > %s > %s !",str,params);
		print("5");
		format(str, sizeof(str), "%s says '%s'", str, params);
		print("6");
		print(string);
		print("7");
		ApplyAnimation(playerid,"MISC","Idle_Chat_02",4.1,0,1,1,1,1);
    for(new i; i<MAX_PLAYERS; i++)
		print("8");
			{
				new Float:x,Float:y, Float:z;
 				GetPlayerPos(playerid,x,y,z);
				print("9");
				if (PlayerToPoint(7,i,x,y,z))
				{
					print("10");
 					return SendClientMessage(i,COLOR_WHITE, str);
  			}
				if (PlayerToPoint(15,i,x,y,z))
				{
					print("11");
 					return SendClientMessage(i,COLOR_GRAYDARK, str);
  			}
			}
  		return 1;
  }
	print("12");
  else return SendClientMessage(playerid,red,"   You must be logged in to use this command");
}
Hope it's Useful!

P.S. Alligments in code are not as they should be!

(( Topic posted by [GMX]Spirit, not me! ))

Reply
#2

Hmm good idea, but when I add something into the script I always check if it works in game. If it doesn't, I just simply remove/edit the last bit of code I've added, but nice idea though.
Reply
#3

Of course, but you can't check InGame if your server crashes.

If commands don't work as it should then you use SendClientMessage except of 'print'
Reply
#4

?bump-a-zoola*
Reply
#5

Quote:
Originally Posted by Gimax
[TUTORIAL] How to find BUG that CRASHES your server?

[...]

1. Open .pwn of script
2. Find part of script that crashes
3. In part, put
Code:
print("<something to recognise, maybe numbers>");
after every line in this part
[...]
This topic is about finding bug in your script, but you say "Find part of script that crashes" in the second step.. How can you find it if you don't know where it is?
Reply
#6

You usually know whether it crashes whenever someone connects, or whenever you try to login or whenever you try to start the gamemode etc.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)