From b29ee57b37103930c911057c74eca5e04d08a849 Mon Sep 17 00:00:00 2001 From: Jan <> Date: Fri, 10 Jul 2015 21:06:58 +0200 Subject: Move LoadScenarioSection call to script counter callback function LoadScenarioSection was called directly from the scenario function StartGame which in turn was called by the menu object. When the "Done" entry in the menu was selected, C4ObjectMenu::MenuCommand executed the menu entry callback which called LoadScenarioSection. However, C4ObjectMenu::MenuCommand still used a dangling pointer to the object belonging to the menu that was deleted by LoadScenarioSection, thus causing random crashes. --- TemplePushing.c4s/Script.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/TemplePushing.c4s/Script.c b/TemplePushing.c4s/Script.c index 535f242..d123912 100644 --- a/TemplePushing.c4s/Script.c +++ b/TemplePushing.c4s/Script.c @@ -14,6 +14,8 @@ static section, mode; static numRelaunches; static deathmatchEnabled, deathmatchWinScore; static playerDeaths, playerScore, teamScore; +static sectionID; +static extinguisherEnabled, rotateInJumpEnabled; static ambienceEnabled; static suddendeathEnabled; static loadingSection; @@ -49,8 +51,6 @@ func Initialize() // Set possible spells SetScrollSpells([ABLA, MBOT, MFRB, MDBT, GVTY, MLGT, CFAL, MSSH, MINV, MARK, MFWV, MGFL, LAVS, MGPL, ICNL, MDFL, AFST, MGCY, MATT]); - - ScriptGo(true); } /*func TeamRow(int team) { return 1 + team * 1000; } @@ -156,20 +156,30 @@ func ShowLobby() LoadScenarioSection("Lobby"); } -func StartGame(object menu, string message) +func SetupDone(object menu, string message) { // Copy settings from menu - var sectionID = menu->LocalN("section"); + sectionID = menu->LocalN("section"); mode = menu->LocalN("mode"); - var extinguisherEnabled = menu->LocalN("extinguisherEnabled"); + extinguisherEnabled = menu->LocalN("extinguisherEnabled"); suddendeathEnabled = menu->LocalN("suddendeathEnabled"); - var rotateInJumpEnabled = menu->LocalN("rotateInJumpEnabled"); + rotateInJumpEnabled = menu->LocalN("rotateInJumpEnabled"); ambienceEnabled = menu->LocalN("ambienceEnabled"); numRelaunches = menu->LocalN("numRelaunches"); deathmatchEnabled = menu->LocalN("deathmatchEnabled"); deathmatchWinScore = menu->LocalN("deathmatchWinScore"); menu->RemoveObject(); + gameStartMessage = message; + + // Make sure LoadScenarioSection is not called from an object by swapping it out to a script counter callback + ScriptGo(true); +} + +func Script0() +{ + ScriptGo(false); + // Change scenario section loadingSection = true; LoadScenarioSection(DefinitionCall(sectionID, "SectionName")); @@ -243,8 +253,6 @@ func StartGame(object menu, string message) if (rotateInJumpEnabled) CreateObject(RIJP, 0, 0, NO_OWNER); CreateObject(OFDR, 0, 0, NO_OWNER); - - // Create mode objects if (mode == MODE_Magic) { @@ -286,7 +294,6 @@ func StartGame(object menu, string message) InitializePlayer(GetPlayerByIndex(i)); } - gameStartMessage = message; ShowCountdown(); } -- cgit v1.2.3-54-g00ecf