Tyrrrz's picture

TextureWrapMode causes InvalidEnum error when passed as a struct field [solved]

I have these two lines of code:

GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)options.WrapMode);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)options.WrapMode);

options is a struct object, which holds TextureWrapMode enum field (called WrapMode).
When i pass it like this OpenGL tells me about InvalidEnum error.
When i pass it directly like TextureWrapMode.Repeat it works fine.
I debugged the field, passed in struct and they are perfectly fine (int representations are also identical).
What do?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

There is no obvious reason why this should be happening. Are you using Windows / .Net, or Mono? Is this a x86 build or AnyCPU?

You can use apitrace to debug what exactly is going on (it will show the exact data that received by the driver.)

Tyrrrz's picture

Windows.Net/AnyCPU
I'm 100% sure that the error occurs at this point, because commenting it out or setting the value of enum directly doesn't produce an error.
Yet, the structure with exact same enum fails.
I'm absolutely clueless.
I will try tracing tomorrow, when i can.

the Fiddler's picture

This is weird. Can you provide a small test case that reproduces this issue?

Edit: I tried with the following but could not reproduce the issue.

        struct Options
        {
            public TextureWrapMode WrapMode { get; set; }
        }
 
        static void Main()
        {
            using (var gw = new GameWindow())
            {
                gw.VSync = VSyncMode.Adaptive;
                gw.Load += (sender, e) =>
                {
                    int id = GL.GenTexture();
                    GL.BindTexture(TextureTarget.Texture2D, id);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)options.WrapMode);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)options.WrapMode);
                    GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, 512, 512, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
                };
                gw.Run();
            }
        }

This was compiled for .Net 2.0, AnyCPU, on VS2013, on Win8.1 x64.

Tyrrrz's picture

Sorry, i was very stupid. I was debugging one texture, while the error occured in the other (where the enum was actually invalid).
I apologize for taking your time.

the Fiddler's picture

All is good then, glad you solved it. :) I was starting to imagine horror scenarios of stack corruption (we had one of those back in the 0.3.x days, and it was *not* fun to debug.)