After two weeks of further debugging I've now came up with a work around so that it does not crash.
These are the modifications that I needed to make to avoid null pointer crashes:
SocketSys.hx (haxe/net/impl/SocketSys.hx)
// M.E. the match error.custom(error.blocked) caused null pointer crash
/*
needClose = !(e == 'Blocking' || (Std.is(e, Error) && (
(e:Error).match(Error.Custom(Error.Blocked)) ||
(e:Error).match(Error.Blocked))
));
*/
if((""+e).indexOf("Block") < 0 && (""+e).indexOf("Custom(EOF)") < 0){
trace('closing socket because of $e');
needClose=true;
}
}
And further down I don't close the socket which caused blocking and crashing things on Android
if (needClose) {
// close(); // M.E. This will cause Android problems
}
Room.hx : avoid null pointer exception
private function patch( binaryPatch: Bytes ) {
// apply patch
// M.E. Check for null on binaryPatch
if(binaryPatch == null || this == null || this._previousState == null){
trace("BINARY PATCH IS NULL or this._previousState == null !");
}else{
this._previousState = FossilDelta.Apply(this._previousState, binaryPatch);
// trigger state callbacks
this.set( MsgPack.decode( this._previousState ) );
this.onStateChange(this.state);
}
}
FossilDelta.hx in Apply to avoid null pointer exception
var total=0;
// M.E. Check for null on src
if(src == null)return haxe.io.Bytes.alloc(0);
if(delta == null) return haxe.io.Bytes.alloc(0);
// M.E. End of modification
And I needed to inform Stencyl about errors in Room.onError or the extension would still use room functions ...
Room.hx connect function
this.connection.onError = function (e) {
var message="Possible causes: room's onAuth() failed or maxClients has been reached.";
if(getGameAttribute("ColyseusErrorMessage") == null)setGameAttribute("ColyseusErrorMessage", ""); setGameAttribute("ColyseusErrorMessage", ""+getGameAttribute("ColyseusErrorMessage")+" "+message);
trace(message);
this.onError(e);
};
In the application I created an onError routine and that would be hit sometimes but then it will do a new client instance and it starts creating rooms again.
So we don't close the socket on haxe.net level but detect problems in Room and Client on Colyseus level.
Hopefully these changes don't bite me later. I really want to continue working on other methods than Lobby mechanism!
Mac OSX, iOS Simulator, iPhone 5, Windows and Android all work without crashes when creating and leaving rooms now.
I ran a demo-game that left and created rooms every 10 seconds and they kept working for an hour.
Android crashed on one device after an hour. It had done over 100 room creations by that time.
I need to keep that in mind when doing more stuff later on and see if it reoccurs.
(HTML5 never gave problems as it didn't use haxe.net)