Fix potential crash in pc_setpos (#5782)

This commit is contained in:
Vincent Stumpf 2021-04-01 16:01:36 -07:00 committed by GitHub
parent 8218337890
commit 6d89b53fb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6059,7 +6059,7 @@ enum e_setpos pc_setpos(struct map_session_data* sd, unsigned short mapindex, in
instance_addusers(new_map_instance_id);
}
if (sd->bg_id && !mapdata->flag[MF_BATTLEGROUND]) // Moving to a map that isn't a Battlegrounds
if (sd->bg_id && mapdata && !mapdata->flag[MF_BATTLEGROUND]) // Moving to a map that isn't a Battlegrounds
bg_team_leave(sd, false, true);
sd->state.pmap = sd->bl.m;
@ -6096,7 +6096,7 @@ enum e_setpos pc_setpos(struct map_session_data* sd, unsigned short mapindex, in
if (sd->regen.state.gc)
sd->regen.state.gc = 0;
// make sure vending is allowed here
if (sd->state.vending && mapdata->flag[MF_NOVENDING]) {
if (sd->state.vending && mapdata && mapdata->flag[MF_NOVENDING]) {
clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
vending_closevending(sd);
}
@ -6131,6 +6131,12 @@ enum e_setpos pc_setpos(struct map_session_data* sd, unsigned short mapindex, in
st = nullptr;
}
if (sd->bg_id) // Switching map servers, remove from bg
bg_team_leave(sd, false, true);
if (sd->state.vending) // Stop vending
vending_closevending(sd);
npc_script_event(sd, NPCE_LOGOUT);
//remove from map, THEN change x/y coordinates
unit_remove_map_pc(sd,clrtype);