[sword-devel] Crash when getting module type
Troy A. Griffitts
scribe at crosswire.org
Sun Oct 29 14:21:12 EDT 2023
Hi David,
On October 29, 2023 10:52:50 MST, "David "Judah's Shadow" Blue" <yudahsshadow at gmx.com> wrote:
>The next class at play is the library class that also has a private member
>swordLibrary,
>
>sword::SWMgr swordLibrary;
This is the issue. Since you are declaring an instance of SWMgr here, it will get constructed in your library class c-tor with its own set of module and filter, etc. objects. Then in setSwordLibrary you assign that fully constructed local instance to a reference to the instance you newed outside.
SWMgr is a factory object and assigning one factory to another doesn't equate to a clear action. We could set option values from the source to the destination, I suppose, but still that would give you what you want. I would suggest changing this swordLibrary property of your library class to a pointer. Then things should work as you expect.
Hope this helps.
Troy
>
>and a setSwordLibrary(), method,
>
>void Library::setSwordLibrary(sword::SWMgr &library) {
> this->swordLibrary = library;
>}
>
>it also has the method in question getModuleList,
>
>
>std::list< std::string > Library::getModuleList(std::string moduleType) {
> std::string module = "";
> sword::ModMap::iterator libraryIterator;
> std::list<std::string> moduleList;
> std::string selectedType;
> std::string modType;
>
> std::string bible = sword::SWMgr::MODTYPE_BIBLES;
> std::string comentary = sword::SWMgr::MODTYPE_COMMENTARIES;
> std::string devo = sword::SWMgr::MODTYPE_DAILYDEVOS;
> std::string book = sword::SWMgr::MODTYPE_GENBOOKS;
> std::string dict = sword::SWMgr::MODTYPE_LEXDICTS;
>
> if(moduleType == "bible") {
> selectedType = bible;
> }
> else if(moduleType == "commentary") {
> selectedType = comentary;
> }
> else if(moduleType == "devotion") {
> selectedType = devo;
> }
> else if(moduleType == "book") {
> selectedType = book;
> }
> else if(moduleType == "dictionary") {
> selectedType = dict;
> }
> else {
> //We should never get here but you never know.
> module = "Invalid type";
> moduleList.push_back(module);
> return moduleList;
> }
>
> for(libraryIterator = this->swordLibrary.Modules.begin();
> libraryIterator != this->swordLibrary.Modules.end();
> libraryIterator++) {
>
> sword::SWModule *tempMod = libraryIterator->second;
>
> modType = tempMod->getType();
>
> if(modType == selectedType) {
> module = "For ";
> module += tempMod->getDescription();
> module += " select ";
> module += tempMod->getName();
> moduleList.push_front(module);
> module = "";
> }
> }
>
> return moduleList;
>
>}
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
More information about the sword-devel
mailing list