2016-04-05 93 views
0

我收到此運行時錯誤:InvalidProgramException: Invalid IL code。我正在使用統一5.3.1f1。該項目是一個編輯器擴展。代碼的簡化版本爲:InvalidProgramException:調用方法時無效的IL代碼

public unsafe class PPAGraph 
{ 
    PaddedImage downSampleImage; 
    int downSampleRate; 
    internal void Calculate(PaddedImage sourceImage) 
    { 
    sourceImage.DownSample(downSampleImage, downSampleRate); 
    } 

此錯誤發生在此行上。

InvalidProgramException: Invalid IL code in Assets.UPlus.TerrEngine.PaddedImage: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 portion) (at Assets/UPlus/TerrEngine/Engine/PPA/PPAGraph.cs:1311) Assets.UPlus.Utils.TerraGodContext.CalcSketchPpa (Assets.UPlus.TerrEngine.PaddedImage sketchImg, Int32 sketchDownSampleRate) (at Assets/UPlus/TerrEngine/UnityEngine/TerraGodContext.cs:70) EditorExtensions.Editor.TerrainGodMainPanel.CreatePanel() (at Assets/UPlus/TerrEngine/Engine/Editor/TerrainGODMainPanel.cs:45) EditorExtensions.Editor.TerrainGODWindow.OnGUI() (at 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-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)

下采樣的方法是:

 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

你在Linux上運行Unity與Mono嗎? –

+0

不,它是在Windows 7上。該項目之前,但一些代碼更改後,也將我的視覺工作室降級到2013年,並resharper到9出現錯誤。我不知道代碼是否因理由或降級而改變。然後我安裝了vs 2015並重新安裝了10,並且錯誤依然存在。嘗試了幾個unityvs版本,甚至安裝了一個新窗口。並從項目中創建了一個包並創建了另一個項目並導入了該包。這也沒有解決問題。 –

+0

我想知道是因爲'at/Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs' –

回答

0

找到了解決辦法。這不是關於項目設置。

問題出在線*padDSPix++ = *dsPix++ = *myPix;。將它轉換爲兩個單獨的語句解決了這個問題。

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

有趣的是,看看錯誤信息是多麼普遍且令人誤解。

相關問題