Skip to content

Commit

Permalink
Added null checks where crashes occured (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
domenukk authored Aug 9, 2023
1 parent 70a948f commit c881d94
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions source/match/handlers/SelectionHandler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func _force_highlight(units_to_highlight):

func _unforce_highlight(units_not_to_highlight_anymore):
for unit in units_not_to_highlight_anymore.iterate():
if unit == null:
continue
var highlight = unit.find_child("Highlight")
if highlight != null:
highlight.unforce()
Expand Down
2 changes: 1 addition & 1 deletion source/match/hud/unit-menus/CommandCenterMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ func _ready():


func _on_produce_worker_button_pressed():
if unit.action != null and unit.action is ManagingProductionAction:
if unit != null and unit.action != null and unit.action is ManagingProductionAction:
unit.action.produce(WorkerUnit)
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ func provision(resources, metadata):
_number_of_pending_worker_resource_requests -= 1
if _ccs.is_empty():
return
_ccs[0].action.produce(WorkerScene)
_number_of_pending_workers += 1
var action = _ccs[0].action
if action != null:
action.produce(WorkerScene)
_number_of_pending_workers += 1
else:
print("Tried to call `produce` on a null-action")
elif metadata == "cc":
assert(
resources == Constants.Match.Units.CONSTRUCTION_COSTS[CommandCenterScene.resource_path],
Expand Down
6 changes: 4 additions & 2 deletions source/match/units/actions/FollowingToReachDistance.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func _ready():
_timer.timeout.connect(_refresh)
add_child(_timer)
_timer.start(REFRESH_INTERVAL)
_movement_trait.movement_finished.connect(_on_movement_finished)
if _movement_trait != null:
_movement_trait.movement_finished.connect(_on_movement_finished)
_refresh()


Expand Down Expand Up @@ -51,7 +52,8 @@ func _align_movement_if_needed():
_last_known_target_unit_position == null
or not _last_known_target_unit_position.is_equal_approx(_target_unit.global_position)
):
_movement_trait.move(_target_unit.global_position)
if _movement_trait != null:
_movement_trait.move(_target_unit.global_position)
_last_known_target_unit_position = _target_unit.global_position


Expand Down

0 comments on commit c881d94

Please sign in to comment.