首页 文章

InvalidProgramException:调用方法时无效的IL代码

提问于
浏览
0

我收到此运行时错误: 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 []参数,System.Globalization.CultureInfo文化)(在/ Users / buil duser / buildslave /单运行时和 - 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;
            }
        }
    }

1 回答

  • 0

    找到了解决方案 . 这不是关于项目设置 .

    问题在于 *padDSPix++ = *dsPix++ = *myPix; 行 . 将其转换为两个单独的语句解决了这个问题 .

    pixH = *myPix; 
    *padDSPix++ = pixH;
    *dsPix++ = pixH;
    

    有趣的是看错误消息是多么普遍和误导 .

相关问题