From 4986df6fb6a7d146763d594106104cbf836665f5 Mon Sep 17 00:00:00 2001 From: Shariq Shah Date: Wed, 8 Jan 2020 15:03:20 +1100 Subject: [PATCH] Fixed crash where deleting a hovered entity in editor would result in us crashing because the editor didn't know about the updated state of the entity and would still be pointing to it --- src/common/version.h | 2 +- src/game/editor.c | 11 +++++++++++ src/game/editor.h | 1 + src/game/game.c | 1 + todo.txt | 6 +++--- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/common/version.h b/src/common/version.h index 46def51..6a0e7f3 100755 --- a/src/common/version.h +++ b/src/common/version.h @@ -4,7 +4,7 @@ /* Auto generated version file. DO NOT MODIFY */ #define SYMMETRY_VERSION_MAJOR 0 #define SYMMETRY_VERSION_MINOR 1 -#define SYMMETRY_VERSION_REVISION 305 +#define SYMMETRY_VERSION_REVISION 306 #define SYMMETRY_VERSION_BRANCH "dev" #endif \ No newline at end of file diff --git a/src/game/editor.c b/src/game/editor.c index b0ce6e0..8f7b016 100755 --- a/src/game/editor.c +++ b/src/game/editor.c @@ -1223,6 +1223,8 @@ void editor_on_key_release(const struct Event* event) { editor->selected_entity->flags |= EF_MARKED_FOR_DELETION; editor_entity_select(editor, NULL); + if(editor->hovered_entity == editor->selected_entity) + editor->hovered_entity = NULL; } if(event->key.key == KEY_D && input_is_key_pressed(KEY_LCTRL) && editor->selected_entity && !editor->camera_looking_around) @@ -1664,6 +1666,8 @@ void editor_show_entity_in_list(struct Editor* editor, struct nk_context* contex { entity->flags |= EF_MARKED_FOR_DELETION; editor_entity_select(editor, NULL); + if(editor->hovered_entity == entity) + editor->hovered_entity = NULL; } if(nk_contextual_item_label(context, "Save", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE)) @@ -2449,3 +2453,10 @@ void editor_entity_dialog(struct Editor* editor, struct nk_context* context) } context->style.window.fixed_background.data.color.a = previous_opacity; } + +void editor_post_update(struct Editor* editor) +{ + if(editor->hovered_entity && !(editor->hovered_entity->flags & EF_ACTIVE)) + editor->hovered_entity = NULL; +} + diff --git a/src/game/editor.h b/src/game/editor.h index 498c7ae..0a80af8 100755 --- a/src/game/editor.h +++ b/src/game/editor.h @@ -64,6 +64,7 @@ void editor_camera_init(struct Editor* editor_state, struct Hashmap* cvars); void editor_init_entities(struct Editor* editor); void editor_render(struct Editor* editor_state, struct Camera* active_camera); void editor_update(struct Editor* editor_state, float dt); +void editor_post_update(struct Editor* editor); void editor_cleanup(struct Editor* editor_state); #endif diff --git a/src/game/game.c b/src/game/game.c index 05f4794..9e79512 100755 --- a/src/game/game.c +++ b/src/game/game.c @@ -581,6 +581,7 @@ void game_post_update(float dt) scene_post_update(game_state->scene); sound_update_3d(game_state->sound); debug_vars_post_update(game_state->debug_vars); + editor_post_update(game_state->editor); } void game_debug_gui(float dt) diff --git a/todo.txt b/todo.txt index 970fb4c..2cae4fe 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,4 @@ Todo: - ? Only show bounding box for hovered entity instead of wireframe mesh - - Fix crash where if an entity is hoverd in editor and deleted, the game crashes because the hovered variable in editor doesn't know that the entity was deleted ? Write entity flags to scene file or when saving entity to file? ? Add scene init/de-init function hashmap that maps a function that should be called when scene is loaded and unloaded. Save this to file for every scene or map functions based on the name of the scene? - Command to create a placeholder entity of a particular type in a file @@ -108,6 +106,7 @@ Improvements: - Improve grid/immediate mode drawing by switching to glDrawElements instead of glDrawArrays. - Investigate why transparency is not working for materials - Picking for other entity types like lights etc by specifically ray casting for them or in editor switching to pick-mode that specifies if we're picking lights or meshes etc + ? Only show bounding box for hovered entity instead of wireframe mesh Bugs: - Better handling of wav format checking at load time @@ -395,4 +394,5 @@ Done: * Disabled picking when a tool is active in editor * Simplified rendering further and removed unnecessary intermediate fbos * We no longer keep geoemtry data loaded from files as it is not needed after data is passed on to opengl - * Shift-A to add entity to scene \ No newline at end of file + * Shift-A to add entity to scene + * Fixed crash where if an entity is hoverd in editor and deleted, the game crashes because the hovered variable in editor doesn't know that the entity was deleted \ No newline at end of file