Re: Crash when getting module type

"Troy A. Griffitts" <[email protected]>
Newsgroups gmane.comp.literature.sword.devel
Message-ID <[email protected]>
Hi David. There shouldn't be any nulls in the SWMgr::Modules map. Have you done anything with the map which might have created an entry?  For example, have you attempted to obtain a module by name which wasn't there? In C++ this would create an empty entry with a null pointer if the KJV wasn't installed.

SWModule *kjv = swordLibrary->Modules["KJV"];

Just trying to guess what might have happened.


On October 26, 2023 10:59:34 MST, "David "Judah's Shadow" Blue" <[email protected]> wrote:
>On Wednesday, October 25, 2023 6:22:54 PM EDT Donna Whisnant wrote:
>> David,
>>
>> Based on the code you are showing, I can pretty much guarantee you that your
>> segfault is caused by tempMod being a null pointer -- i.e. that the value
>> of the map element you are iterating is null.
>
>Ok, I didn't know that there could be null elements in the map.
>
>> Your code needs to be more defensive and check if tempMod is a nullptr
>> before dereferencing it.  Adding an 'if' around that code block should fix
>> your segfault problem.
>
>
>
>> But you'll have to determine why some module
>> entries in your map are nulls -- perhaps you missed loading modules or
>> something? Your code snippet doesn't show any of those details...  it only
>> shows iterating something that appears to be a std::map.
>
>Do you have to do something to load modules? When my program initializes, I do
>this
>
>swordLibrary = new sword::SWMgr(new sword::MarkupFilterMgr(sword::FMT_PLAIN));
>and then pass a pointer to that around my various classes.
>
>In this particular function,  the iterator is this,
>
>sword::ModMap::iterator libraryIterator;
>
>I had thought I was following one of the examples.

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

_______________________________________________
sword-devel mailing list: [email protected]
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.