Skip to content

Commit

Permalink
More checks to prevent already freed portraits to cause trouble (#1702)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jowan-Spooner authored Aug 31, 2023
1 parent 42bd66e commit 11428c5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions addons/dialogic/Modules/Character/subsystem_portraits.gd
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,21 @@ func leave_all_characters(animation_name:String="", animation_length:float= 0, a
func remove_character(character:DialogicCharacter) -> void:
if !is_character_joined(character):
return
if dialogic.current_state_info['portraits'][character.resource_path].node is Node:
if is_instance_valid(dialogic.current_state_info['portraits'][character.resource_path].node) and \
dialogic.current_state_info['portraits'][character.resource_path].node is Node:
_remove_portrait(dialogic.current_state_info['portraits'][character.resource_path].node)
character_left.emit({'character':character})
dialogic.current_state_info['portraits'].erase(character.resource_path)


## Returns true if the given character is currently joined.
func is_character_joined(character:DialogicCharacter) -> bool:
return character.resource_path in dialogic.current_state_info['portraits']
if !character.resource_path in dialogic.current_state_info['portraits']:
return false
if dialogic.current_state_info['portraits'][character.resource_path].get('node', null) != null and \
is_instance_valid(dialogic.current_state_info['portraits'][character.resource_path].node):
return true
return false


## Returns a list of the joined charcters (as resources)
Expand Down

0 comments on commit 11428c5

Please sign in to comment.