[sword-devel] Crash when getting module type
David "Judah's Shadow" Blue
yudahsshadow at gmx.com
Sun Oct 29 13:52:50 EDT 2023
On Friday, October 27, 2023 1:25:44 PM EDT Troy A. Griffitts wrote:
> I don't believe the issue is between when you declare the tempMod
> variable and when you assign it.
>
> I believe the issue is between when you construct SWMgr() and when you
> get to your code block. Somebody has done something strange with SWMgr
> before you get to your code block.
That is possible, I do pass the pointer to my SWMgr around a bit.
> If you give more context, I can have a look. Another thing you can try
> is to simply to create 'swordLibrary' just before your `for` loop block
> to be sure nothing has gone wrong someplace else.
Creating a new instance of SWMgr works as expected, so something is happening
between.
> But to help you debug, I'd need to see a block of code that doesn't work
> which also contains your construction of 'swordLibrary' and everything
> between that construction and the `for` loop you've posted.
>
Ok. Let me see what I can do.
First, I have a couple of classes at play. The interface class which houses
the initial swordLibrary declared as a Private member
sword::SWMgr *swordLibrary;
I instantiate the library in the initialize (non-constructor) method.
void Interface::initalize() {
configScreen();
std::cout << "Initializing SWORD, please wait..." << std::endl;
this->swordLibrary = new sword::SWMgr(new
sword::MarkupFilterMgr(sword::FMT_PLAIN));
library.setSwordLibrary(*swordLibrary);
library.passage.setLibrary(*swordLibrary);
library.lexicon.setSwordLibrary(*swordLibrary);
std::cout << "Initialized, proceeding to shell..." << std::endl;
}
Then, things pass off to my various methods that run the interface, but don't
touch the sword library (or at least shouldn't)
The next class at play is the library class that also has a private member
swordLibrary,
sword::SWMgr swordLibrary;
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://crosswire.org/pipermail/sword-devel/attachments/20231029/67b05234/attachment.sig>
More information about the sword-devel
mailing list