From a74aa554093622cf40a228b5a785e79c7a64f2cd Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Sun, 25 Nov 2018 04:17:00 +0100 Subject: [PATCH] character: allow creating characters with NULL name Useful for shared characters that are going to be swapped between their archetypes. --- src/character.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/character.c b/src/character.c index acf6e7e..e999741 100644 --- a/src/character.c +++ b/src/character.c @@ -307,9 +307,11 @@ SYMBOL_EXPORT void RegisterSpritesheet(struct Game* game, struct Character* char } SYMBOL_EXPORT struct Character* CreateCharacter(struct Game* game, char* name) { - PrintConsole(game, "Creating character %s...", name); + if (name) { + PrintConsole(game, "Creating character %s...", name); + } struct Character* character = malloc(sizeof(struct Character)); - character->name = strdup(name); + character->name = name ? strdup(name) : NULL; character->frame = NULL; character->spritesheet = NULL; character->spritesheets = NULL; @@ -396,7 +398,9 @@ SYMBOL_EXPORT void DestroyCharacter(struct Game* game, struct Character* charact if (character->predecessor) { free(character->predecessor); } - free(character->name); + if (character->name) { + free(character->name); + } free(character); }