2016-04-05 9 views
0

Ich erhalte diesen Laufzeitfehler: InvalidProgramException: Invalid IL code. Ich benutze Einheit 5.3.1f1. Das Projekt ist eine Editor-Erweiterung. Eine vereinfachte Version des Codes lautet:InvalidProgramException: Ungültiger IL-Code beim Aufruf der Methode

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

Dieser Fehler tritt in dieser Zeile auf.

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)

Die Neuberechnung Methode ist:

 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

Betreiben Sie Unity mit Mono unter Linux? –

+0

Nein, es ist auf Windows 7. Das Projekt war in Ordnung, aber nach einigen Code-Änderungen und auch Downgrade meiner Visual Studio auf 2013 und Nachrüsten auf 9 der Fehler zeigte sich. Ich weiß nicht, ob sich der Code ändert, wo der Grund oder das Downgrade war. Dann habe ich vs 2015 installiert und 10 erneut geschärft und der Fehler ist geblieben. Versuchte ein paar UnityVs-Versionen und sogar ein neues Windows installiert. Und ein Paket aus dem Projekt gemacht und ein anderes Projekt erstellt und das Paket importiert. Dies hat das Problem auch nicht gelöst. –

+0

Ich wundere mich wegen 'at/Benutzer/Builduser/Buildslave/Mono-Runtime-und-Classlibs/Build/McS/Klasse/Corlib/System.Reflection/MonoMethod.cs' –

Antwort

0

die Lösung gefunden. Es ging nicht um die Projekteinrichtung.

Das Problem ist mit Linie *padDSPix++ = *dsPix++ = *myPix;. Durch die Umwandlung in zwei separate Anweisungen wurde das Problem gelöst.

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

Es ist interessant zu sehen, wie sehr die Fehlermeldung allgemein und irreführend ist.

Verwandte Themen