Skip to content

Commit

Permalink
Fix blueprint loading crash with units with no categories (#6281)
Browse files Browse the repository at this point in the history
Fix `ExtractCloakMeshBlueprint` (which assumes Categories) being called on a unit without a Categories bp table.
Fix a crash when the "Weak" weapon categories are being assigned to a unit without a Categories bp table.

Co-authored-by: lL1l1 <[email protected]>
  • Loading branch information
The-Balthazar and lL1l1 authored Oct 12, 2024
1 parent 6261cc0 commit c95b42a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog/snippets/fix.6281.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- (#6281) Fix two errors during blueprint loading when a unit has no Categories table in its blueprint.
- `ExtractCloakMeshBlueprint`-related error.
- Automatic category assignment for the "Weak" weapon categories.
3 changes: 1 addition & 2 deletions lua/system/Blueprints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,9 @@ end
---@param all_bps BlueprintsTable All the blueprints of the game.
function PreModBlueprints(all_bps)
for _, bp in all_bps.Unit do
ExtractCloakMeshBlueprint(bp)

-- Units with no categories are skipped
if bp.Categories then
ExtractCloakMeshBlueprint(bp)

-- Construct hash-based categories
bp.CategoriesHash = table.hash(bp.Categories)
Expand Down
4 changes: 4 additions & 0 deletions lua/system/blueprints-units.lua
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,10 @@ local function PostProcessUnit(unit)
table.sort(array, function(e1, e2) return e1.Damage > e2.Damage end)
local factor = array[1].Damage

if not unit.Categories then
unit.Categories = {}
end

for category, damage in pairs(damagePerRangeCategory) do
if damage > 0 then
local cat = "OVERLAY" .. category
Expand Down

0 comments on commit c95b42a

Please sign in to comment.