Resolve obvious runtime error revealing more subtle one

pull/998/head
AnyOldName3 9 years ago
parent fbe6dc9704
commit 195dd27780

@ -69,7 +69,8 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
{
// Create a local alias for brevity
namespace bpo = boost::program_options;
typedef std::vector<Files::EscapeHashString> StringsVector;
typedef std::vector<Files::EscapeHashString> EscapeStringsVector;
typedef std::vector<std::string> StringsVector;
bpo::options_description desc("Syntax: openmw <options>\nAllowed options");
@ -82,7 +83,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
("data-local", bpo::value<Files::EscapeHashString>()->default_value(""),
"set local data directory (highest priority)")
("fallback-archive", bpo::value<StringsVector>()->default_value(StringsVector(), "fallback-archive")
("fallback-archive", bpo::value<EscapeStringsVector>()->default_value(EscapeStringsVector(), "fallback-archive")
->multitoken(), "set fallback BSA archives (later archives have higher priority)")
("resources", bpo::value<Files::EscapeHashString>()->default_value("resources"),
@ -91,7 +92,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
("start", bpo::value<Files::EscapeHashString>()->default_value(""),
"set initial cell")
("content", bpo::value<StringsVector>()->default_value(StringsVector(), "")
("content", bpo::value<EscapeStringsVector>()->default_value(EscapeStringsVector(), "")
->multitoken(), "content file(s): esm/esp, or omwgame/omwaddon")
("no-sound", bpo::value<bool>()->implicit_value(true)
@ -119,7 +120,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
"\t1 - show warning but consider script as correctly compiled anyway\n"
"\t2 - treat warnings as errors")
("script-blacklist", bpo::value<StringsVector>()->default_value(StringsVector(), "")
("script-blacklist", bpo::value<EscapeStringsVector>()->default_value(EscapeStringsVector(), "")
->multitoken(), "ignore the specified script (if the use of the blacklist is enabled)")
("script-blacklist-use", bpo::value<bool>()->implicit_value(true)
@ -173,20 +174,20 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
{
cfgMgr.readConfiguration(variables, desc, true);
Version::Version v = Version::getOpenmwVersion(variables["resources"].as<std::string>());
Version::Version v = Version::getOpenmwVersion(variables["resources"].as<Files::EscapeHashString>().toStdString());
std::cout << v.describe() << std::endl;
return false;
}
cfgMgr.readConfiguration(variables, desc);
Version::Version v = Version::getOpenmwVersion(variables["resources"].as<std::string>());
Version::Version v = Version::getOpenmwVersion(variables["resources"].as<Files::EscapeHashString>().toStdString());
std::cout << v.describe() << std::endl;
engine.setGrabMouse(!variables.count("no-grab"));
// Font encoding settings
std::string encoding(variables["encoding"].as<std::string>());
std::string encoding(variables["encoding"].as<Files::EscapeHashString>().toStdString());
std::cout << ToUTF8::encodingUsingMessage(encoding) << std::endl;
engine.setEncoding(ToUTF8::calculateEncoding(encoding));
@ -195,7 +196,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
Files::PathContainer dataDirs(variables["data"].as<Files::PathContainer>());
std::string local(variables["data-local"].as<std::string>());
std::string local(variables["data-local"].as<Files::EscapeHashString>().toStdString());
if (!local.empty())
{
dataDirs.push_back(Files::PathContainer::value_type(local));
@ -206,15 +207,15 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
engine.setDataDirs(dataDirs);
// fallback archives
StringsVector archives = variables["fallback-archive"].as<StringsVector>();
StringsVector archives = Files::EscapeHashString::toStdStringVector(variables["fallback-archive"].as<EscapeStringsVector>());
for (StringsVector::const_iterator it = archives.begin(); it != archives.end(); ++it)
{
engine.addArchive(*it);
}
engine.setResourceDir(variables["resources"].as<std::string>());
engine.setResourceDir(variables["resources"].as<Files::EscapeHashString>().toStdString());
StringsVector content = variables["content"].as<StringsVector>();
StringsVector content = Files::EscapeHashString::toStdStringVector(variables["content"].as<EscapeStringsVector>());
if (content.empty())
{
std::cout << "No content file given (esm/esp, nor omwgame/omwaddon). Aborting..." << std::endl;
@ -229,7 +230,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
}
// startup-settings
engine.setCell(variables["start"].as<std::string>());
engine.setCell(variables["start"].as<Files::EscapeHashString>().toStdString());
engine.setSkipMenu (variables["skip-menu"].as<bool>(), variables["new-game"].as<bool>());
if (!variables["skip-menu"].as<bool>() && variables["new-game"].as<bool>())
std::cerr << "new-game used without skip-menu -> ignoring it" << std::endl;
@ -239,11 +240,11 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
engine.setCompileAllDialogue(variables["script-all-dialogue"].as<bool>());
engine.setScriptsVerbosity(variables["script-verbose"].as<bool>());
engine.setScriptConsoleMode (variables["script-console"].as<bool>());
engine.setStartupScript (variables["script-run"].as<std::string>());
engine.setStartupScript (variables["script-run"].as<Files::EscapeHashString>().toStdString());
engine.setWarningsMode (variables["script-warn"].as<int>());
engine.setScriptBlacklist (Files::EscapeHashString::toStdStringVector(variables["script-blacklist"].as<StringsVector>()));
engine.setScriptBlacklist (Files::EscapeHashString::toStdStringVector(variables["script-blacklist"].as<EscapeStringsVector>()));
engine.setScriptBlacklistUse (variables["script-blacklist-use"].as<bool>());
engine.setSaveGameFile (variables["load-savegame"].as<std::string>());
engine.setSaveGameFile (variables["load-savegame"].as<Files::EscapeHashString>().toStdString());
// other settings
engine.setSoundUsage(!variables["no-sound"].as<bool>());

@ -67,9 +67,14 @@ namespace Fallback
namespace Files {
void validate(boost::any &v, const std::vector<std::string> &tokens, Files::EscapeHashString * eHS, int a)
{
std::string * temp = eHS->toStdStringPtr();
boost::program_options::validate(v, tokens, temp, a);
delete temp;
if (eHS == NULL)
boost::program_options::validate(v, tokens, (std::string *) NULL, a);
else
{
std::string * temp = eHS->toStdStringPtr();
boost::program_options::validate(v, tokens, temp, a);
delete temp;
}
}
}

@ -251,44 +251,43 @@ std::vector<std::string> EscapeHashString::toStdStringVector(const std::vector<E
return temp;
}
EscapeHashString::EscapeHashString()
EscapeHashString::EscapeHashString() : mData()
{
}
EscapeHashString::EscapeHashString(const std::string & str) : std::string(EscapeHashString::processString(str))
EscapeHashString::EscapeHashString(const std::string & str) : mData(EscapeHashString::processString(str))
{
}
EscapeHashString::EscapeHashString(const std::string & str, size_t pos, size_t len) : std::string(EscapeHashString::processString(str), pos, len)
EscapeHashString::EscapeHashString(const std::string & str, size_t pos, size_t len) : mData(EscapeHashString::processString(str), pos, len)
{
}
EscapeHashString::EscapeHashString(const char * s) : std::string(EscapeHashString::processString(std::string(s)))
EscapeHashString::EscapeHashString(const char * s) : mData(EscapeHashString::processString(std::string(s)))
{
}
EscapeHashString::EscapeHashString(const char * s, size_t n) : std::string(EscapeHashString::processString(std::string(s)), 0, n)
EscapeHashString::EscapeHashString(const char * s, size_t n) : mData(EscapeHashString::processString(std::string(s)), 0, n)
{
}
EscapeHashString::EscapeHashString(size_t n, char c) : std::string(n, c)
EscapeHashString::EscapeHashString(size_t n, char c) : mData(n, c)
{
}
template <class InputIterator>
EscapeHashString::EscapeHashString(InputIterator first, InputIterator last) : std::string(EscapeHashString::processString(std::string(first, last)))
EscapeHashString::EscapeHashString(InputIterator first, InputIterator last) : mData(EscapeHashString::processString(std::string(first, last)))
{
}
std::string EscapeHashString::toStdString() const
{
return std::string(* this);
return std::string(mData);
}
std::string * EscapeHashString::toStdStringPtr() const
{
std::string * ret = new std::string(*this);
return ret;
return new std::string(mData);
}
const boost::filesystem::path& ConfigurationManager::getGlobalPath() const

@ -93,6 +93,8 @@ struct escape_hash_filter : public boost::iostreams::input_filter
*/
class EscapeHashString : public std::string
{
private:
std::string mData;
public:
static std::string processString(const std::string & str);
static std::vector<std::string> toStdStringVector(const std::vector<EscapeHashString> & vec);

Loading…
Cancel
Save