Skip to content

Commit

Permalink
Stop loading on duplicate definition from same mod (#58542)
Browse files Browse the repository at this point in the history
Don't allow the game to complete loading if an object is defined twice,
as objects being defined twice is likely to cause more errors.
  • Loading branch information
anothersimulacrum committed Jun 19, 2022
1 parent cc6a29c commit 91fd32c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/mod_tracker.h
Expand Up @@ -26,6 +26,12 @@
* after the 'id' member has been assigned.
*/

class mod_error : public std::runtime_error
{
public:
explicit mod_error( const std::string &msg ) : std::runtime_error( msg ) {}
};

struct mod_tracker {
/** Template magic to determine if the conditions above are satisfied */
template<typename T, typename = cata::void_t<>>
Expand Down Expand Up @@ -72,8 +78,8 @@ struct has_src_member<T, cata::void_t<decltype( std::declval<T &>().src.emplace_
// We need to make sure we're keeping where this entity has been loaded
// If the id this was last loaded with is not this one, discard the history and start again
if( n.src.back() == o.src.back() ) {
debugmsg( "%s (%s) has two definitions from the same source (%s)!", n.id.str(),
demangle( typeid( T ).name() ), n.src.back().second.str() );
throw mod_error( string_format( "%s (%s) has two definitions from the same source (%s)!",
n.id.str(), demangle( typeid( T ).name() ), n.src.back().second.str() ) );
}
}

Expand Down

0 comments on commit 91fd32c

Please sign in to comment.