-
Notifications
You must be signed in to change notification settings - Fork 75
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
gl.FenceSync returns invalid unsafe.Pointer, causing crash #71
Comments
Thanks for reporting. This sounds somewhat similar to #31 that we've had to resolve for Go 1.6. Except I'm guessing that
I need to refresh my memory on this (if you happen to have the relevant doc link handy, please share, otherwise I'll have to look for it), but that's likely the right fix. Thanks. Do you want to send a PR (to go-gl/glow, the generator that generates these bindings)? |
gl.IsSync too. I think it's everything that has |
It's not quite the same as #31, but does fall into the category of not playing loose with pointer types. Regarding documentation: https://www.khronos.org/opengl/wiki/Sync_Object and the Go spec would be relevant here. The former specifies that GLsync is an opaque type Good point re gl.IsSync – I haven't looked up the whole list of GLsync-related functions.
I can do that if my proposed solution is accepted. |
Right, it should be straightforward to update |
Reopening because we still need to regenerate these bindings with the latest glow. (See https://github.com/go-gl/gl#generating and #54 for an example of a regenerate PR.) |
Regenerate all bindings after generator change in go-gl/glow#79. Done with latest version of glow: go generate -tags=gen github.com/go-gl/gl Resolves #71.
It seems that the straightforward fix to change the generated type to Go is unhappy converting between It might be safe to do a just-in-time conversion from |
I can't say for sure if that conversion would be safe or not. I'd like to err on the side of "not safe" if arguments are placed on the stack before the call. I'm currently checking if there is another way around this that doesn't require extending glow. |
@errcw So… Doing I don't see any other solution than the one proposed by you, which adds C shims to do the conversion for us. One idea that I had was a |
So, in theory, we can mangle the C parameter types used for both the GL function typedefs and the corresponding cgo entry points, because we simply need the types to align throughout the generated code and be compatible with the function pointers, rather than being exactly faithful to the GL definitions. In |
Which type would you use instead? We can't use |
In a cursory search I failed to find conclusive evidence whether Another alternative we could consider is to change the |
Like I said in my previous message, using |
I'm not sure we'd have to route through |
@errcw, was this issue closed intentionally? |
Alas, no, I was just resyncing my fork to try to work on it. |
@errcw What I am referring to is that a C function
because of
Of course you can convert a uintptr to an unsafe.Pointer, and that's what
results in
and
|
All right, I have a proposed workaround in glow #85. It relies on I verified it works as intended on macOS but that's the only platform I currently have available to build and test on. If somebody else is interested in verifying on another platform that'd be great. |
I should be able to give the patch a test later this week. |
Friendly ping @dominikh. |
I've finally gotten around to testing the change. It compiles, doesn't cause runtime panics, and I've successfully used a fence. |
Thanks! I've merged in my fix. Ideally we now regenerate go-gl/gl with the updated code. |
@errcw it might be worth mentioning that when I regenerated the 4.5-core bindings with glow, some function signatures changed from accepting int32 to accepting int. I don't know if that's expected or not, but it'd break consumers of the API. |
Alas. Well, because of #80, I'm expecting a more broadly breaking API change will be necessary, so hopefully we can break everyone only once. |
We've regenerated with latest glow and merged #93. I believe this should be resolved. Can you please confirm? |
Friendly ping @dominikh. You said on February 15:
If that's still the case, I think we can close this issue as resolved (via PR go-gl/glow#85 to glow, and PR #93 to regenerate gl). |
Like I said, it's working :-) |
gl.FenceSync returns the created fence as an unsafe.Pointer. However, values returned by glFenceSync aren't necessarily valid pointers to memory owned by the driver.
On my system (nvidia 378.13 on Linux), for example, glFenceSync returns increasing numbers, starting at 1. The issue with that is that the Go runtime expects pointers in unsafe.Pointer to be valid, either pointing to memory owned by the Go memory allocator, or valid, non-Go memory. Pointers such as "1" are neither, which causes runtime.writebarrierptr to abort the program with a "bad pointer in write barrier" error. Similarly, the driver might return a value that looks like a valid pointer to Go memory, preventing said Go memory from being garbage collected as long as the unsafe.Pointer is alive.
To simulate the issue, compile https://play.golang.org/p/614oIx_Y1D and run it with GOGC=0 (to force frequent GCs, triggering the problem faster.). You should see the following:
I would recommend returning a uintptr instead (and, similarly, accepting a uintptr in gl.ClientWaitSync and gl.WaitSync).
The text was updated successfully, but these errors were encountered: