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.