我有2个互操作的数据结构的一类私有成员,AccessViolationException如果我变量声明为公共成员,而不是局部变量
public class RunInterop
{
private AlphaShapeCg _alphaHandler;
private DoubleCgList alphaLevels;
private FaceCgList faceCgList;
public RunInterop()
{
faceCgList =new FaceCgList();
alphaLevels = new DoubleCgList();
Interop_Init(ref _alphaHandler, ref faceCgList, ref alphaLevels);
Interop_Run(ref _alphaHandler);
}
}
现在的问题是,我将在Interop_Run
得到System.AccessViolationException
线。
但是,如果我用以下方式重写我的代码:
public class RunInterop
{
private AlphaShapeCg _alphaHandler;
public RunInterop()
{
var faceCgList =new FaceCgList();
var alphaLevels = new DoubleCgList();
Interop_Init(ref _alphaHandler, ref faceCgList, ref alphaLevels);
Interop_Run(ref _alphaHandler);
}
}
那么我不会有任何问题。任何想法为什么这是这种情况?
编辑:真令人费解的是,为什么如果我宣布faceCgList
和alphaLevels
为局部变量,问题就会消失?
“_alphaHandler”声明在哪里? –
也,你的代码闻起来。 –
@ DanielA.White,问题更新 – Graviton