[sword-devel] Crash when getting module type

David "Judah's Shadow" Blue yudahsshadow at gmx.com
Mon Oct 30 09:23:27 EDT 2023


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"
<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.

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.
-------------- 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/20231030/d19199bd/attachment-0001.sig>


More information about the sword-devel mailing list