Fix MAIL_LOAD_AUTO_MISSION crash: defer initialize(this) to sender==this self-mail

'gui_objects have no parent' crash at line 907: initialize(this) cannot be
called from sender==@conlobby@ context (external mail). Fix:

1. Replace initialize(this)+mail(-9998,parent) in MAIL_LOAD_AUTO_MISSION
   with mail(MAIL_LOAD_AUTO_MISSION_DONE=-8888, this) -- a self-mail.

2. Add MAIL_LOAD_AUTO_MISSION_DONE handler in sender==this block, which
   safely calls initialize(this)+mail(-9998,parent) from the correct context.

Also repaired a corrupt duplicate MAIL_PREVIOUS_MISSION_PARAMS block
that was left orphaned by an earlier edit (the original body of
MAIL_LOAD_AUTO_MISSION had been inserted there when the handler was
moved from sender==this to sender==@conlobby@).

No rebuild required (script-only).
This commit is contained in:
2026-07-24 11:09:50 -05:00
parent 06de4534da
commit e5561181bb
@@ -53,6 +53,7 @@
#define MAIL_RECORD_MISSION -4444
#define MAIL_PREVIOUS_MISSION_PARAMS -5555
#define MAIL_LOAD_AUTO_MISSION -6666 // [automaticmode] sync with ConLobby.script
#define MAIL_LOAD_AUTO_MISSION_DONE -8888 // [automaticmode] internal finalize (self-mail)
#define ROOKIE_MISSION "ScarabStronghold - Attrition"
@@ -902,9 +903,9 @@ main
nTempValue = $$g_nAutoArmorMode$$
o_game_options[16].state = 0
callback($$SetNetworkMissionParamater$$, nTempParam, nTempValue)
initialize(this)
// notify ConLobby: game type/params changed (updates cur_game_type, cur_team_val display)
mail(-9998, parent)
// Finalize via self-mail: initialize(this) and mail(-9998,parent) must run
// in a sender==this context to avoid the 'gui_objects have no parent' crash.
mail(MAIL_LOAD_AUTO_MISSION_DONE, this)
return
}
}
@@ -1083,78 +1084,10 @@ main
initialize(this)
return
}
if (getmessage() == MAIL_PREVIOUS_MISSION_PARAMS)
// [automaticmode] finalize in sender==this context (initialize/parent safe here)
if (getmessage() == MAIL_LOAD_AUTO_MISSION_DONE)
{
callback($$SetNetworkMissionParamater$$, game_type, selection_to_standard[$$g_nAutoGameType$$])
// visibility
o_game_options[2].nselected = $$g_nAutoVisibility$$
callback($$SetNetworkMissionParamater$$, visibility, o_game_options[2].nselected)
// weather
o_game_options[3].nselected = $$g_nAutoWeather$$
callback($$SetNetworkMissionParamater$$, weather, o_game_options[3].nselected)
// time of day
o_game_options[4].nselected = $$g_nAutoTimeOfDay$$
callback($$SetNetworkMissionParamater$$, night_parameter, o_game_options[4].nselected)
callback($$Shell_CallbackHandler$$, ShellSetTime, o_game_options[4].nselected)
// time limit
int nAutoTL = $$g_nAutoTimeLimit$$
int temp_num
if nAutoTL >= 0
temp_num = nAutoTL
else
temp_num = TIME_VALUE_DEFAULT
int m
for (m = 0; m < o_game_options[5].list_size; m++)
{
if (makeint(o_game_options[5].list_item[m]) == temp_num)
{
o_game_options[5].nselected = m
break
}
}
callback($$SetNetworkMissionParamater$$, time_limit, temp_num)
// radar
int nTempParam = radar
int nTempValue = $$g_nAutoRadar$$
o_game_options[6].nselected = nTempValue
callback($$SetNetworkMissionParamater$$, nTempParam, nTempValue)
// heat
nTempParam = HEAT_PARAMETER
nTempValue = $$g_nAutoHeat$$
o_game_options[7].state = 0
callback($$SetNetworkMissionParamater$$, nTempParam, nTempValue)
// friendly fire
nTempParam = FRIENDLY_FIRE_PERCENTGE_PARAMETER
nTempValue = $$g_nAutoFriendlyFire$$
o_game_options[8].state = 0
callback($$SetNetworkMissionParamater$$, nTempParam, nTempValue)
// splash
nTempParam = SPLASH_ON_PARAMETER
nTempValue = $$g_nAutoSplash$$
o_game_options[9].state = 0
callback($$SetNetworkMissionParamater$$, nTempParam, nTempValue)
// unlimited ammo
nTempParam = UNLIMITED_AMMO_PARAMETER
nTempValue = $$g_nAutoUnlimitedAmmo$$
o_game_options[10].state = 0
callback($$SetNetworkMissionParamater$$, nTempParam, nTempValue)
// weapon jam
nTempParam = WEAPON_JAM_PARAMETER
nTempValue = $$g_nAutoWeaponJam$$
o_game_options[14].state = 0
callback($$SetNetworkMissionParamater$$, nTempParam, nTempValue)
// advance mode
nTempParam = ADVANCE_MODE_PARAMETER
nTempValue = $$g_nAutoAdvanceMode$$
o_game_options[15].state = 0
callback($$SetNetworkMissionParamater$$, nTempParam, nTempValue)
// armor mode
nTempParam = ARMOR_MODE_PARAMETER
nTempValue = $$g_nAutoArmorMode$$
o_game_options[16].state = 0
callback($$SetNetworkMissionParamater$$, nTempParam, nTempValue)
initialize(this)
// notify ConLobby: game type/params changed (updates cur_game_type, cur_team_val display)
mail(-9998, parent)
return
}