character: allow creating characters with NULL name

Useful for shared characters that are going to be swapped between
their archetypes.
This commit is contained in:
Sebastian Krzyszkowiak 2018-11-25 04:17:00 +01:00
parent a7d2ed55c0
commit a74aa55409
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF

View file

@ -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);
}