[sword-devel] VerseKey semantics
Troy A. Griffitts
scribe at crosswire.org
Mon Dec 8 04:23:57 MST 2014
You can reference a module's internal key directly and use that
reference to position a module just fine, but you shouldn't hold on to
the reference. A subsequent call to a module's setKey method will often
invalidate any previous reference to the module's internal key.
If you'd like to use a module's internal key instead of creating your
own, if possible gain the reference each time with mod->getKey() (or as
you have done with the (SWKey *) cast operator). Or else be careful not
to call mod->setKey, but I would not recommend the latter.
On 12/07/2014 06:27 PM, Karl Kleinpaste wrote:
> I asked Troy about this in IRC a bit yesterday, but I ran into
> problems today and I'm in need of clues.
>
> In the av11n world, I've had to convert all VerseKey initialization to
> be v11n-sensitive. Mostly, I'd prefer just to use a module's own key
> directly:
>
> VerseKey *k = (VerseKey *)(SWKey *)(*mod);
>
> The problem I've got is that there are a number of instances where
> subsequent operations on k cause crashes or give exciting results.
> For one, when trying to fill a navbar book selector, the 2nd call to
> k->setTestament(1) (populating OT books) segfaults. Note, not the 1st
> call, rather it's the 2nd, every time. It's become necessary to
> create the key the other way:
>
> VerseKey *k = (VerseKey *)mod->createKey();
>
> and then calls to k->setTestament(1) work just fine. Of course I have
> to remember to
> delete k;
> which is mildly annoying to have to do, and wasn't necessary when
> using the module's own key.
>
> Can anyone offer reasoning why the VerseKey from the module would have
> trouble with this sort of use, and why an independently-created key
> from the same module works fine?
>
>
> _______________________________________________
> sword-devel mailing list: sword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above page
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.crosswire.org/pipermail/sword-devel/attachments/20141208/47b0dec6/attachment.html>
More information about the sword-devel
mailing list