Re: Crash when getting module type
"Donna Whisnant" <[email protected]>
| Newsgroups | gmane.comp.literature.sword.devel |
|---|---|
| Message-ID | <[email protected]> |
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.
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.
Donna
> Date: Tue, 24 Oct 2023 16:04:03 -0400
> From: "David \"Judah's Shadow\" Blue"
> Subject: [sword-devel] Crash when getting module type
> Message-ID: <5986010.lOV4Wx5bFT@brooks>
> Content-Type: text/plain; charset="us-ascii"
>
> I've resumed working on bibish some, and I'm getting a weird crash I never had
> before. I'm trying to interate through the list of installed modules and
> select those that match a given type. This is my code:
>
>
> for(libraryIterator = swordLibrary.Modules.begin();
> libraryIterator != 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 = "";
> }
> }
>
> I am getting a segfault on the modType = tempMod->getType(); line. I'm
> using
> 1.9.0 built myself. I'm not sure what I'm doing wrong.
_______________________________________________
sword-devel mailing list: [email protected]
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page