Threaded timers???
#1

Hi,

I just found a bug in my current gamemode: Timers crashes the server if I try to reload a lot of data (MySQL, XML, ...)

A test resulted in: Timers are threaded?


I have a timer (250ms interval)

I send a RCON command which reloads all pickups on the server from a MySQL database.


In timer: printing "Loop"

In RCON command: printing one line for each loaded pickup


Output in the server log file:
Код:
[2012-04-23 21:26:34] Pickup: 1
[2012-04-23 21:26:34] Loop
[2012-04-23 21:26:34] Pickup: 2
[2012-04-23 21:26:34] Loop
[2012-04-23 21:26:34] Pickup: 3
[2012-04-23 21:26:34] Loop
[2012-04-23 21:26:34] Pickup: 4
[2012-04-23 21:26:34] Loop
[2012-04-23 21:26:34] Pickup: 5
[2012-04-23 21:26:34] Loop
WTF

I think it should look like that:
Код:
[2012-04-23 21:26:34] Loop
[2012-04-23 21:26:34] Loop
[2012-04-23 21:26:34] Loop
[2012-04-23 21:26:34] Loop
[2012-04-23 21:26:34] Pickup: 1
[2012-04-23 21:26:34] Pickup: 2
[2012-04-23 21:26:34] Pickup: 3
[2012-04-23 21:26:34] Pickup: 4
[2012-04-23 21:26:34] Pickup: 5
Reply
#2

Perhaps you could show us your code, it'd really help to find the problem (and understand what you mean)
Reply
#3

hmmm... crazy... I can't reproduce the problem in a simple test script.

Maybe the plugins I use work in threads and cause the server to crash if I call a function at the wrong time?

I'm using the following plugins: Are some of them known as buggy in this way?

SA-MP Server version: 0.3e RC7 (I also had this problem in RC6)


//EDIT: I found the problem.

I have an filterscript to process RCON commands in the gamemode. In my filterscript (rcon proxy) I just call rcmd_<command> with CallRemoteFunction().


RCON Proxy Filterscript:
Код:
#include <a_samp>

public OnFilterScriptInit()
{
	print("RCON Proxy Filterscript loaded");
	return true;
}

public OnFilterScriptExit()
{
	print("RCON Proxy Filterscript unloaded");
	return true;
}

public OnRconCommand(cmd[])
{
	new pos;
	new functionName[32];
	while (cmd[pos] > ' ')
	{
		functionName[pos] = tolower(cmd[pos]);
		pos++;
	}
	format(functionName, sizeof(functionName), "rcmd_%s", functionName);
	while (cmd[pos] == ' ')
	{
		pos++;
	}
	if (!cmd[pos])
	{
		return CallRemoteFunction(functionName, "s", "\1");
	}
	return CallRemoteFunction(functionName, "s", cmd[pos]);
}
Test gamemode:
Код:
#include <a_samp>

public OnGameModeInit()
{
	SetTimer("Timer", 250, true);
}

SlowFunction()
{
	print("SlowFunction:Start");
	// Simulate slow function
	new oldTime = gettime();
	new difference;
	while (difference < 5)
	{
		difference = gettime() - oldTime;
	}
	print("SlowFunction:End");
}

forward rcmd_testcmd(command[]);
public rcmd_testcmd(command[])
{
	SlowFunction();
	return true;
}

forward Timer();
public Timer()
{
	print("Timer");
}

main(){}
Just type "testcmd" in the server console or send it via RCON.


The result will look like that:
Код:
[00:44:22] Timer
[00:44:23] Timer
[00:44:23] Timer
[00:44:23] Timer
Console input: testcmd
[00:44:23] SlowFunction:Start
[00:44:23] Timer
[00:44:24] Timer
[00:44:24] Timer
[00:44:24] Timer
[00:44:25] Timer
[00:44:25] Timer
[00:44:25] Timer
[00:44:25] Timer
[00:44:26] Timer
[00:44:26] Timer
[00:44:26] Timer
[00:44:27] Timer
[00:44:27] Timer
[00:44:27] Timer
[00:44:27] Timer
[00:44:28] SlowFunction:End
[00:44:28] Timer
[00:44:28] Timer
[00:44:28] Timer
[00:44:28] Timer
[00:44:29] Timer
[00:44:29] Timer
But I want that:
Код:
[00:44:22] Timer
[00:44:23] Timer
[00:44:23] Timer
[00:44:23] Timer
Console input: testcmd
[00:44:23] SlowFunction:Start
[00:44:28] SlowFunction:End
[00:44:28] Timer
[00:44:28] Timer
[00:44:28] Timer
[00:44:28] Timer
[00:44:29] Timer
[00:44:29] Timer
//EDIT2: I moved the SlowFunction() code directly to OnRconCommand() in the filterscript. Same problem...

Filterscripts don't run in the main loop? But I thought SA-MP is using a single thread?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)