使用 FFTWLib (C#):使用 fftw.dft_r2c_2d() 会导致 vshost.exe 崩溃,如果 vshost 未运行则导致主程序崩溃
正如标题所述:我正在尝试使用 Tamas Szalay 的 FFTW 的 C# 端口 在 Visual C# 2010 Professional(试用版)中,当我尝试使用二维变换时,出现上述错误。 (当我切换到 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。 之前曾在 Visual C# 2010 Express 中引起问题,通过切换到专业试用版,然后手动将配置目标从“x86”更改为“任何 CPU”来解决。
更新:运行提供的测试代码工作正常。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,计划函数不能采用“虚拟”指针——它们指向的数组必须被初始化。回想起来,这应该是显而易见的......
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...