Custom FC Command Crashes Game

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Custom FC Command Crashes Game

Post by commanderawesome »

...with this error:

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 50448 bytes failed - no free blocks left in Heap -1 ()
This is the command in question:
http://pastebin.com/3HBp6rVT

This occurred on Stock Mygeeto GCW conquest, using stock sides. I haven't tried any other maps.
razac920
2nd Lieutenant
2nd Lieutenant
Posts: 365
Joined: Sun Jan 16, 2011 12:42 am

Re: Custom FC Command Crashes Game

Post by razac920 »

Some context would be nice. Are you calling this fc command midgame? Because I don't think ReadDataFile works midgame. If you had previously loaded the other skins that you wanted, then maybe your command would work. Why don't you try removing the ReadDataFile line from your command and instead just mix up the stock skins already loaded, and see if that works?
User avatar
Nedarb7
Lieutenant General
Lieutenant General
Posts: 676
Joined: Sat Sep 22, 2012 3:41 pm

Re: Custom FC Command Crashes Game

Post by Nedarb7 »

ReadDataFile works perfectly fine ingame. Though it may require a little bit of time before you try using the contents from the level file.
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Custom FC Command Crashes Game

Post by commanderawesome »

I used the command right at the beginning of the level. I've had similar commands work perfectly fine in the past, like this one: http://pastebin.com/47WagWDB

These are all added though a global 1.3 patch user script.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Custom FC Command Crashes Game

Post by Maveritchell »

A couple quick observations:

1) Your "command description" is a nonsensical string - it's looking for a localization string, just like the example given in the comment.

2) Where are the variables all_inf_etc. defined? It looks like you could have mistakenly placed those as variables instead of strings, but they'd return nil that way as well.

And further, I'm not 100% sure whether you can properly read in from a side .lvl file after the script is loaded. It'd be better if you read in the optional units in ScriptInit and then made your custom command simply call for them.
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Custom FC Command Crashes Game

Post by commanderawesome »

Maveritchell wrote:A couple quick observations:

1) Your "command description" is a nonsensical string - it's looking for a localization string, just like the example given in the comment.
The command description shows up in game, that isn't a problem.
Maveritchell wrote:2) Where are the variables all_inf_etc. defined? It looks like you could have mistakenly placed those as variables instead of strings, but they'd return nil that way as well.
I'm trying to get it to check if each class exists. It still crashed even before I added those.
Maveritchell wrote:And further, I'm not 100% sure whether you can properly read in from a side .lvl file after the script is loaded. It'd be better if you read in the optional units in ScriptInit and then made your custom command simply call for them.
As I said in my previous post, I've done it before, and it has worked.
User avatar
Nedarb7
Lieutenant General
Lieutenant General
Posts: 676
Joined: Sat Sep 22, 2012 3:41 pm

Re: Custom FC Command Crashes Game

Post by Nedarb7 »

commanderawesome wrote:
Maveritchell wrote:2) Where are the variables all_inf_etc. defined? It looks like you could have mistakenly placed those as variables instead of strings, but they'd return nil that way as well.
I'm trying to get it to check if each class exists. It still crashed even before I added those.
The problem is that:

Code: Select all

all_inf_etc
Means nothing if the variable hasn't been set elsewhere. Because of that, you are changing every single class that is in your code, even if it isn't present in the game. My guess is that that is what is causing the game to crash.

Something like this would make more sense:

Code: Select all

all_inf_rifleman = true 

...

if all_inf_rifleman == true then
SetClassProperty(...)
end
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Custom FC Command Crashes Game

Post by Maveritchell »

commanderawesome wrote:I'm trying to get it to check if each class exists. It still crashed even before I added those.
That's the wrong way to go about it, then, because (for example) all_inf_rifleman will never exist (unless you make it a variable. Edit: Nedarb, you're making the same mistake. "All_inf_rifleman" as a reference is a string, not a variable.). You're trying to check to see (assuming you're working with SetupTeams) what class is assigned to the soldier table, and to do that you'd want to do something like:

Code: Select all

if soldier[1] == "all_inf_rifleman" then
SetClassProperty("all_inf_rifleman", "GeometryName", "all_inf_snowtrooper")
end
I don't know offhand if that's local to the SetupTeams .lua, but you should be able to check and verify that.

And if everything in the code you showed us worked (or had already stopped working before you added it), why are you showing us this? You need to be able to show where something crashed - it's hard to make a judgment when you post something you've already modified post-crash. In other words, work back until you have something that works, and then add things until it doesn't. We can help you understand better what the problem is then.
User avatar
Nedarb7
Lieutenant General
Lieutenant General
Posts: 676
Joined: Sat Sep 22, 2012 3:41 pm

Re: Custom FC Command Crashes Game

Post by Nedarb7 »

Maveritchell wrote:Edit: Nedarb, you're making the same mistake. "All_inf_rifleman" as a reference is a string, not a variable.).
With the code he had, I was just explaining what would need to be fixed.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Custom FC Command Crashes Game

Post by Maveritchell »

Nedarb7 wrote:
Maveritchell wrote:Edit: Nedarb, you're making the same mistake. "All_inf_rifleman" as a reference is a string, not a variable.).
With the code he had, I was just explaining what would need to be fixed.
That shouldn't cause a crash, though - a variable that's not set just returns nil, which he's already checking against. Consequently, none of his classes are changing, because none of the "if" statements are met.

That said, "the code he had" is a good point. If there's more code to be seen, it'd be worth seeing, especially if he has other things he thinks are working and they're versions of this he's "done before."
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Custom FC Command Crashes Game

Post by [RDH]Zerted »

All those if statements are false so none of the SetClassProperty lines are running so the problem is with the ff_AddCommand call or the ReadDataFile calls. Your ff_AddCommand arguments look fine* (and it's a RedMemory error), so the issue is with ReadDataFile. It looks like a memory pool is too small. I don't know which pools you need to add or increase, but look into doing that. There's also a ReadDataFileInGame function. I don't know how it differs from ReadDataFile.

You can use uf_isKnownClass(<class string>) to check if a unit class has been added to a side or not. uf_isKnownClass() returns false if the class hasn't been added to a side and a number if it has.

Example:

Code: Select all

if uf_isKnownClass('all_inf_rifleman') ~= false then
    SetClassProperty("all_inf_rifleman", "GeometryName", "all_inf_snowtrooper")
end
Rewriting all those if statements into a loop would be even better:
Hidden/Spoiler:
[code]--class properties to reconfigure
--format: <unit class> = { {<first property to change>}, {<second property to change>}, {etc...} ,}
---- format of <# property to change>
---- * table of 3 elements
---- ** 1st element: class name
---- ** 2nd element: property name
---- ** 3rd element: new property value
local changes = {
all_inf_rifleman = {{"all_inf_rifleman", "GeometryName", "all_inf_snowtrooper"},},
all_inf_rocketeer = {{"all_inf_rocketeer", "OverrideTexture", "all_inf_vanguard_hoth"}, {"all_inf_rocketeer", "OverrideTexture2", "Rebel_face02"},},
}

--apply all the property changes
for key, value in pairs(changes) do
if uf_isKnownClass(key) ~= false then
for _,arguments in ipairs(value) do
SetClassProperty(arguments[1], arguments[2], arguments[3])
end
end
end[/code]
*It's better to localize your strings, but when the localization key doesn't exist the game simple outputs the key it was looking for. Thus using text in any key location does work, but you won't be able to translate it (which doesn't matter for personal projects).
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Custom FC Command Crashes Game

Post by commanderawesome »

Maveritchell wrote:if everything in the code you showed us worked (or had already stopped working before you added it), why are you showing us this?
The code that works is a different command, which changes Phase 2 clones to Phase 1 clones. Though obviously there are less variants of clones then there are rebels, so there wasn't a problem. Sorry for the confusion.
Maveritchell wrote:You're trying to check to see (assuming you're working with SetupTeams) what class is assigned to the soldier table, and to do that you'd want to do something like:

Code: Select all

if soldier[1] == "all_inf_rifleman" then
SetClassProperty("all_inf_rifleman", "GeometryName", "all_inf_snowtrooper")
end
I don't know offhand if that's local to the SetupTeams .lua, but you should be able to check and verify that.
[RDH]Zerted wrote:
You can use uf_isKnownClass(<class string>) to check if a unit class has been added to a side or not. uf_isKnownClass() returns false if the class hasn't been added to a side and a number if it has.

Example:

Code: Select all

if uf_isKnownClass('all_inf_rifleman') ~= false then
    SetClassProperty("all_inf_rifleman", "GeometryName", "all_inf_snowtrooper")
end
Rewriting all those if statements into a loop would be even better:
Hidden/Spoiler:
[code]--class properties to reconfigure
--format: <unit class> = { {<first property to change>}, {<second property to change>}, {etc...} ,}
---- format of <# property to change>
---- * table of 3 elements
---- ** 1st element: class name
---- ** 2nd element: property name
---- ** 3rd element: new property value
local changes = {
all_inf_rifleman = {{"all_inf_rifleman", "GeometryName", "all_inf_snowtrooper"},},
all_inf_rocketeer = {{"all_inf_rocketeer", "OverrideTexture", "all_inf_vanguard_hoth"}, {"all_inf_rocketeer", "OverrideTexture2", "Rebel_face02"},},
}

--apply all the property changes
for key, value in pairs(changes) do
if uf_isKnownClass(key) ~= false then
for _,arguments in ipairs(value) do
SetClassProperty(arguments[1], arguments[2], arguments[3])
end
end
end[/code]
I'll see which (and if) one of those works and report back.
[RDH]Zerted wrote: *It's better to localize your strings, but when the localization key doesn't exist the game simple outputs the key it was looking for. Thus using text in any key location does work, but you won't be able to translate it (which doesn't matter for personal projects).
I'll localize it when it's finished and ready for public release.
User avatar
Teancum
Jedi Admin
Jedi Admin
Posts: 11080
Joined: Wed Sep 07, 2005 11:42 pm
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set
Location: Indiana

Re: Custom FC Command Crashes Game

Post by Teancum »

Try running the memory command ("mem" ? ) in the console in the debug executable. The redMemory error implies that there wasn't enough room in the pool to fit all the required elements. Check the memory pools prior to running the command to be sure you have room.
User avatar
Nedarb7
Lieutenant General
Lieutenant General
Posts: 676
Joined: Sat Sep 22, 2012 3:41 pm

Re: Custom FC Command Crashes Game

Post by Nedarb7 »

You also might want to consider preventing the user from loading a level file more than once. Right now your code is setup to load the lvl file every time the button is pressed which is completely (from what I see) unnecessary.
Maveritchell wrote:That shouldn't cause a crash, though - a variable that's not set just returns nil, which he's already checking against. Consequently, none of his classes are changing, because none of the "if" statements are met.
Ah, right. My bad, I was confused due to a past experience.
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Custom FC Command Crashes Game

Post by commanderawesome »

Mav's solution didn't work. I will try Zerted's next.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Custom FC Command Crashes Game

Post by Maveritchell »

commanderawesome wrote:Mav's solution didn't work. I will try Zerted's next.
I just checked for you, and like I warned you - the list of soldier classes (as an array) is local to SetupTeams. You'll need to modify that so that typeList isn't local. I also gave you pseudocode (soldier[1] doesn't mean anything in the context of an unchanged mission script), which will obviously make things "not work."

Zerted's solution is probably simpler (given that it comes from the utility functions he made for the 1.3 patch), but no matter what you do, you'll have to read the instruction.
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Custom FC Command Crashes Game

Post by commanderawesome »

Code: Select all

for key, value in pairs(changes) do
    if uf_isKnownClass(key) ~= false then
        for _,arguments in ipairs(value) do
            SetClassProperty(arguments[1], arguments[2], arguments[3])
        end
    end
end
I'm a bit confused by this part. Do I leave this as it is, or change the variables to that of each unit?
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Custom FC Command Crashes Game

Post by [RDH]Zerted »

Leave it as is. Only edit the changes table.
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Custom FC Command Crashes Game

Post by commanderawesome »

Ok, thought so. Just checking to make sure. Also, just to eliminate the possibility of it being a memory issue, what memory pool would I need to raise? And to what number? (BTW, Zerted, did you get my E-Mail?)
Post Reply