Skip to content

Commit

Permalink
Fixes skill database reloading (#4669)
Browse files Browse the repository at this point in the history
* Fixes #4660.
* Resolves an issue with skill database reloading not clearing the previous data first.
* While clearing the YAML cache it will also resize the cache to the previous capacity.
Thanks to @teededung!
  • Loading branch information
aleos89 committed Mar 4, 2020
1 parent 5c35ec7 commit 496f362
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/common/database.hpp
Expand Up @@ -147,7 +147,11 @@ template <typename keytype, typename datatype> class TypesafeCachedYamlDatabase
void clear() override{
TypesafeYamlDatabase<keytype, datatype>::clear();

// Restore size after clearing
size_t cap = cache.capacity();

cache.clear();
cache.resize(cap, nullptr);
}

std::shared_ptr<datatype> find( keytype key ) override{
Expand Down
11 changes: 5 additions & 6 deletions src/map/skill.cpp
Expand Up @@ -21943,7 +21943,7 @@ uint64 SkillDatabase::parseBodyNode(const YAML::Node &node) {
void SkillDatabase::clear() {
TypesafeCachedYamlDatabase::clear();
memset(skilldb_id2idx, 0, sizeof(skilldb_id2idx));
skill_num = 0;
skill_num = 1;
}

SkillDatabase skill_db;
Expand Down Expand Up @@ -22485,15 +22485,14 @@ static void skill_readdb(void)
}

void skill_reload (void) {
struct s_mapiterator *iter;
struct map_session_data *sd;

skill_db.clear();
skill_readdb();
initChangeTables(); // Re-init Status Change tables

/* lets update all players skill tree : so that if any skill modes were changed they're properly updated */
iter = mapit_getallusers();
for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) {
s_mapiterator *iter = mapit_getallusers();

for( map_session_data *sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) {
pc_validate_skill(sd);
clif_skillinfoblock(sd);
}
Expand Down

0 comments on commit 496f362

Please sign in to comment.