Re: [sword-devel] Crash when getting module type

2023-10-31 Thread David "Judah's Shadow" Blue
Found my issue. I had a locally scoped library object that had it's own 
uninitalized swordLibrary that was taking precidence 臘, now I'm getting no 
crashes. I have other issues but that's for another email.



___
sword-devel mailing list: sword-devel@crosswire.org
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page


Re: [sword-devel] Crash when getting module type

2023-10-30 Thread David "Judah's Shadow" Blue
On Sunday, October 29, 2023 2:21:12 PM EDT Troy A. Griffitts wrote:
> Hi David,
>
> On October 29, 2023 10:52:50 MST, "David "Judah's Shadow" Blue"
 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.

That all makes senese. I've changed it to be a pointer in my interface class,
so now it've got, my initialize 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;
}

And in my Library class, I've got a private member

sword::SWMgr *swordLibrary;

void Library::setSwordLibrary(sword::SWMgr *library) {
this->swordLibrary = library;
}

But I'm still getting a crash in the same spot once I try to get a module
type, so I'm sure I've done something else wrong but am not sure what.


signature.asc
Description: This is a digitally signed message part.
___
sword-devel mailing list: sword-devel@crosswire.org
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page


Re: [sword-devel] Crash when getting module type

2023-10-29 Thread Troy A. Griffitts
Important typo:

- We could set option values from the source to the destination, I suppose, but 
still that would give you what you want.
+ We could set option values from the source to the destination, I suppose, but 
still that WOULDN'T give you what you want.

On October 29, 2023 11:21:12 MST, "Troy A. Griffitts"  
wrote:
>Hi David,
>
>On October 29, 2023 10:52:50 MST, "David "Judah's Shadow" Blue" 
> 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 ) {
>>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 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.
>___
>sword-devel mailing list: sword-devel@crosswire.org
>http://crosswire.org/mailman/listinfo/sword-devel
>Instructions to unsubscribe/change your settings at above page

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.___
sword-devel mailing list: sword-devel@crosswire.org
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page


Re: [sword-devel] Crash when getting module type

2023-10-29 Thread Troy A. Griffitts
Hi David,

On October 29, 2023 10:52:50 MST, "David "Judah's Shadow" Blue" 
 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 ) {
>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 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.
___
sword-devel mailing list: sword-devel@crosswire.org
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page


Re: [sword-devel] Crash when getting module type

2023-10-29 Thread David "Judah's Shadow" Blue
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 ) {
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 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;

}


signature.asc
Description: This is a digitally signed message part.
___
sword-devel mailing list: sword-devel@crosswire.org
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page


Re: [sword-devel] Crash when getting module type

2023-10-27 Thread Troy A. Griffitts

On 10/27/23 09:33, David "Judah's Shadow" Blue wrote:

On Friday, October 27, 2023 8:46:19 AM EDT Troy A. Griffitts wrote:

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.

No, I'm declaring the SWModule *tempMod and then the very next thing is
assigning it to libraryIterator->second.


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.


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.


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.



libraryIterator is a sword::ModMap::iterator if that makes a difference.

While stepping through in my debugger, after I assign tempMod to
libraryIterator->second looking at the variables, I am getting values in
tempMod that indicate something is wrong (I can provide those if that would
help)

Ultimately, I want to build a list of strings of the form "For [module
description/long name select [module shortname] for all installed modules of a
given type. Perhaps there is a better way to do that?

___
sword-devel mailing list: sword-devel@crosswire.org
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page

___
sword-devel mailing list: sword-devel@crosswire.org
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page


Re: [sword-devel] Crash when getting module type

2023-10-27 Thread David "Judah's Shadow" Blue
On Friday, October 27, 2023 8:46:19 AM EDT Troy A. Griffitts wrote:
> 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.

No, I'm declaring the SWModule *tempMod and then the very next thing is
assigning it to libraryIterator->second.

libraryIterator is a sword::ModMap::iterator if that makes a difference.

While stepping through in my debugger, after I assign tempMod to
libraryIterator->second looking at the variables, I am getting values in
tempMod that indicate something is wrong (I can provide those if that would
help)

Ultimately, I want to build a list of strings of the form "For [module
description/long name select [module shortname] for all installed modules of a
given type. Perhaps there is a better way to do that?


signature.asc
Description: This is a digitally signed message part.
___
sword-devel mailing list: sword-devel@crosswire.org
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page


Re: [sword-devel] Crash when getting module type

2023-10-27 Thread Troy A. Griffitts
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" 
 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: sword-devel@crosswire.org
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page


Re: [sword-devel] Crash when getting module type

2023-10-26 Thread David "Judah's Shadow" Blue
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.


signature.asc
Description: This is a digitally signed message part.
___
sword-devel mailing list: sword-devel@crosswire.org
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page


Re: [sword-devel] Crash when getting module type

2023-10-25 Thread Donna Whisnant
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: sword-devel@crosswire.org
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page