Page 1 of 1

Crash when trying to load a layer through the LUA [Solved]

Posted: Wed Oct 03, 2012 7:36 pm
by GAB
Ok, so recently I started an update of my latest map and implemented the Random Weather function. I wanted to load with each of the possible weather variables a layer with objects and regions specific to that variable, like Marth wanted to do in this thread.

Problem is that, when I try this, the map crashes after loading with these two severity 3 errors.

Code: Select all

Message Severity: 3
C:\Battlefront2\main\RedEngineFL\Memory\RedMemory.cpp(561)
attempted to allocate from invalid heap -1

Message Severity: 3
C:\Battlefront2\main\RedEngineFL\Memory\RedMemory.cpp(538)
Allocating 720 bytes failed - no free blocks left in Heap -1 ()
Here's my lua:
Hidden/Spoiler:
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

-- load the gametype script
ScriptCB_DoFile("ObjectiveConquest")
ScriptCB_DoFile("setup_teams")

-- REP Attacking (attacker is always #1)
REP = 1;
CIS = 2;
-- These variables do not change
ATT = REP;
DEF = CIS;


function ScriptPostLoad()

WeatherMode = math.random(1,3)
weather()

SetProperty("entry_door1", "IsLocked", 1)
SetProperty("entry_door2", "IsLocked", 1)


--This defines the CPs. These need to happen first
cp1 = CommandPost:New{name = "cp1"}
cp2 = CommandPost:New{name = "cp2"}
cp3 = CommandPost:New{name = "cp3"}
cp4 = CommandPost:New{name = "cp4"}
cp5 = CommandPost:New{name = "cp5"}
cp6 = CommandPost:New{name = "cp6"}



--This sets up the actual objective. This needs to happen after cp's are defined
conquest = ObjectiveConquest:New{teamATT = ATT, teamDEF = DEF,
textATT = "game.modes.con",
textDEF = "game.modes.con2",
multiplayerRules = true}

--This adds the CPs to the objective. This needs to happen after the objective is set up
conquest:AddCommandPost(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
conquest:AddCommandPost(cp4)
conquest:AddCommandPost(cp5)
conquest:AddCommandPost(cp6)

conquest:Start()

EnableSPHeroRules()

AddDeathRegion("deathregion")

end


---------------------------------------------------------------------------
-- FUNCTION: ScriptInit
-- PURPOSE: This function is only run once
-- INPUT:
-- OUTPUT:
-- NOTES: The name, 'ScriptInit' is a chosen convention, and each
-- mission script must contain a version of this function, as
-- it is called from C to start the mission.
---------------------------------------------------------------------------
function ScriptInit()

ReadDataFile("dc:Load\\AL3_con.lvl")
ReadDataFile("dc:ingame.lvl")
ReadDataFile("ingame.lvl")

SetMaxFlyHeight(20)
SetMaxPlayerFlyHeight (20)
AISnipeSuitabilityDist(15)

SetMemoryPoolSize ("ClothData",20)
SetMemoryPoolSize ("Combo",50) -- should be ~ 2x number of jedi classes
SetMemoryPoolSize ("Combo::State",650) -- should be ~12x #Combo
SetMemoryPoolSize ("Combo::Transition",650) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Condition",650) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Attack",550) -- should be ~8-12x #Combo
SetMemoryPoolSize ("Combo::DamageSample",6000) -- should be ~8-12x #Combo::Attack
SetMemoryPoolSize ("Combo::Deflect",100) -- should be ~1x #combo

ReadDataFile("sound\\kas.lvl;kas2cw")
ReadDataFile("dc:sound\\AL3.lvl;tescw")

ReadDataFile("SIDE\\rep.lvl",
"rep_inf_ep3_rifleman",
"rep_inf_ep3_rocketeer",
"rep_inf_ep3_engineer",
"rep_inf_ep3_sniper",
"rep_inf_ep3_officer",
"rep_inf_ep3_jettrooper",
"rep_hero_kiyadimundi",
"rep_hover_fightertank",
"rep_walk_oneman_atst")
ReadDataFile("dc:SIDE\\ren.lvl")

ReadDataFile("SIDE\\cis.lvl",
"cis_inf_rifleman",
"cis_inf_rocketeer",
"cis_inf_engineer",
"cis_inf_sniper",
"cis_inf_officer",
"cis_inf_droideka",
"cis_hero_jangofett",
"cis_tread_snailtank",
"cis_hover_aat")
ReadDataFile("dc:SIDE\\cin.lvl")

ReadDataFile("dc:SIDE\\tur.lvl",
"tur_bldg_chaingun_roof_remote")

SetupTeams{
rep = {
team = REP,
units = 32,
reinforcements = 150,
soldier = { "rep_inf_ep3_rifleman",8, 24},
assault = { "rep_inf_ep3_rocketeer",4, 8},
engineer = { "rep_inf_ep3_engineer",4, 8},
sniper = { "rep_inf_ep3_sniper",1, 3},
officer = {"rep_inf_ep3_officer",1, 4},
special = { "rep_inf_ep3_jettrooper",1, 4},

},
cis = {
team = CIS,
units = 32,
reinforcements = 150,
soldier = { "cis_inf_rifleman",8, 24},
assault = { "cis_inf_rocketeer",4, 8},
engineer = { "cis_inf_engineer",4, 8},
sniper = { "cis_inf_sniper",1, 3},
officer = {"cis_inf_officer",1, 4},
special = { "cis_inf_droideka",1, 4},
}
}

SetHeroClass(CIS, "cis_hero_jangofett")
SetHeroClass(REP, "rep_hero_kiyadimundi")

-- Level Stats
ClearWalkers()
AddWalkerType(0, 4) -- special -> droidekas
AddWalkerType(1, 4) -- 1x2 (1 pair of legs)

local weaponCnt = 1024
SetMemoryPoolSize("Aimer", 75)
SetMemoryPoolSize("AmmoCounter", weaponCnt)
SetMemoryPoolSize("BaseHint", 1024)
SetMemoryPoolSize("EnergyBar", weaponCnt)
SetMemoryPoolSize("EntityCloth", 32)
SetMemoryPoolSize("EntityFlyer", 32)
SetMemoryPoolSize("EntityWalker", 32)
SetMemoryPoolSize("EntityHover", 32)
SetMemoryPoolSize("EntityLight", 256)
SetMemoryPoolSize("EntityRemoteTerminal", 12)
SetMemoryPoolSize("EntitySoundStream", 12)
SetMemoryPoolSize("EntitySoundStatic", 32)
SetMemoryPoolSize("MountedTurret", 32)
SetMemoryPoolSize("Navigator", 128)
SetMemoryPoolSize("Obstacle", 1024)
SetMemoryPoolSize("PathNode", 1024)
SetMemoryPoolSize("RedOmniLight", 252)
SetMemoryPoolSize("SoundSpaceRegion", 64)
SetMemoryPoolSize("SoldierAnimation", 500)
SetMemoryPoolSize("TreeGridStack", 1024)
SetMemoryPoolSize("UnitAgent", 128)
SetMemoryPoolSize("UnitController", 128)
SetMemoryPoolSize("Weapon", weaponCnt)

function weather()
if WeatherMode == 1 then
ReadDataFile("dc:AL3\\sky.lvl", "dawn")
ReadDataFile("dc:AL3\\AL3.lvl", "AL3_conquest", "AL3_dawn")
elseif WeatherMode == 2 then
ReadDataFile("dc:AL3\\sky.lvl", "snow")
ReadDataFile("dc:AL3\\AL3.lvl", "AL3_conquest", "AL3_snow")
elseif WeatherMode == 3 then
ReadDataFile("dc:AL3\\sky.lvl", "dusk")
ReadDataFile("dc:AL3\\AL3.lvl", "AL3_conquest", "AL3_dusk")
end
end

SetSpawnDelay(10.0, 0.25)
-- ReadDataFile("dc:AL3\\AL3.lvl", "AL3_conquest")
SetDenseEnvironment("true")
SetAIViewMultiplier(0.85)

-- Sound

SetSoundEffect("ScopeDisplayZoomIn", "binocularzoomin")
SetSoundEffect("ScopeDisplayZoomOut", "binocularzoomout")

voiceSlow = OpenAudioStream("sound\\global.lvl", "rep_unit_vo_slow")
AudioStreamAppendSegments("sound\\global.lvl", "cis_unit_vo_slow", voiceSlow)
AudioStreamAppendSegments("sound\\global.lvl", "global_vo_slow", voiceSlow)

voiceQuick = OpenAudioStream("sound\\global.lvl", "rep_unit_vo_quick")
AudioStreamAppendSegments("sound\\global.lvl", "cis_unit_vo_quick", voiceQuick)

OpenAudioStream("sound\\global.lvl", "cw_music")
-- OpenAudioStream("sound\\global.lvl", "global_vo_quick")
-- OpenAudioStream("sound\\global.lvl", "global_vo_slow")
OpenAudioStream("dc:sound\\AL3.lvl", "tes1")
OpenAudioStream("dc:sound\\AL3.lvl", "tes1")

SetBleedingVoiceOver(REP, REP, "rep_off_com_report_us_overwhelmed", 1)
SetBleedingVoiceOver(REP, CIS, "rep_off_com_report_enemy_losing", 1)
SetBleedingVoiceOver(CIS, REP, "cis_off_com_report_enemy_losing", 1)
SetBleedingVoiceOver(CIS, CIS, "cis_off_com_report_us_overwhelmed", 1)

SetOutOfBoundsVoiceOver(2, "cisleaving")
SetOutOfBoundsVoiceOver(1, "repleaving")

SetAmbientMusic(REP, 1.0, "rep_kas_amb_start", 0,1)
SetAmbientMusic(REP, 0.8, "rep_kas_amb_middle", 1,1)
SetAmbientMusic(REP, 0.2,"rep_kas_amb_end", 2,1)
SetAmbientMusic(CIS, 1.0, "cis_kas_amb_start", 0,1)
SetAmbientMusic(CIS, 0.8, "cis_kas_amb_middle", 1,1)
SetAmbientMusic(CIS, 0.2,"cis_kas_amb_end", 2,1)

SetVictoryMusic(REP, "rep_kas_amb_victory")
SetDefeatMusic (REP, "rep_kas_amb_defeat")
SetVictoryMusic(CIS, "cis_kas_amb_victory")
SetDefeatMusic (CIS, "cis_kas_amb_defeat")

SetSoundEffect("ScopeDisplayZoomIn", "binocularzoomin")
SetSoundEffect("ScopeDisplayZoomOut", "binocularzoomout")
--SetSoundEffect("BirdScatter", "birdsFlySeq1")
--SetSoundEffect("WeaponUnableSelect", "com_weap_inf_weaponchange_null")
--SetSoundEffect("WeaponModeUnableSelect", "com_weap_inf_modechange_null")
SetSoundEffect("SpawnDisplayUnitChange", "shell_select_unit")
SetSoundEffect("SpawnDisplayUnitAccept", "shell_menu_enter")
SetSoundEffect("SpawnDisplaySpawnPointChange", "shell_select_change")
SetSoundEffect("SpawnDisplaySpawnPointAccept", "shell_menu_enter")
SetSoundEffect("SpawnDisplayBack", "shell_menu_exit")


--OpeningSateliteShot
AddCameraShot(0.690961, -0.023666, 0.722081, 0.024732, -90.000000, 6.373174, 259.261047);

end
And the map's REQ (the one located in the world1 folder)
Hidden/Spoiler:
ucft
{
REQN
{
"config"
}

REQN
{
"texture"
"water_bumpmap_0"
"water_bumpmap_1"
"water_bumpmap_2"
"water_bumpmap_3"
"water_bumpmap_4"
"water_bumpmap_5"
"water_bumpmap_6"
"water_bumpmap_7"
"water_bumpmap_8"
"water_bumpmap_9"
"water_bumpmap_10"
"water_bumpmap_11"
"water_bumpmap_12"
"water_bumpmap_13"
"water_bumpmap_14"
"water_bumpmap_15"

"water_normalmap_0"
"water_normalmap_1"
"water_normalmap_2"
"water_normalmap_3"
"water_normalmap_4"
"water_normalmap_5"
"water_normalmap_6"
"water_normalmap_7"
"water_normalmap_8"
"water_normalmap_9"
"water_normalmap_10"
"water_normalmap_11"
"water_normalmap_12"
"water_normalmap_13"
"water_normalmap_14"
"water_normalmap_15"
"AL3_map"
}
REQN
{
"path"
"AL3"
}
REQN
{
"congraph"
"AL3"
}
REQN
{
"world"
"AL3"
"AL3_Trees"
"AL3_RainShadow"
"AL3_collision"
"AL3_Droids"
"AL3_SoundSpaces"
"AL3_SoundStreams"
}
REQN
{
"prop"
"AL3"
}
REQN
{
"class"
"bluelight"
"redlight"
"greenlight"
"whitelight"
}
REQN
{
"config"
}
REQN
{
"lvl"
"AL3_Conquest"
"AL3_1flag"
"AL3_hunt"
"AL3_dawn"
"AL3_snow"
"AL3_dusk"
}
REQN
{
"boundary"
"AL3"
}
}
Does anybody know what is the cause of the errors mentioned above and if there's a solution to them?

Re: Crash when trying to load a layer through the LUA

Posted: Wed Oct 03, 2012 11:15 pm
by AQT
First off, you currently have:
GAB wrote:WeatherMode = math.random(1,3)
weather()

--...

function weather()
if WeatherMode == 1 then
ReadDataFile("dc:AL3\\sky.lvl", "dawn")
ReadDataFile("dc:AL3\\AL3.lvl", "AL3_conquest", "AL3_dawn")
elseif WeatherMode == 2 then
ReadDataFile("dc:AL3\\sky.lvl", "snow")
ReadDataFile("dc:AL3\\AL3.lvl", "AL3_conquest", "AL3_snow")
elseif WeatherMode == 3 then
ReadDataFile("dc:AL3\\sky.lvl", "dusk")
ReadDataFile("dc:AL3\\AL3.lvl", "AL3_conquest", "AL3_dusk")
end
end
It should be:

Code: Select all

--...

WeatherMode = math.random(1,3)

if WeatherMode == 1 then
ReadDataFile("dc:AL3\\sky.lvl", "dawn")
ReadDataFile("dc:AL3\\AL3.lvl", "AL3_conquest", "AL3_dawn")
elseif WeatherMode == 2 then
ReadDataFile("dc:AL3\\sky.lvl", "snow")
ReadDataFile("dc:AL3\\AL3.lvl", "AL3_conquest", "AL3_snow")
elseif WeatherMode == 3 then
ReadDataFile("dc:AL3\\sky.lvl", "dusk")
ReadDataFile("dc:AL3\\AL3.lvl", "AL3_conquest", "AL3_dusk")
end
And how exactly did you configure the dawn, snow, and dusk layers? Were there anything else you did aside from creating/configuring these three layers and implementing the randomization function prior to this crash occurring?

Re: Crash when trying to load a layer through the LUA

Posted: Thu Oct 04, 2012 12:10 pm
by GAB
Ok AQT, I'm going to try this.
AQT wrote:And how exactly did you configure the dawn, snow, and dusk layers?
In the same way they were configured for the Dagobah's xwing and gunship props.
AQT wrote:Were there anything else you did aside from creating/configuring these three layers and implementing the randomization function prior to this crash occurring?
No. The problem started when I tried to load the layers. By the way, when I comment those lines out the map doesn't crash.

EDIT:

Thanks a lot AQT. That solved the problem. Everything works perfectly now :thumbs: