【问题标题】:Using FFTWLib (C#): Using fftw.dft_r2c_2d() crashes vshost.exe, or main program if vshost is not running使用 FFTWLib (C#):使用 fftw.dft_r2c_2d() 会导致 vshost.exe 崩溃,如果 vshost 未运行,则主程序会崩溃
【发布时间】:2012-02-08 03:49:09
【问题描述】:

正如标题所述:我正在尝试在 Visual C# 2010 Professional(试用版)中使用 Tamas Szalay 的 C# port of FFTW,当我尝试使用二维变换时出现上述错误。 (当我切换到 dft_c2r_2d() 时问题仍然存在)。其他函数(特别是 fftw.malloc())工作正常。

详情:

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));
}

控制台最多可打印“3.7”。尝试运行FourierPlan = ... 会导致程序崩溃并弹出一个消息框:

vshost.exe has stopped working.

禁用 Visual Studio 宿主进程只会将“vshost.exe”替换为“FFTFind”。

可能相关:我在 x64 环境(Windows Server Standard)中运行它,但 dll 和程序是 x86。这个previously caused a problem in Visual C# 2010 Express,通过切换到专业试用版然后手动将配置目标从“x86”更改为“Any CPU”来解决。

更新:运行提供的测试代码工作正常。

【问题讨论】:

  • 您似乎在对本机方法的 pinvoke 中发现了一个错误,或者您在本机代码中遇到了一个错误。你也没有发帖,我们能提供什么帮助?
  • 我也没有写 - 代码链接在帖子中,Tamas Szaley 的 C# 端口。如果您认为合适,我会发送一封电子邮件,但由于这对时间很敏感,我会很感激您的帮助。
  • (哦,Szaley 发布了他的源代码并且对使用没有限制,所以如果你愿意走那么远,就有那个选项。恐怕我对图书馆知道要复制什么,但如果你给我指示,我可以盲目地听从指示。)
  • 就像注释一样,免费工作的人可能不太关心时间敏感性。我知道我不会免费阅读完整项目的源代码,希望这里有人在项目团队工作,或者足够慷慨(和无聊)来为你解决问题。如果您确实找到了某人,他们的解决方案可能是构建一个像您这样的测试用例并通过调试器运行它......当您这样做时会发生什么?
  • 我知道,依靠 StackOverflow 相对较大的容量来弥补。并不是我不能发布 sn-ps - 我只是不知道要复制什么。

标签: c# fft fftw


【解决方案1】:

事实证明,计划函数不能采用“虚拟”指针——它们指向的数组必须被初始化。回想起来,这应该是显而易见的......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-23
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多