Plugin problem - error adding callbacker in uidialog to select seismic

51 views
Skip to first unread message

Paul Maguire

unread,
Feb 6, 2017, 7:22:59 PM2/6/17
to OpendTect Developers


I wonder if anyone can help me with my code. I'm trying to write a simple plugin dialog box that allows the user to select multiple horizons and a seismic volume. Everything was working fine until I tried to attach a callbacker function "inpSel" to inpfld_, with the following lines of code:

const CallBack inpcb( mCB(this,uiMyPluginDlg,inpSel) );
inpfld_->selectionDone.notify( inpcb );

From looking at uiTut and other Opendtect code, this seems to be the correct approach. Yet, for some reason, this triggers an error when running: "Access violation reading location". 

Does anyone have any ideas what I'm doing wrong? Below is my code for the dialog constructor. I've highlighted the offending line in red.


uiMyPluginDlg::uiMyPluginDlg( uiParent* p )  

: uiDialog(p,Setup("MyPlugin control dialog","Select horizons",
mNoHelpKey))
{
// Dialog items for selecting horizons
horlist_ = new uiListBox(this,"List of control horizons", OD::ChooseZeroOrMore);
horlist_->setFieldWidth(18);

addbutton_ = new uiPushButton( this, uiStrings::sAdd(),
   mCB(this,uiMyPluginDlg,addHorizon), false );
addbutton_->attach( rightOf, horlist_ );

removebutton_ = new uiPushButton( this, "Remove",
   mCB(this,uiMyPluginDlg,removeHorizon), false );
    removebutton_->attach( alignedBelow, addbutton_ );
    removebutton_->setSensitive( false );


// Dialog items for selecting seismic volume
const CallBack inpcb( mCB(this,uiMyPluginDlg,inpSel) );

inpfld_ = new uiSeisSel( this, uiSeisSel::ioContext(Seis::Vol,true),
uiSeisSel::Setup(Seis::Vol) );
inpfld_->selectionDone.notify( inpcb );

inpfld_->attach(alignedBelow,horlist_);
 
    subselfld_ = uiSeisSubSel::get( this, Seis::SelSetup(Seis::Vol) );
subselfld_->attachObj()->attach( alignedBelow, inpfld_ );
}

The class is declared in my header file as follows:-

class uiMyPluginDlg : public uiDialog
mODTextTranslationClass(uiMyPluginDlg);

public:
uiMyPluginDlg( uiParent* );
~uiMyPluginDlg();

protected:

// Horizon selection
uiListBox* horlist_;
uiPushButton* addbutton_;
uiPushButton* removebutton_;
TypeSet<MultiID> horizonlist_;

// Seismic selection
uiSeisSel* inpfld_;
    uiSeisSubSel* subselfld_;
    

void addHorizon(CallBacker*);
void removeHorizon( CallBacker* );
void addHorizonTableEntry(const IOObj& ioobj, bool isfault, char side);
void inpSel(CallBacker*);
bool acceptOK( CallBacker* );
};

Is it perhaps to do with the fact that I have not used mExpClass() in the declaration? (I struggled to understand how this macro works, so I simply omitted it...! It hasn't caused a problem... yet.)

Bert Bril

unread,
Feb 6, 2017, 7:39:01 PM2/6/17
to devel...@opendtect.org
Hi Paul,


> const CallBack inpcb( mCB(this,uiMyPluginDlg,inpSel) );
> inpfld_->selectionDone.notify( inpcb );

Looks good.


> From looking at uiTut and other Opendtect code, this seems to be the
> correct approach. Yet, for some reason, this triggers an error when
> running: "Access violation reading location".

This may not be directly related. Do you have a call stack?


Code looks OK to me, just a remark:

> subselfld_->attachObj()->attach( alignedBelow, inpfld_ );

subselfld_->attach( alignedBelow, inpfld_ ) will do too - there is a
special attach() in uiGroup so you don't have to think about whether
something is a uiGroup or a uiObject.


> Is it perhaps to do with the fact that I have not used mExpClass() in
> the declaration? (I struggled to understand how this macro works, so I
> simply omitted it...! It hasn't caused a problem... yet.)

The mExpClass() stuff is only there because M$ Windows needs it when you
want to use the class outside of the DLL you are making. In this case,
even on Windows there is no problem as you are (probably) not using this
class from other plugins.

In short, I do not see a problem just looking at this code. Maybe the
inpSel() itself does something bad?


All in all, a call stack may be helpful. In Visual Studio or an IDE it's
in one of these subwindows on the bottom, on linux command line just do
'where' in gdb.


/Bert

--

Bert Bril
Coach/Consultant Software Development
_________________________________________________

dGB Earth Sciences

Phone: +31 53 4315155
E-mail: bert...@dgbes.com
Internet: http://dgbes.com & http://opendtect.org

<<SEG Distinguished Achievement Award 2016>>
_________________________________________________

Paul Maguire

unread,
Feb 7, 2017, 10:51:44 AM2/7/17
to OpendTect Developers
Hi Bert, 

Thanks for the  swift response. Here's the call stack, which I think is telling me that .selectionDone.notify (line 32 in uiMyPluginDlg) is causing the violation. Any idea what's going on here?

> Basic.dll!Threads::Lock::isSpinLock()  Line 68 + 0x23 bytes C++
  Basic.dll!Threads::Locker::reLock(Threads::Locker::WaitType wt)  Line 113 + 0xe bytes C++
  Basic.dll!Threads::Locker::Locker(Threads::Lock & lck)  Line 84 + 0x5e bytes C++
  Basic.dll!NotifierAccess::notify(const CallBack & cb, bool first)  Line 512 + 0x1a bytes C++
  uiMyPlugin.dll!uiMyPluginDlg::uiMyPluginDlg(uiParent * p)  Line 32 C++
  uiMyPlugin.dll!uiMyPluginMgr::dispMyPluginDlg(CallBacker * __formal)  Line 115 + 0x16 bytes C++
  Basic.dll!CallBack::doCall(CallBacker * cber)  Line 299 + 0x21 bytes C++
  Basic.dll!CallBackSet::doCall(CallBacker * obj, CallBacker * exclude)  Line 399 C++
  Basic.dll!NotifierAccess::doTrigger(CallBackSet & cbs, CallBacker * c, CallBacker * exclude)  Line 565 C++
  uiBase.dll!Notifier<uiAction>::trigger(CallBacker * c, CallBacker * exclude)  Line 264 + 0x63 bytes C++
  uiBase.dll!uiAction::trigger(bool checked)  Line 257 C++
  uiBase.dll!i_ActionMessenger::triggered(bool checked)  Line 59 C++
  uiBase.dll!i_ActionMessenger::qt_static_metacall(QObject * _o, QMetaObject::Call _c, int _id, void * * _a)  Line 52 + 0x1f bytes C++


Regards
Paul




Bert Bril

unread,
Feb 7, 2017, 11:00:22 AM2/7/17
to devel...@opendtect.org
Hi Paul,


>>Basic.dll!Threads::Lock::isSpinLock() Line 68 + 0x23 bytesC++
> Basic.dll!Threads::Locker::reLock(Threads::Locker::WaitType wt) Line
> 113 + 0xe bytesC++
> Basic.dll!Threads::Locker::Locker(Threads::Lock & lck) Line 84 + 0x5e
> bytesC++
> Basic.dll!NotifierAccess::notify(const CallBack & cb, bool first) Line
> 512 + 0x1a bytesC++

Hmmm can't say that rings a bell.

Can you try replacing:

const CallBack inpcb( mCB(this,uiMyPluginDlg,inpSel) );
inpfld_->selectionDone.notify( inpcb );

with this (this is what I do in new code):

mAttachCB( inpfld_->selectionDone, uiMyPluginDlg::inpSel );


Does that make any difference at compile or runtime?

Paul Maguire

unread,
Feb 7, 2017, 11:58:27 AM2/7/17
to OpendTect Developers
Hi Bert,

Incidentally, here is how the class is used. I create a menu item that uses the following callback function.

void uiMyPluginMgr::dispMyPluginDlg( CallBacker* )
{
    uiMyPluginDlg dlg( &appl );
dlg.go();
}

 Am I perhaps creating an instance of the class incorrectly? (Just trying to think of potential novice errors.)

Regards
Paul

Paul Maguire

unread,
Feb 7, 2017, 11:58:27 AM2/7/17
to OpendTect Developers
Hi Bert,

> mAttachCB( inpfld_->selectionDone, uiMyPluginDlg::inpSel ); 

Thanks for the suggestion. Unfortunately it triggers just the same error:

> Basic.dll!Threads::Lock::isSpinLock()  Line 68 + 0x23 bytes C++
  Basic.dll!Threads::Locker::reLock(Threads::Locker::WaitType wt)  Line 113 + 0xe bytes C++
  Basic.dll!Threads::Locker::Locker(Threads::Lock & lck)  Line 84 + 0x5e bytes C++
  Basic.dll!NotifierAccess::notify(const CallBack & cb, bool first)  Line 512 + 0x1a bytes C++
  Basic.dll!CallBacker::attachCB(NotifierAccess & notif, const CallBack & cb, bool onlyifnew)  Line 212 C++

Regards
Paul

Bert Bril

unread,
Feb 7, 2017, 12:38:24 PM2/7/17
to devel...@opendtect.org
Paul,


I see nothing fishy. I'm starting to think about some kind of mismatch
between the release's DLL's and the plugin DLL, maybe Visual Studio
versions, compiler flags, ...

Maybe something Windows-specific in general. Which is not really my
thing. Anyone else (maybe you, Ranojay)?

Nanne Hemstra

unread,
Feb 7, 2017, 12:48:01 PM2/7/17
to developers
Hi Paul,

I've seen mysterious errors when mixing up release and debug dlls. If you build your plugin in Debug mode and load it in the release version of OpendTect, it will most certainly crash when there's a CallBacker involved.

Best regards,
Nanne




--
You received this message because you are subscribed to the Google Groups "OpendTect Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+unsubscribe@opendtect.org.
To post to this group, send email to devel...@opendtect.org.
Visit this group at https://groups.google.com/a/opendtect.org/group/developers/.
To view this discussion on the web visit https://groups.google.com/a/opendtect.org/d/msgid/developers/701c39f6-c695-4141-8511-50411b921445%40opendtect.org.



--
Nanne Hemstra
Executive Vice President - Americas
____________________________

dGB Earth Sciences
Phone:+1 281 240 3939
Skype:dgbnanne
E-mail:nanne....@dgbes.com
Internet:dgbes.com & opendtect.org

 SEG Distinguished Achievement Award 2016
____________________________

Paul Maguire

unread,
Feb 7, 2017, 3:28:51 PM2/7/17
to OpendTect Developers
Hi Nanne,

I think you may be onto something there. I am compiling od_main and my plugin in debug/x64. But interestingly, if I compile my plugin as release/x64, then try to install into my normal Opendtect installation, it crashes straight away upon installing.

I am running Opendtect V6.0.2/win64, and building my plugin with the following:-


For what it's worth, My CMakeLists.txt file for uiMyPlugin looks like this:-


SET(OD_MODULE_DEPS uiODMain MyPlugin)

SET(OD_IS_PLUGIN yes)

SET(OD_MODULE_SOURCES

uiMypluginpi.cc)

SET( OD_NO_ALO_ENTRY 1 )

OD_INIT_MODULE()


Regards

Paul

Ranojay

unread,
Feb 7, 2017, 11:24:20 PM2/7/17
to devel...@opendtect.org

Hi Paul,

I think I now got the problem, its because of using different Visual Studio version (Thanks for sharing the Visual Studio version information).

OpendTect 6.0 is built with Visual Studio 2013(version 12), and you will need either Visual Studio 2013 or Visual Studio 2013 Express to build the plugins for OpendTect 6.0. No other versions of Visual Studio could be used, as they are not cross compatible.

You may want to download the express edition of Visual Studio 2013 from official Microsoft website here https://www.microsoft.com/en-in/download/details.aspx?id=44914

Let us know if that helps.

Regards
Ranojay
--
You received this message because you are subscribed to the Google Groups "OpendTect Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@opendtect.org.

To post to this group, send email to devel...@opendtect.org.
Visit this group at https://groups.google.com/a/opendtect.org/group/developers/.

--
Ranojay Sen
Team Leader Windows Development
______________________________

dGB Earth Sciences, India
Phone: +91 22 25704984
E-mail: ranoj...@dgbes.com
Internet: dgbes.com & opendtect.org
______________________________

Paul Maguire

unread,
Feb 8, 2017, 6:57:44 AM2/8/17
to OpendTect Developers
Thanks Ranojay. I'm sure you've solved it. I haven't made a plugin since updating to OpendTect 6.0 so I was unaware of the corresponding change from Visual Studio 2010 to 2013. I'll download it and hopefully that will fix it.

Thanks again
Paul

محمد زين العابدين

unread,
Feb 13, 2017, 8:02:09 AM2/13/17
to devel...@opendtect.org
Reply all
Reply to author
Forward
0 new messages