Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2004

Tip: Looking for answers? Try searching our database.

Runtime error, 'Invalid IL code'

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sijmen Mulder - 17 May 2004 12:47 GMT
For my SDL wrapper, I wrote some code to correctly convert 256-color
palettes. That needed some interop, so this is what I did:

1. Added the native function definition to my interop class.
3. Added extra required structs to the interop class.
2. Added the call to the method.

But now I am getting this error, at runtime:

---
** ERROR **: Invalid IL code at IL0000 in
ManagedGL.Native.Sdl:SDL_SetColors
(ManagedGL.Native.Sdl/SDL_Surface*,ManagedGL.Native.Sdl/SDL_Color*,int,int):
IL_0000: stloc.s   48
---

Here is the interop definition:

---
[DllImport(SDL_DLL, CallingConvention=CallingConvention.Cdecl),
 SuppressUnmanagedCodeSecurity]
public static extern int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors,
 int firstcolor, int ncolors);
---

Here are the definitions of the added structs:

---
[StructLayout(LayoutKind.Sequential, Pack=4)]
public struct SDL_Color
{
 public byte r;
 public byte g;
 public byte b;
 public byte unused;
}
       
[StructLayout(LayoutKind.Sequential, Pack=4)]
public struct SDL_Palette
{
 public int       ncolors;
 public SDL_Color *colors;
}
---

Here, at final, is the call that caused all the problems:

---
Sdl.SDL_SetColors(ret.surface, surface->format->palette->colors, 0,
 surface->format->palette->ncolors);
---

The platform on which I ran this is Linux/Mono/x86, nothing weird.

IMPORTANT NOTE: There are 10+ other native structs and 100+ more
functions declared in the interop class, they work great. They are defined
exactly the same as the new one.

To take a further look at the source files, checkout
www.sourceforge.net/projects/managedgl

Thanks in advance!
Daniel O'Connell [C# MVP] - 17 May 2004 13:38 GMT
> For my SDL wrapper, I wrote some code to correctly convert 256-color
> palettes. That needed some interop, so this is what I did:
[quoted text clipped - 10 lines]
> (ManagedGL.Native.Sdl/SDL_Surface*,ManagedGL.Native.Sdl/SDL_Color*,int,int):
> IL_0000: stloc.s   48

Well, this is a problem. You can't emit a stloc instruction as the first
instruction. Stloc stores the value currently on the stack. at IL_0000 the
stack is empty. I would suspect that the problem is due to the compiler. You
mention further down that you are using mono, which version of the compiler
are you using?

> To take a further look at the source files, checkout
> www.sourceforge.net/projects/managedgl
>
> Thanks in advance!
Sijmen Mulder - 17 May 2004 13:54 GMT
> Well, this is a problem. You can't emit a stloc instruction as the first
> instruction. Stloc stores the value currently on the stack. at IL_0000 the
> stack is empty. I would suspect that the problem is due to the compiler. You
> mention further down that you are using mono, which version of the compiler
> are you using?

I am using beta 1, the newest AFAIK.
Very strange. I wonder where such a thing could slip in. Maybe wrong
interop definitions.. or a null pointer?
Daniel O'Connell [C# MVP] - 17 May 2004 14:09 GMT
>> Well, this is a problem. You can't emit a stloc instruction as the first
>> instruction. Stloc stores the value currently on the stack. at IL_0000
[quoted text clipped - 8 lines]
> Very strange. I wonder where such a thing could slip in. Maybe wrong
> interop definitions.. or a null pointer?

Not sure. Try compiling with microsofts compiler and see what happens. If
csc compiles it correctly then I would file a bug with mono, if it doesn't
then...well, then leave a message here and we'll see what we can find out.

I've had a few issues with mono emitting incorrect code and\or metadata with
some of the earlier versions. This one might still have a codegen bug they
havn't caught.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.