From 53c03b65cf94588bb6a809cdd5df77ef1d1c2135 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Mon, 17 Oct 2022 09:37:56 +0200 Subject: [PATCH] Prevent potentially returning garbage flags --- apps/openmw/mwbase/dialoguemanager.hpp | 2 +- apps/openmw/mwdialogue/dialoguemanagerimp.cpp | 7 +++++-- apps/openmw/mwdialogue/dialoguemanagerimp.hpp | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwbase/dialoguemanager.hpp b/apps/openmw/mwbase/dialoguemanager.hpp index 94543ed955..2e58403248 100644 --- a/apps/openmw/mwbase/dialoguemanager.hpp +++ b/apps/openmw/mwbase/dialoguemanager.hpp @@ -90,7 +90,7 @@ namespace MWBase }; virtual std::list getAvailableTopics() = 0; - virtual int getTopicFlag(const std::string&) = 0; + virtual int getTopicFlag(const std::string&) const = 0; virtual bool checkServiceRefused (ResponseCallback* callback, ServiceType service = ServiceType::Any) = 0; diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index 1e4f8b0c5e..d06fbbfd40 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -422,9 +422,12 @@ namespace MWDialogue return keywordList; } - int DialogueManager::getTopicFlag(const std::string& topicId) + int DialogueManager::getTopicFlag(const std::string& topicId) const { - return mActorKnownTopics[topicId].mFlags; + auto known = mActorKnownTopics.find(topicId); + if (known != mActorKnownTopics.end()) + return known->second.mFlags; + return 0; } void DialogueManager::keywordSelected (const std::string& keyword, ResponseCallback* callback) diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp index 5d0c5279d2..e611e52315 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp @@ -83,7 +83,7 @@ namespace MWDialogue bool startDialogue (const MWWorld::Ptr& actor, ResponseCallback* callback) override; std::list getAvailableTopics() override; - int getTopicFlag(const std::string& topicId) override; + int getTopicFlag(const std::string& topicId) const override; bool inJournal (const std::string& topicId, const std::string& infoId) override;