Skip to content

Commit

Permalink
Fixing crash if file could not be loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
kestrelm committed Apr 30, 2016
1 parent 8b8e983 commit 60b164d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions creaturegodot/creaturegodot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static bool add_loaded_animation(CreatureModule::CreatureManager * creature_mana
return false;
}

void
bool
CreatureGodot::load_json(const String& filename_in)
{
auto global_path = Globals::get_singleton()->globalize_path(filename_in);
Expand All @@ -101,7 +101,7 @@ CreatureGodot::load_json(const String& filename_in)
if(!can_load)
{
std::cout<<"CreatureGodot::load_json() - ERRROR! Could not load file: "<<load_filename<<std::endl;
return;
return false;
}
std::cout<<"CreatureGodot::load_json() - Finished loading file: "<<load_filename<<std::endl;

Expand All @@ -121,6 +121,8 @@ CreatureGodot::load_json(const String& filename_in)

manager->SetActiveAnimationName(first_animation_name);
anim_name = String(first_animation_name.c_str());

return true;
}

bool CreatureGodot::blend_to_animation(String animation_name, float blend_delta)
Expand Down Expand Up @@ -315,9 +317,13 @@ Color CreatureGodot::get_color() const{

void CreatureGodot::set_asset_filename(const String& filename_in)
{
asset_filename = filename_in;
load_json(filename_in);
update_animation(0.1f);
auto retval = load_json(filename_in);

if(retval)
{
asset_filename = filename_in;
update_animation(0.1f);
}
}

String CreatureGodot::get_asset_filename() const
Expand Down
2 changes: 1 addition & 1 deletion creaturegodot/creaturegodot.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CreatureGodot : public Node2D {
static void _bind_methods();
public:

void load_json(const String& filename_in);
bool load_json(const String& filename_in);

void update_animation(float delta);

Expand Down

0 comments on commit 60b164d

Please sign in to comment.