Colyseus : Leaving room
Since a couple of weeks I'm debugging the leaving room situation. It is kind of driving m.e. nuts.
Today I started over since I was not sure if my player information was ruining stuff or the leaving room situation.
All seems well with HTML5. But the CPP builds (Windows and Android) are giving me problems.
Most of the time the Windows build performs well, unless I try to do a Windows debug build. Then it crashes immediately.
Running the Android version gives me almost immediately problems. (I estimate that it is doing leave room twice so the new room is left immediately)
trace("input.readBytes catch : "+e);
if(Std.is(e,Error)) trace("isError"); // still OK
/* Output:
input.readBytes catch : Custom(EOF)
isError
*/
// Below line crashes: debug build
//if( (e:Error).match(Error.Custom(Error.Blocked)) ) trace("ErrorCustom"); // Null Pointer Exception
// And since it is used in the needClose detection it fails
needClose = !(e == 'Blocking' || (Std.is(e, Error) && (
(e:Error).match(Error.Custom(Error.Blocked)) ||
(e:Error).match(Error.Blocked))
));
So I cannot debug using Visual Studio...
But I don't care if Windows Debugger works as long as the issue can be resolved without it ...
This is the code that works:
public static function joinRoom(ID:String){
if(isInit){
var theOptions:Map<String, Dynamic>=new Map();
theOptions.set("Type", "JOIN");
theOptions.set("PlayerName", "TESTPLAYER" );
//if(room!=null) room.leave();
room = client.join(""+ID, theOptions);
}
}// joinRoom
public static function createRoom(RoomType:String){
if(isInit){
var theOptions:Map<String, Dynamic>=new Map();
theOptions.set("Type", "NEW");
theOptions.set("PlayerName", "TESTPLAYER" );
//if(room!=null) room.leave();
room = client.join(RoomType, theOptions);
}
}
But when I comment out the room.leave so that it actually leaves to current room and then Android gives me problems and
sometimes Windows crashes or gives the same problem (0 clients in room and then the room will be autodisposed)
Any suggestions are appreciated!
By the way : if I don't use room.leave and use the colyseus monitor to dispose them it works fine(!)
Also, I tried using a timer behind the room.leave to allow the engine to dispose the room but it looks like leave is called when I initiated another room.
I also tried using an Array of rooms where I leave the room[roomCounter] but this acts like it is also leaving the initiated room