4

As the title states: I'm trying to use Tamas Szalay's C# port of FFTW in Visual C# 2010 Professional (Trial), and I'm getting the above error when I try to use a two-dimensional transform. (The problem persists when I switch to dft_c2r_2d()). Other functions (in particular, fftw.malloc()) work fine.

Details:

unsafe void FFTFind(IntPtr Scan0, int stride, int width, int height, Rectangle roi)
{
    IntPtr ComplexImage = fftw.malloc(width * height * 16);
    double[] pComplexImage = new double[width * height * 2];
    byte* pScan0 = (byte*)Scan0.ToPointer();

    Console.WriteLine("3");

    for (int y = 0; y < height; y++)
    {
        for (int x = 0; x < width; x++)
        {
            pComplexImage[x * y * 2] = pScan0[y * stride + x * 4];
            //pComplexImage[x * y * 2] = pScan0[y * stride + x];
        }
    }

    Console.WriteLine("3.05");

    Marshal.Copy(pComplexImage, 0, ComplexImage, width * height * 2);

    Console.WriteLine("Starting FFTFind");

    FFTFindKernel(ComplexImage, stride, width, height, roi);
}

unsafe void FFTFindKernel(IntPtr imageIn, int stride, int width, int height, Rectangle roi)
{
    Console.WriteLine("3.1");
    IntPtr hScan0 = (IntPtr) GCHandle.Alloc(imageIn, GCHandleType.Pinned);
    Console.WriteLine("3.3");
    IntPtr FourierPlan;

    Console.WriteLine("3.5");
    int start = System.Environment.TickCount;
    Console.WriteLine("3.7");
    FourierPlan = fftw.dft_r2c_2d(width, height, hScan0, hScan0, 0);
    Console.WriteLine("4");
    fftw.execute(FourierPlan);
    Console.WriteLine("Time: {0} ms", (System.Environment.TickCount - start));
}

The console prints up to "3.7". Attempting to run FourierPlan = ... causes the program to crash and a message box to pop-up:

vshost.exe has stopped working.

Disabling the Visual Studio host process only replaces "vshost.exe" with "FFTFind".

Possibly relevant: I'm running this in an x64 environment (Windows Server Standard), but the dlls and programs are x86. This previously caused a problem in Visual C# 2010 Express, which was solved by switching to the Professional Trial and then manually changing the Configuration Target from "x86" to "Any CPU."

UPDATE: Running the provided test code works fine.

Community
  • 1
  • 1
linkhyrule5
  • 871
  • 13
  • 29
  • It seems you've found a bug in either your pinvoke to the native method or you've hit a bug in the native code. You didn't post either so how can we help? – M.Babcock Feb 08 '12 at 04:29
  • I didn't write either - the code is linked in the post, Tamas Szaley's C# port. I'll send off an email about it if you think that's appropriate, but as this is kind of time-sensitive I'd appreciate the assistance. – linkhyrule5 Feb 08 '12 at 04:43
  • (Oh, and Szaley published his source and has no limits on usage, so if you're willing to go that far there's that option. I'm afraid I'm not really familiar enough with the libraries to know what to copy, but if you give me instructions I can blindly follow directions.) – linkhyrule5 Feb 08 '12 at 04:44
  • Just as a note people that work for free could care less about time sensitivity. I know I won't read through a full project's source for free, hopefully someone here works on the project team or is generous (and bored) enough to solve your problem for you. If you do find someone, their solution will likely be to build a test case like yours and run it through the debugger... what happens when you do that? – M.Babcock Feb 08 '12 at 04:46
  • I'm aware, counting on StackOverflow's relatively large volume to compensate. And it's not like I can't post snippets - I just wouldn't know what to copy. – linkhyrule5 Feb 08 '12 at 04:51
  • (This is me finding out that you can't use carriage returns in comments.) And I'll try that - I'll post here when I find out. – linkhyrule5 Feb 08 '12 at 04:52
  • So I gave Szaley's test code a try, and it worked like a charm in 1d. I'm about to try 2d, see if it breaks anything. – linkhyrule5 Feb 08 '12 at 05:30
  • @linkhyrule5: You mention an error, yet nowhere can I see you provided what the error says. Have you tried using both the managed and unmanaged debuggers at the same time? – leppie Feb 08 '12 at 05:33
  • The error is quoted in the text - I can set it off if you like, but there's no exception code. I'm afraid I don't know how to do that - if you mean clicking "Debug vshost.exe," it tells me that a debugger is already attached. – linkhyrule5 Feb 08 '12 at 05:46
  • There, I set off the error. That's all that I get - no line number, caller, or exception code (which is odd, because I do have a general exception handler at the top that just prints the error to a MessageBox). – linkhyrule5 Feb 08 '12 at 05:47
  • @linkhyrule5: In the debug setting of the project properties, you can enable unmanaged/native debugging. – leppie Feb 08 '12 at 05:49
  • Ah, thanks. I'll try that. By the way: Tested "fftw.dft_2d()" in the test code; it also works. About to test "fftw.dft_r2c_2d()" itself. – linkhyrule5 Feb 08 '12 at 05:50
  • @leppie: Ah, excellent: I got an error code. `Unhandled exception at 0x70681866 in FFTFind_Proj.exe: 0xC0000005: Access violation writing location 0x00000000000c2000.` I'm going to guess that means I'm walking on memory? – linkhyrule5 Feb 08 '12 at 06:04
  • @linkhyrule5: Yes, kinda, that is the native equivalent of `NullReferenceException`. You probably sending in a value instead of an address somewhere. – leppie Feb 08 '12 at 06:06
  • @leppie: Ah, found it. Much appreciated. – linkhyrule5 Feb 08 '12 at 06:20
  • @linkhyrule5: I suggest you post the solution (however trivial) as an answer, and mark it as accepted. – leppie Feb 08 '12 at 06:53
  • The Tamas Szalay's C# port of FFTW link is broken. Do you know were I can found a free C# wrapper for FFTW? – Pedro77 Jul 04 '13 at 13:16

1 Answers1

0

As it turned out, the plan functions cannot take "dummy" pointers - the arrays they point to must be initialized. In retrospect, this should've been obvious...

linkhyrule5
  • 871
  • 13
  • 29