Hi all
I still couldn't find a solution to my problem, so I will describe the problem more detailed.
wxVersion: 2-9-3, wxmsw
compiler: mingw gcc 4.4.0
Now let me explain with some code. Below you can see a part of a function which decide if the plot (which causes the crash when it will be closed) is
used or not! I inserted some logging functions and at this position, it's something strange, but I'm not sure if I'm doing everything right!
The function call:
mlp_->setMemFuncPointShowPlot((void*) this, &NnetGUIBase::Wrapper_To_Call_showPerfPlot);
uses function pointers. So for the logging, I tried to determine the address of the pointers.
Can I do it on this way for the "this" pointer?
I get the same address as for the
)&NnetGUIBase::Wrapper_To_Call_showPerfPlot;
function pointer! See the
part from the logging after the code snippet!
Code: Select all
if (this->enablePerfPlot_->GetValue()){
//
// now define the function pointer to pass
// to the ai::nnet::mlp library.
// The first argument '(void*) this'
//
Logging *loger = new Logging();
int adr = (int)(void*)this;
char buf[33];
itoa(adr, buf, 10);
loger->log("the address of the this pointer is:");
loger->log(buf);
int adr2 = (int)&NnetGUIBase::Wrapper_To_Call_showPerfPlot;
char buf2[33];
itoa(adr2, buf2, 10);
loger->log("the address of the NnetGUIBase::Wrapper_To_Call_showPerfPlot pointer is:");
loger->log(buf);
mlp_->setMemFuncPointShowPlot((void*) this, &NnetGUIBase::Wrapper_To_Call_showPerfPlot);
delete loger;
}else
Fri Apr 06 22:54:05 2012 : File: ..\src\nnetGUIBase.cpp: Function: onTrainButton --Line: 1887: the address of the this pointer is:
Fri Apr 06 22:54:05 2012 : File: ..\src\nnetGUIBase.cpp: Function: onTrainButton --Line: 1888: 61051472
Fri Apr 06 22:54:05 2012 : File: ..\src\nnetGUIBase.cpp: Function: onTrainButton --Line: 1893: the address of the NnetGUIBase::Wrapper_To_Call_showPerfPlot pointer is:
Fri Apr 06 22:54:05 2012 : File: ..\src\nnetGUIBase.cpp: Function: onTrainButton --Line: 1894: 61051472
Inside the mlp_ object the function pointer is called and on this way I call the next function
Code: Select all
/*!
* Static wrapper-function to be able to callback the member function showProgPlot
*/
void NnetGUIBase::Wrapper_To_Call_showPerfPlot(void* pt2Object, stl_dVector perf, stl_dVector valiPerf)
{
//
// Explicitly cast to a pointer to NnetGUIBase
//
NnetGUIBase* mySelf = (NnetGUIBase*) pt2Object;
//
// Call member
//
mySelf->showProgPlot(perf, valiPerf);
}//void NnetGUIBase::Wrapper_To_Call_showPerfPlot...
Code: Select all
void NnetGUIBase::showProgPlot(stl_dVector perf, stl_dVector valiPerf)
{
Logging *loger = new Logging();
int adr = (int)&visBasic2D_;
char buf[33];
itoa(adr, buf, 10);
loger->log("the address of the visBasic2D_ pointer is:");
loger->log(buf);
if (!visBasic2D_){ // object exists, check if library is loaded
if (libVisBasic2D_.IsLoaded()){ // returns true if library is loaded
std::cout << "already loaded vis_basic_2D.dll\n";
getVisBasic2DDllObj pGetDllObj = (getVisBasic2DDllObj)libVisBasic2D_.GetSymbol("createVisBasic2D");
visBasic2D_ = (pGetDllObj)();
visBasic2D_->setMemFuncPointResetShowPlot((void*) this, NnetGUIBase::Wrapper_To_Reset_showPlot);
}else{ // load the library
if (libVisBasic2D_.Load("./plugins/vis_basic_2D")){
std::cout << "load vis_basic_2D.dll successfully\n";
getVisBasic2DDllObj pGetDllObj = (getVisBasic2DDllObj)libVisBasic2D_.GetSymbol("createVisBasic2D");
visBasic2D_ = (pGetDllObj)();
visBasic2D_->setMemFuncPointResetShowPlot((void*) this, NnetGUIBase::Wrapper_To_Reset_showPlot);
}else{
///todo throw an exception
loger_->log("Couldn't load the library: vis::basic::2D");
std::cout << "Couldn't load the library: vis::basic::2D\n";
}
}
}else{ // in this case the object should be valid
}// if (!visBasic2D_...
if (visBasic2D_){
if (visBasic2D_->isShown()){
// do nothing
// std::cout << "short before performancePlot\n";
visBasic2D_->performancePlot(perf,valiPerf);
}else{
visBasic2D_->show();
}
}else{
std::cout << "visBasic2D_ seems not to be valid\n";
}// if (visBasic2D_)
delete loger;
}//void NnetGUIBase::showProgPlot(...
Until this position, everything seems to be okay. But if I close now the plot frame, I get the crash, even if it looks to me
that the pointer of the visBasic2D_ object is still the same!
Code: Select all
/*!
* Static wrapper-function to be able to callback the member function resetShowPlot
*/
void NnetGUIBase::Wrapper_To_Reset_showPlot(void* pt2Object)
{
Logging *loger = new Logging();
// explicitly cast to a pointer to NnetGUIBase
NnetGUIBase* mySelf = (NnetGUIBase*) pt2Object;
loger->log("before the resetShowPlot command");
// call member
mySelf->resetShowPlot();
delete loger;
}//void NnetGUIBase::Wrapper_To_Reset_showPlot(void* pt2Object)
Code: Select all
/*!
* Sets the function pointer visBasic2D_ to NULL. This function is used
* inside the Wrapper-Functions to pass data to and from the ai::nne::mlp
* library.
*/
void NnetGUIBase::resetShowPlot()
{
Logging *loger = new Logging();
int adr = (int)&visBasic2D_;
char buf[33];
itoa(adr, buf, 10);
loger->log("the address of the visBasic2D_ pointer is:");
loger->log(buf);
delete visBasic2D_; // muss noch getestet werden !!
loger->log("after delete visBasic2D_");
visBasic2D_ = NULL;
loger->log("after visBasic2D_=NULL");
delete loger;
}//void NnetGUIBase::resetShowPlot()
As everyone can see, the logging part of the visBasic2D_ seems to be ok.
Fri Apr 06 22:54:05 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3118: the address of the visBasic2D_ pointer is:
Fri Apr 06 22:54:05 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3119: 61052036
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3118: the address of the visBasic2D_ pointer is:
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3119: 61052036
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3118: the address of the visBasic2D_ pointer is:
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3119: 61052036
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3118: the address of the visBasic2D_ pointer is:
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3119: 61052036
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3118: the address of the visBasic2D_ pointer is:
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3119: 61052036
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3118: the address of the visBasic2D_ pointer is:
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3119: 61052036
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3118: the address of the visBasic2D_ pointer is:
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3119: 61052036
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3118: the address of the visBasic2D_ pointer is:
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3119: 61052036
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3118: the address of the visBasic2D_ pointer is:
Fri Apr 06 22:54:06 2012 : File: ..\src\nnetGUIBase.cpp: Function: showProgPlot --Line: 3119: 61052036
Fri Apr 06 22:54:07 2012 : File: ..\src\nnetGUIBase.cpp: Function: Wrapper_To_Reset_showPlot --Line: 3230: before the resetShowPlot command
Fri Apr 06 22:54:07 2012 : File: ..\src\nnetGUIBase.cpp: Function: resetShowPlot --Line: 2721: the address of the visBasic2D_ pointer is:
Fri Apr 06 22:54:07 2012 : File: ..\src\nnetGUIBase.cpp: Function: resetShowPlot --Line: 2722: 61052036
Fri Apr 06 22:54:07 2012 : File: ..\src\nnetGUIBase.cpp: Function: resetShowPlot --Line: 2726: after delete visBasic2D_
Fri Apr 06 22:54:07 2012 : File: ..\src\nnetGUIBase.cpp: Function: resetShowPlot --Line: 2728: after visBasic2D_=NULL
At the end, let me show you that the function pointers are correct for reseting the plot frame ...
Fri Apr 06 23:28:47 2012 : File: ..\src\visBasic2D_frame.cpp: Function: setMemFuncPointResetShowPlot --Line: 318: the address of the pointer pt2ObjectResetShowPlot_ is:
Fri Apr 06 23:28:47 2012 : File: ..\src\visBasic2D_frame.cpp: Function: setMemFuncPointResetShowPlot --Line: 319: 61190096
Fri Apr 06 23:28:47 2012 : File: ..\src\visBasic2D_frame.cpp: Function: setMemFuncPointResetShowPlot --Line: 326: the address of the function pointer pMemFuncResetShowPlot_ is:
Fri Apr 06 23:28:47 2012 : File: ..\src\visBasic2D_frame.cpp: Function: setMemFuncPointResetShowPlot --Line: 327: 61190104
Fri Apr 06 23:28:49 2012 : File: ..\src\visBasic2D_frame.cpp: Function: onClose --Line: 203: after Destroy
Fri Apr 06 23:28:49 2012 : File: ..\src\visBasic2D_frame.cpp: Function: onClose --Line: 207: inside if (pMemFuncResetShowPlot_
Fri Apr 06 23:28:49 2012 : File: ..\src\visBasic2D_frame.cpp: Function: onClose --Line: 208: inside if (pt2ObjectResetShowPlot_
Fri Apr 06 23:28:49 2012 : File: ..\src\visBasic2D_frame.cpp: Function: onClose --Line: 210: after pMemFuncResetShowPlot_(pt2ObjectResetShowPlot_)
Fri Apr 06 23:28:49 2012 : File: ..\src\visBasic2D_frame.cpp: Function: onClose --Line: 216: the address of the pointer is:
Fri Apr 06 23:28:49 2012 : File: ..\src\visBasic2D_frame.cpp: Function: onClose --Line: 217: 61190096
Fri Apr 06 23:28:49 2012 : File: ..\src\visBasic2D_frame.cpp: Function: onClose --Line: 222: the address of the function pointer is:
Fri Apr 06 23:28:49 2012 : File: ..\src\visBasic2D_frame.cpp: Function: onClose --Line: 223: 61190104
Fri Apr 06 23:28:49 2012 : File: ..\src\visBasic2D_frame.cpp: Function: onClose --Line: 228: END OF void VisBasic2DFrame::onClose(...
Does anyone have some more hints?
Thanks for any help
Michael