Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DrawElements does not work in a safe context #1350

Closed
Tracked by #1372
ManaMarkTea opened this issue Mar 21, 2023 · 8 comments
Closed
Tracked by #1372

DrawElements does not work in a safe context #1350

ManaMarkTea opened this issue Mar 21, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@ManaMarkTea
Copy link

Summary

Using a 0 with draw elements results in nothing drawing, no warnings, no errors. But putting an unsafe void* fixes the problem.

        public void DrawElements()
        {
            gl.DrawElements(PrimitiveType.Triangles, (uint)validIndex, DrawElementsType.UnsignedInt, 0);
        }

        public unsafe void DrawElements()
        {
            gl.DrawElements(PrimitiveType.Triangles, (uint)validIndex, DrawElementsType.UnsignedInt, null);
        }

Steps to reproduce

  • Platform: Desktop
  • Framework Version: .NET Core 3
  • API: OpenGL
  • API Version: OpenGL 4.5 Core

Setup a VAO with EBO and ABO bound correctly
Call Draw elements with 0
Note that it doesn't work.
Call Draw Elements with unsafe null.
Note that it starts working fine.

Comments

This has been noted by multiple people in discord

If you know how to fix this issue, please submit a pull request instead!
I assume its something in the marshal process?

@ManaMarkTea ManaMarkTea added the bug Something isn't working label Mar 21, 2023
@ManaMarkTea
Copy link
Author

        gl.BindBuffer(BufferTargetARB.ArrayBuffer, vertexData);
        {                
            byte[] bogusBuffer = new byte[dataSize];
            gl.BufferData<byte>(BufferTargetARB.ArrayBuffer, (nuint)dataSize, bogusBuffer, drawType); // reserve space
        }

BufferData seems to have a similar problem when trying to reserve buffer space for BufferSubData but instead it crashes with an access exception, requiring you to provide a throw away buffer that open gl would not normally require.

@Perksey
Copy link
Member

Perksey commented Mar 21, 2023

By passing zero you are asking the library to pass a pointer to zero, rather than a zero pointer.

We had tried to remove these overloads, but guess it’s not working. I’ll have another look at it. However, we most likely won’t be adding a safe overload for this.

@ManaMarkTea
Copy link
Author

Thats very interesting, is that what that nint stuff is? Is it not possible to add a marshal for IntPtr.Zero? Thanks for checking, it certainly threw me off, and if it wasn't for someone else mentioning it, I would have been really stuck trying to figure out what wasn't drawing.

@Beyley
Copy link
Contributor

Beyley commented Mar 21, 2023

Thats very interesting, is that what that nint stuff is? Is it not possible to add a marshal for IntPtr.Zero? Thanks for checking, it certainly threw me off, and if it wasn't for someone else mentioning it, I would have been really stuck trying to figure out what wasn't drawing.

What would be the use of an IntPtr overload when there is a void* one?

@ManaMarkTea
Copy link
Author

ManaMarkTea commented Mar 21, 2023 via email

@Beyley
Copy link
Contributor

Beyley commented Mar 21, 2023

You can use IntPtr without needing the unsafe keyword.

On Tue, Mar 21, 2023 at 2:05 PM Beyley Thomas @.***>
wrote:

Thats very interesting, is that what that nint stuff is? Is it not
possible to add a marshal for IntPtr.Zero? Thanks for checking, it
certainly threw me off, and if it wasn't for someone else mentioning it, I
would have been really stuck trying to figure out what wasn't drawing.

What would be the use of an IntPtr overload when there is a void* one?


Reply to this email directly, view it on GitHub
#1350 (comment),
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AA4KCBSPJHKTEQGUEXKOAYLW5IJ3DANCNFSM6AAAAAAWB7YOLM
.
You are receiving this because you authored the thread.Message ID:
@.***>

Why avoid unsafe? that would just bloat overload counts

@ManaMarkTea
Copy link
Author

Ya, I guess I've just enjoyed OpenTK's ability to leave the Unsafe options off yet still can do all the things I need to do to render things. But if being an safe compatible API is not a goal (which does not appear to be the case), then just removing the errant behavior would be good.

@Perksey
Copy link
Member

Perksey commented Mar 30, 2023

I have experimented with fixing this and unfortunately I cannot implement a fix that is acceptable to the team.

Please note: even if you're not using unsafe language features, everything you do with Silk.NET (or even OpenTK or any native interop library) is inherently unsafe and avoiding those language features doesn't change that.

Please use null instead of 0. 0 passes an implicit pointer to 0 which is not what you want in most cases. This will require an unsafe context.

Thanks.

@Perksey Perksey closed this as not planned Won't fix, can't repro, duplicate, stale Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants