Renumber crash fix (#1498)

close #1312
This commit is contained in:
manongjohn 2017-10-02 06:30:28 -04:00 committed by shun-iwasawa
parent 6d9ee85559
commit 88ffb47e4c
6 changed files with 40 additions and 9 deletions

View file

@ -141,6 +141,8 @@ Binding an id to 0 is equivalent to unbinding it.
//! succeeded. //! succeeded.
bool rebind(const std::string &srcId, const std::string &dstId); bool rebind(const std::string &srcId, const std::string &dstId);
bool renumber(const std::string &srcId, const TFrameId &fid);
//! Unbinds all known identifiers, resetting the image manager to its empty //! Unbinds all known identifiers, resetting the image manager to its empty
//! state. //! state.
void clear(); void clear();
@ -286,6 +288,8 @@ protected:
std::vector<TFrameId>, std::vector<TFrameId>,
std::vector<std::string>, bool){}; std::vector<std::string>, bool){};
virtual void setFid(const TFrameId &fid){};
//! Clears the builder's cached data. //! Clears the builder's cached data.
virtual void invalidate() { virtual void invalidate() {
m_info = TImageInfo(); m_info = TImageInfo();

View file

@ -450,8 +450,8 @@ public:
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
std::map<TXshCell, TXshCell>::const_iterator it = std::map<TXshCell, TXshCell>::const_iterator it =
table.find(cells[i]); table.find(cells[i]);
if (it != table.end()) if (it != table.end() && it->first != it->second)
cells[i] = it->second, changed = it->first != it->second; cells[i] = it->second, changed = true;
} }
if (changed) xsh->setCells(r0, c, n, &cells[0]); if (changed) xsh->setCells(r0, c, n, &cells[0]);
} }

View file

@ -231,6 +231,8 @@ void ImageLoader::buildAllIconsAndPutInCache(TXshSimpleLevel *level,
} }
} }
void ImageLoader::setFid(const TFrameId &fid) { m_fid = fid; }
//*************************************************************************************** //***************************************************************************************
// ImageRasterizer implementation // ImageRasterizer implementation
//*************************************************************************************** //***************************************************************************************

View file

@ -59,6 +59,10 @@ public:
std::vector<std::string> iconIds, std::vector<std::string> iconIds,
bool cacheImagesAsWell) override; bool cacheImagesAsWell) override;
/* Exposed to allow Fid to be updated due to a renumber operation
*/
void setFid(const TFrameId &fid);
protected: protected:
bool getInfo(TImageInfo &info, int imFlags, void *extData) override; bool getInfo(TImageInfo &info, int imFlags, void *extData) override;
TImageP build(int imFlags, void *extData) override; TImageP build(int imFlags, void *extData) override;

View file

@ -246,11 +246,24 @@ bool ImageManager::rebind(const std::string &srcId, const std::string &dstId) {
m_imp->m_builders.erase(st); m_imp->m_builders.erase(st);
m_imp->m_builders[dstId] = builder; m_imp->m_builders[dstId] = builder;
m_imp->m_builders[dstId]->m_cached = true;
m_imp->m_builders[dstId]->m_modified = true;
TImageCache::instance()->remap(dstId, srcId); TImageCache::instance()->remap(dstId, srcId);
return true; return true;
} }
bool ImageManager::renumber(const std::string &srcId, const TFrameId &fid) {
std::map<std::string, ImageBuilderP>::iterator st =
m_imp->m_builders.find(srcId);
if (st == m_imp->m_builders.end()) return false;
m_imp->m_builders[srcId]->setFid(fid);
return true;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void ImageManager::clear() { void ImageManager::clear() {

View file

@ -1964,11 +1964,20 @@ void TXshSimpleLevel::renumber(const std::vector<TFrameId> &fids) {
std::map<TFrameId, TFrameId>::iterator jt; std::map<TFrameId, TFrameId>::iterator jt;
{ {
for (i = 0, jt = table.begin(); jt != table.end(); ++jt, ++i) for (i = 0, jt = table.begin(); jt != table.end(); ++jt, ++i) {
im->rebind(getImageId(jt->first), "^" + std::to_string(i)); std::string Id = getImageId(jt->first);
im->rebind(Id, "^" + std::to_string(i));
TImageCache::instance()->remap("^icon:" + std::to_string(i),
"icon:" + Id);
}
for (i = 0, jt = table.begin(); jt != table.end(); ++jt, ++i) for (i = 0, jt = table.begin(); jt != table.end(); ++jt, ++i) {
im->rebind("^" + std::to_string(i), getImageId(jt->second)); std::string Id = getImageId(jt->second);
im->rebind("^" + std::to_string(i), Id);
TImageCache::instance()->remap("icon:" + Id,
"^icon:" + std::to_string(i));
im->renumber(Id, jt->second);
}
} }
if (getType() == PLI_XSHLEVEL) { if (getType() == PLI_XSHLEVEL) {
@ -2178,8 +2187,7 @@ TFilePath TXshSimpleLevel::getExistingHookFile(
} }
assert(h >= 0); assert(h >= 0);
return (h < 0) ? TFilePath() return (h < 0) ? TFilePath() : decodedLevelPath.getParentDir() +
: decodedLevelPath.getParentDir() +
TFilePath(hookFiles[h].toStdWString()); TFilePath(hookFiles[h].toStdWString());
} }