Fix crash when failing to connect to server

This commit is contained in:
UnknownShadow200 2018-04-28 08:44:25 +10:00
parent 8d76c0c1b1
commit 7db39d73ee
2 changed files with 11 additions and 9 deletions

View File

@ -59,7 +59,7 @@ namespace ClassicalSharp.Network {
cpe = new CPEProtocol(game); cpe = new CPEProtocol(game);
cpeBlockDefs = new CPEProtocolBlockDefs(game); cpeBlockDefs = new CPEProtocolBlockDefs(game);
wom = new WoMProtocol(game); wom = new WoMProtocol(game);
ResetProtocols(); ResetState();
classic.WriteLogin(game.Username, game.Mppass); classic.WriteLogin(game.Username, game.Mppass);
SendPacket(); SendPacket();
@ -190,21 +190,22 @@ namespace ClassicalSharp.Network {
packetSizes[i] = 0; packetSizes[i] = 0;
} }
reader.ExtendedPositions = false; reader.ExtendedBlocks = false; BlockInfo.SetMaxUsed(255);
writer.ExtendedPositions = false; writer.ExtendedBlocks = false; ResetState();
BlockInfo.SetMaxUsed(255);
ResetProtocols();
cpeData.Reset();
Dispose(); Dispose();
} }
void ResetProtocols() { void ResetState() {
if (classic == null) return; // null if no successful connection ever made before if (classic == null) return; // null if no successful connection ever made before
cpeData.Reset();
classic.Reset(); classic.Reset();
cpe.Reset(); cpe.Reset();
cpeBlockDefs.Reset(); cpeBlockDefs.Reset();
wom.Reset(); wom.Reset();
reader.ExtendedPositions = false; reader.ExtendedBlocks = false;
writer.ExtendedPositions = false; writer.ExtendedBlocks = false;
} }
internal Action[] handlers = new Action[256]; internal Action[] handlers = new Action[256];
@ -225,6 +226,7 @@ namespace ClassicalSharp.Network {
public override void OnNewMap(Game game) { public override void OnNewMap(Game game) {
// wipe all existing entity states // wipe all existing entity states
if (classic == null) return;
for (int i = 0; i < EntityList.MaxCount; i++) { for (int i = 0; i < EntityList.MaxCount; i++) {
classic.RemoveEntity((byte)i); classic.RemoveEntity((byte)i);
} }

View File

@ -21,7 +21,7 @@ String_AppendConst(&logMsg, "\r\n");
String_AppendConst(&logMsg, "Please report the crash to github.com/UnknownShadow200/ClassicalSharp/issues so we can fix it."); String_AppendConst(&logMsg, "Please report the crash to github.com/UnknownShadow200/ClassicalSharp/issues so we can fix it.");
LONG WINAPI ErrorHandler_UnhandledFilter(struct _EXCEPTION_POINTERS* pInfo) { LONG WINAPI ErrorHandler_UnhandledFilter(struct _EXCEPTION_POINTERS* pInfo) {
//pInfo->ExceptionRecord-> pInfo->ExceptionRecord->
return EXCEPTION_EXECUTE_HANDLER; return EXCEPTION_EXECUTE_HANDLER;
} }