我收到此运行时错误:InvalidProgramException: Invalid IL code
。我正在使用unity 5.3.1f1。该项目是编辑器扩展。代码的简化版本是:
public unsafe class PPAGraph
{
PaddedImage downSampleImage;
int downSampleRate;
internal void Calculate(PaddedImage sourceImage)
{
sourceImage.DownSample(downSampleImage, downSampleRate);
}
此行发生此错误。
InvalidProgramException:Assets.UPlus.TerrEngine.PaddedImage中的IL代码无效:DownSample(Assets.UPlus.TerrEngine.PaddedImage,int):IL_00a9:stloc.s 15
Assets.UPlus.TerrEngine.PPAGraph.Calculate(Assets.UPlus.TerrEngine.PaddedImage sourceImage,Boolean isRidge,Boolean sketch,Int32 plength,Int32 part)(在Assets / UPlus / TerrEngine / Engine / PPA / PPAGraph.cs: 1311) Assets.UPlus.Utils.TerraGodContext.CalcSketchPpa(Assets.UPlus.TerrEngine.PaddedImage sketchImg,Int32 sketchDownSampleRate)(在Assets / UPlus / TerrEngine / UnityEngine / TerraGodContext.cs:70) EditorExtensions.Editor.TerrainGodMainPanel.CreatePanel()(在Assets / UPlus / TerrEngine / Engine / Editor / TerrainGODMainPanel.cs:45) EditorExtensions.Editor.TerrainGODWindow.OnGUI()(在Assets / UPlus / TerrEngine / Engine / Editor / TerrainGODWindow.cs:39) System.Reflection.MonoMethod.Invoke(System.Object obj,BindingFlags invokeAttr,System.Reflection.Binder binder,System.Object [] parameters,System.Globalization.CultureInfo culture)(at / Users / builduser / buildslave / mono-runtime-和-classlibs /建造/ MCS /类/ corlib /的System.Reflection / MonoMethod.cs:222)
DownSample方法是:
public void DownSample(PaddedImage downSampImg, int downsampleRate)
{
int dsW = downSampImg.Width;
int dsH = downSampImg.Height;
float* dsPix = downSampImg.Pixels,padDSPix=downSampImg.PaddedPixels;
int pad = Padding;
int twoPad = pad + pad;
float* rowMyPix = PaddedPixels;
rowMyPix += pad*PaddedWidth + pad;
float* myPix;
int yStep = downsampleRate * PaddedWidth;
int dsPad = downSampImg.Padding;
int twoDSPad = dsPad + dsPad;
padDSPix += downSampImg.PaddedWidth*dsPad + dsPad;
if (downSampImg.PixelsPtr != IntPtr.Zero)
{
for (int y = 0; y < dsH; y++)
{
myPix = rowMyPix;
for (int x = 0; x < dsW; x++)
{
*padDSPix++ = *dsPix++ = *myPix;
myPix += downsampleRate;
}
padDSPix += twoDSPad;
rowMyPix += yStep;
}
}
else
{
for (int y = 0; y < dsH; y++)
{
myPix = rowMyPix;
for (int x = 0; x < dsW; x++)
{
*padDSPix++ = *dsPix++ = *myPix;
myPix += downsampleRate;
}
padDSPix += twoDSPad;
rowMyPix += yStep;
}
}
}
答案 0 :(得分:0)
找到解决方案。这不是关于项目设置。
问题在于行*padDSPix++ = *dsPix++ = *myPix;
。将其转换为两个单独的语句解决了这个问题。
pixH = *myPix;
*padDSPix++ = pixH;
*dsPix++ = pixH;
有趣的是看错误信息的一般性和误导性。