Forum Multiplayer "ScheduleCallback" must be mad

Discussion and help relating to the PlayerIO Multiplayer API.

"ScheduleCallback" must be mad

Postby guixizheng » March 16th, 2017, 3:30 pm

Hi,
Yesterday everything is ok.But Today,the server is mad and sending players message without interval.It seems that the "ScheduleCallback"
become crazy.By the way,it is still ok on the local server.
Below is the code.

private DateTime lastFrameTime;
[RoomType("PCSGame")]
public class GameCode : Game<Player>
{
.......
public int FrameDuring = 40;
private DateTime lastFrameTime;
.......
private void gameFrame()
{
Message f = Message.Create("f");//frame input
......
Broadcast(f);
DateTime currentFrameTime = DateTime.Now;
TimeSpan executionTime = currentFrameTime - lastFrameTime;
lastFrameTime = currentFrameTime;
int restTimeMS = 2*FrameDuring-(int)executionTime.TotalMilliseconds;
//Run again
int dueTime=Math.Min(restTimeMS - msgTimeMS, FrameDuring - msgTimeMS);
if (dueTime <= 25)
{
gameFrame();
}
else
{
ScheduleCallback(gameFrame, dueTime);
}

}
guixizheng
 
Posts: 5
Joined: July 1st, 2016, 4:49 am

Re: "ScheduleCallback" must be mad

Postby guixizheng » March 17th, 2017, 12:14 am

Today everything is ok again.I guess it may be issue of network.So let it be...
guixizheng
 
Posts: 5
Joined: July 1st, 2016, 4:49 am

Re: "ScheduleCallback" must be mad

Postby guixizheng » March 18th, 2017, 7:44 am

Hi,
I think I shall add volatile before lastFrameTime to avoid thread issue.
guixizheng
 
Posts: 5
Joined: July 1st, 2016, 4:49 am

Re: "ScheduleCallback" must be mad

Postby Henrik » March 19th, 2017, 8:07 am

My only suggestion, if it happens again, would be to add more logging for a single user to see what values you actually calculate for the callback time.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm


Return to Multiplayer