1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-28 14:39:43 +00:00

Do not use invalid iterators

This commit is contained in:
Andrei Kortunov 2023-07-31 16:29:14 +04:00
parent deba5b4d47
commit b1c8a968ae
8 changed files with 41 additions and 6 deletions

View file

@ -100,6 +100,7 @@ namespace CSMPrefs
{
QWidget* widget = static_cast<QWidget*>(watched);
ShortcutMap::iterator shortcutListIt = mWidgetShortcuts.find(widget);
assert(shortcutListIt != mWidgetShortcuts.end());
// Deactivate in case events are missed
for (ShortcutList::iterator it = shortcutListIt->second.begin(); it != shortcutListIt->second.end(); ++it)

View file

@ -744,7 +744,9 @@ void CSMWorld::RefIdCollection::cloneRecord(
const ESM::RefId& origin, const ESM::RefId& destination, const CSMWorld::UniversalId::Type type)
{
std::unique_ptr<RecordBase> newRecord = mData.getRecord(mData.searchId(origin)).modifiedCopy();
mAdapters.find(type)->second->setId(*newRecord, destination.getRefIdString());
auto adapter = mAdapters.find(type);
assert(adapter != mAdapters.end());
adapter->second->setId(*newRecord, destination.getRefIdString());
mData.insertRecord(std::move(newRecord), type, destination);
}

View file

@ -429,7 +429,9 @@ void CSMWorld::RefIdData::copyTo(int index, RefIdData& target) const
{
LocalIndex localIndex = globalToLocalIndex(index);
RefIdDataContainerBase* source = mRecordContainers.find(localIndex.second)->second;
auto foundIndex = mRecordContainers.find(localIndex.second);
assert(foundIndex != mRecordContainers.end());
RefIdDataContainerBase* source = foundIndex->second;
target.insertRecord(
source->getRecord(localIndex.first).modifiedCopy(), localIndex.second, source->getId(localIndex.first));

View file

@ -129,7 +129,9 @@ CSVWidget::ModeButton* CSVWidget::SceneToolMode::getCurrent()
std::string CSVWidget::SceneToolMode::getCurrentId() const
{
return mButtons.find(mCurrent)->second;
auto currentButton = mButtons.find(mCurrent);
assert(currentButton != mButtons.end());
return currentButton->second;
}
void CSVWidget::SceneToolMode::setButton(const std::string& id)

View file

@ -354,7 +354,16 @@ namespace MWGui
const ESM::Skill* skill = MWBase::Environment::get().getESMStore()->get<ESM::Skill>().search(skillId);
if (!skill) // Skip unknown skills
continue;
const MWMechanics::SkillValue& stat = mSkillValues.find(skill->mId)->second;
auto skillValue = mSkillValues.find(skill->mId);
if (skillValue == mSkillValues.end())
{
Log(Debug::Error) << "Failed to update stats review window: can not find value for skill "
<< skill->mId;
continue;
}
const MWMechanics::SkillValue& stat = skillValue->second;
int base = stat.getBase();
int modified = stat.getModified();

View file

@ -151,7 +151,10 @@ namespace MWGui
MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player);
MWMechanics::Spells& spells = stats.getSpells();
spells.add(mSpellsWidgetMap.find(_sender)->second);
auto spell = mSpellsWidgetMap.find(_sender);
assert(spell != mSpellsWidgetMap.end());
spells.add(spell->second);
player.getClass().getContainerStore(player).remove(MWWorld::ContainerStore::sGoldId, price);
// add gold to NPC trading gold pool

View file

@ -10,6 +10,8 @@
#include <MyGUI_TextIterator.h>
#include <MyGUI_Window.h>
#include <components/debug/debuglog.hpp>
#include <components/esm3/loadbsgn.hpp>
#include <components/esm3/loadclas.hpp>
#include <components/esm3/loadfact.hpp>
@ -496,6 +498,13 @@ namespace MWGui
if (!skill) // Skip unknown skills
continue;
auto skillValue = mSkillValues.find(skill->mId);
if (skillValue == mSkillValues.end())
{
Log(Debug::Error) << "Failed to update stats window: can not find value for skill " << skill->mId;
continue;
}
const ESM::Attribute* attr = esmStore.get<ESM::Attribute>().find(skill->mData.mAttribute);
std::pair<MyGUI::TextBox*, MyGUI::TextBox*> widgets
@ -516,7 +525,7 @@ namespace MWGui
mSkillWidgets[mSkillWidgets.size() - 1 - i]->setUserString("Range_SkillProgress", "100");
}
setValue(skill->mId, mSkillValues.find(skill->mId)->second);
setValue(skill->mId, skillValue->second);
}
}

View file

@ -1,6 +1,7 @@
#include "shadermanager.hpp"
#include <algorithm>
#include <cassert>
#include <chrono>
#include <components/debug/debuglog.hpp>
#include <components/files/conversion.hpp>
@ -472,9 +473,15 @@ namespace Shader
{
ShaderManager::ShaderMap::iterator shaderIt
= Manager.mShaders.find(std::make_pair(templateName, shaderDefines));
if (shaderIt == Manager.mShaders.end())
{
Log(Debug::Error) << "Failed to find shader " << templateName;
continue;
}
ShaderManager::TemplateMap::iterator templateIt = Manager.mShaderTemplates.find(
templateName); // Can't be Null, if we're here it means the template was added
assert(templateIt != Manager.mShaderTemplates.end());
std::string& shaderSource = templateIt->second;
std::set<std::filesystem::path> insertedPaths;
std::filesystem::path path = (std::filesystem::path(Manager.mPath) / templateName);