Skip to content

Commit

Permalink
Fix more JSON failed to visit member errors
Browse files Browse the repository at this point in the history
As they appear in the diff:

1. I couldn't track down where the error was occurring here, so I just
   told the tileset load to ignore it. (It was loading correctly)

2. This makes it more clear why the 'additional_tiles' member is not
   visited.

3. Color loaders are loaded separately from their type member being
   loaded (but it is required elsewhere), so just visit it.

4. In initializing the JsonObjectInputArchive, a JsonObject was created
   and destroyed without visiting members. Make that explicit, and tell
   it  to ignore omitted members.

5. Support for reactor and tank _plut was removed recently, but old
   saves may still have them. Just visit them, it'll be resolved with a
   new save.

6. grab_type was only read if grab_point is valid, but it was
   unconditionally written. So read it, but don't always use it.

7. See #5

8. This member was written, but not read.

9. This member was written, but not read.

10. external options have an info string explaining what they do. Visit
    this string, even though it doesn't contain anything the game uses.
    I chose to visit it instead of commenting it out to avoid massive
    amounts of lines changed (in mods and in data/core).
  • Loading branch information
anothersimulacrum committed Dec 13, 2020
1 parent aa9f4f8 commit 54c3ce3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ void tileset_loader::load( const std::string &tileset_id, const bool precheck )

JsonIn config_json( config_file );
JsonObject config = config_json.get_object();
config.allow_omitted_members();

// "tile_info" section must exist.
if( !config.has_member( "tile_info" ) ) {
Expand Down Expand Up @@ -928,6 +929,8 @@ void tileset_loader::load_tilejson_from_file( const JsonObject &config )
curr_subtile.height_3d = t_h3d;
curr_tile.available_subtiles.push_back( s_id );
}
} else if( entry.has_array( "additional_tiles" ) ) {
entry.throw_error( "Additional tiles defined, but 'multitile' is not true." );
}
// write the information of the base tile to curr_tile
curr_tile.multitile = t_multi;
Expand Down
2 changes: 2 additions & 0 deletions src/color_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class color_loader
jsin.start_array();
while( !jsin.end_array() ) {
JsonObject jo = jsin.get_object();
// This isn't actually read (here), so just ignore it
jo.get_string( "type" );
load_colors( jo );
jo.finish();
}
Expand Down
4 changes: 3 additions & 1 deletion src/savegame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,9 @@ void mongroup::io( Archive &archive )

void mongroup::deserialize( JsonIn &data )
{
io::JsonObjectInputArchive archive( data );
JsonObject jo = data.get_object();
jo.allow_omitted_members();
io::JsonObjectInputArchive archive( jo );
io( archive );
}

Expand Down
24 changes: 24 additions & 0 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,15 @@ void avatar::load( const JsonObject &data )
{
player::load( data );

// Remove after 0.F
// Exists to prevent failed to visit member errors
if( data.has_member( "reactor_plut" ) ) {
data.get_int( "reactor_plut" );
}
if( data.has_member( "tank_plut" ) ) {
data.get_int( "tank_plut" );
}

std::string prof_ident = "(null)";
if( data.read( "profession", prof_ident ) && string_id<profession>( prof_ident ).is_valid() ) {
prof = &string_id<profession>( prof_ident ).obj();
Expand All @@ -1269,7 +1278,12 @@ void avatar::load( const JsonObject &data )
if( grab_point.x != 0 || grab_point.y != 0 ) {
grab_typestr = "OBJECT_VEHICLE";
data.read( "grab_type", grab_typestr );
} else {
// we just want to read, but ignore grab_type
std::string fake;
data.read( "grab_type", fake );
}

const auto iter = std::find( obj_type_name.begin(), obj_type_name.end(), grab_typestr );
grab( iter == obj_type_name.end() ?
object_type::NONE : static_cast<object_type>( std::distance( obj_type_name.begin(), iter ) ),
Expand Down Expand Up @@ -1637,9 +1651,19 @@ void npc::load( const JsonObject &data )
time_point companion_mission_t_r = calendar::turn_zero;
std::string act_id;

// Remove after 0.F
// Exists to prevent failed to visit member errors
if( data.has_member( "reactor_plut" ) ) {
data.get_int( "reactor_plut" );
}
if( data.has_member( "tank_plut" ) ) {
data.get_int( "tank_plut" );
}

data.read( "name", name );
data.read( "marked_for_death", marked_for_death );
data.read( "dead", dead );
data.read( "patience", patience );
if( data.has_number( "myclass" ) ) {
data.read( "myclass", classtmp );
myclass = npc_class::from_legacy_int( classtmp );
Expand Down
1 change: 1 addition & 0 deletions src/uistate.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class uistatedata
jo.read( "adv_inv_container_in_vehicle", adv_inv_container_in_vehicle );
jo.read( "adv_inv_container_type", adv_inv_container_type );
jo.read( "adv_inv_container_content_type", adv_inv_container_content_type );
jo.read( "editmap_nsa_viewmode", editmap_nsa_viewmode );
jo.read( "overmap_blinking", overmap_blinking );
jo.read( "overmap_show_overlays", overmap_show_overlays );
jo.read( "overmap_show_map_notes", overmap_show_map_notes );
Expand Down
4 changes: 4 additions & 0 deletions src/worldfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,10 @@ void load_external_option( const JsonObject &jo )
} else {
jo.throw_error( "Unknown or unsupported stype for external option", "stype" );
}
// Just visit this member if it exists
if( jo.has_member( "info" ) ) {
jo.get_string( "info" );
}
}

mod_manager &worldfactory::get_mod_manager()
Expand Down

0 comments on commit 54c3ce3

Please sign in to comment.