Dear Community,
I have a very strange error that started to occur two weeks ago. When I run
an Application that worked without problems for nearly half a year now, there
suddenly is one function which I am calling via PInvoke that sometimes fails.
If this happens, I find one of the following entries in the Eventlog:
Faulting application smarttray.exe, version 2.0.0.8, stamp 44f57722,
faulting module libfftw3f-3.dll, version 0.0.0.0, stamp 44a9eea3, debug? 0,
fault address 0x000a5c35.
or
Faulting application smarttray.exe, version 2.0.0.8, faulting module
libfftw3f-3.dll, version 0.0.0.0, fault address 0x00099bc3.
One very strange thing is that restarting the Aplication with exactly the
same Input Data will help. Sometimes I need to restart it once, sometimes I
need to restart it up to 10 times. Once it started running, it will continue
to work without error.
I identified the exact line of Code but even an additional try-catch block
does not help. The runtime simply crashes.
Another strange thing is that the Visual Studio 2005 Debuger (Pressing Play)
somehow prevents this error from happening.
Does anybody have an Idea how to solve this issue? Or an idea what is
different when using the Visual Studio Debugger? (If it is just a matter of
compiler switches, I would like to try them out)
As I already mentioned, this error only occurs since approx. 2 Weeks. Does
anybody have an Idea if one of the recent Windows Updates may be the cause?
Thanks in Advance for your Efforts
Fonz
I was asked to provide DLLImport Section and relevant Information
the function that only works sometimes is:
fftwf_execute_dft_r2c in libfftw3f-3.dl
This is the Import in the Wrapper DLL which calls libfftw3f-3.dl internally
the binaries can be downloaded from fftw.org
[DllImport("emp.dll")]
private static extern void AliPol2D_makeRefs (IntPtr ptr);
This is the function in the DLL that calls libfftw:
void empAlign2DPolar::makeRefs () {
if (!(_Refs)) throw empError ("empAlign2DPolar", "makeRefs", "Refs nicht
gesetzt!");
// Variablen
int index = 0;
int end = 0;
int xh = _Refs->dimx() / 2;
int yh = _Refs->dimy() / 2;
if ( (!_fwd) || (!_inv)) {
_makePlan();
}
// _Referenzen erzeugen, falls noch nicht erzeugt
if (_polRefVec.size() == 0) {
// Debug
dmsg (10 , "Erstelle Referenzen \n");
_polRefVec.resize (_Refs->dimz());
_Params->x_center = (float) xh;
_Params->y_center = (float) yh;
end = _Refs->dimz();
#pragma omp parallel default(shared)
{
#pragma omp for
for ( index = 0; index < end; index++) {
// Hilfs Variablen
empPolar polTmp;
empImgR tmpRef (_Refs->get_XYImg(index));
//_normvar (tmpRef );
polTmp.setParams (*_Params );
polTmp.setImg ( tmpRef );
dmsg (10 , "Compute Polar Coord. Nr.: %d \n", index);
polTmp.compute ();
// Normalize to Sigma = 1.
dmsg (10 , "Compute Normalise Coord. Nr.: %d \n", index);
_normvar (polTmp.getImg());
dmsg (10 , "Ende Normalise Coord. Nr.: %d \n", index);
dmsg (10 , "Compute fft Nr.: %d \n", index);
_polRefVec[index].swap (_fft(polTmp.getImg()) );
dmsg (10 , "Ende fft Nr.: %d \n", index);
dmsg (10 , "Ref. Nr.: %d \n", index);
}
} // Ende pragma omp
} // Ende "if (_polRefVec.size() == 0)"
dmsg (10 , "_haveRefs = true;\n");
_haveRefs = true;
}
void empAlign2DPolar::_makePlan () {
int fft = _Params->extras & 0x0003;
int dim = (int) (_Params->radius*_Params->sampling);
for (int i=0; i < sizeof(fsize)/4; i++) {
if (dim > fsize[i]) continue;
dim = fsize[i];
break;
}
if (_fwd) fftwf_destroy_plan(_fwd);
if (_inv) fftwf_destroy_plan(_inv);
// Erzeuge FFTW-Plan
float *in = MALLOC(float, dim);
fftwf_complex *out = MALLOC(fftwf_complex, dim/2+2);
memset (in, 1, dim*sizeof(float));
_fwd = fftwf_plan_dft_r2c_1d(dim, in, out, PLANTYPE);
_inv = fftwf_plan_dft_c2r_1d(dim, out, in, PLANTYPE);
FREE (in);
FREE (out);
#endif
}
empImgC empAlign2DPolar::_fft (const empImgR& value) {
int fft = _Params->extras & 0x0003;
int size = value.dimx()/2+2;
empImgC tmp (size, value.dimy());
dmsg (10 , "Compute fftwf_execute_dft_r2c\n");
for (int i=0; i < value.dimy(); i++) {
fftwf_execute_dft_r2c(_fwd, value.ptr(0, i),
reinterpret_cast<fftwf_complex*>(tmp.ptr(0,i)));
}
dmsg (10 , "end fftwf_execute_dft_r2c\n");
return tmp;
}
I any additional Information is needed, please ask!
Thomas Scheidegger [MVP] - 31 Aug 2006 14:57 GMT
> [DllImport("emp.dll")]
> private static extern void AliPol2D_makeRefs (IntPtr ptr);
>
> This is the function in the DLL that calls libfftw:
> void empAlign2DPolar::makeRefs () {
why is there an 'IntPtr' parameter in C# DllImport, but none in C++?
ThisCall?
was multi-threading used anywhere in the project?

Signature
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_dotnet.html - http://dnetmaster.net/
Chucker - 31 Aug 2006 15:28 GMT
Because I forgot to post the Wrapper Part, here it is:
Multithreading is used in the C# Part of the Aplication I am using the
UpdaterAplicationBlock 2.0 and the Updater runs in it´s own thread.
In the native C++ part of the Aplication I am not using explicit
multithreading but OpenMP, disabling OpenMP does not change the strange
behaviour.
The libfftw3 ist threadsafe except for the generation of fftw_plans but I am
taking care of this.
Thanks for your Efforts so far!
Fonz
.
.
.
private CImgR _refs;
private CImgR _imgs;
private InParams _iparam;
private IntPtr _ali;
public Align2D()
{
_refs = new CImgR ();
_imgs = new CImgR ();
_ali = AliPol2D_Create ();
}
~Align2D()
{
_refs = null;
_imgs = null;
AliPol2D_Delete (_ali);
}
public ImgF Refs
{
set {
_refs.Image = value;
AliPol2D_setRefs (_ali, _refs.CPointer );
#if(VERBOSE)
Console.WriteLine("Calling AliPol2D_makeRefs (_ali );");
#endif
AliPol2D_makeRefs (_ali );
#if(VERBOSE)
Console.WriteLine("AliPol2D_makeRefs finished");
#endif
}
}
public ImgF Imgs
{
set {
_imgs.Image = value;
AliPol2D_setImgs (_ali, _imgs.CPointer );
}
}
> > [DllImport("emp.dll")]
> > private static extern void AliPol2D_makeRefs (IntPtr ptr);
[quoted text clipped - 6 lines]
>
> was multi-threading used anywhere in the project?