-
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
PtrOffset causes "cgo argument has Go pointer to Go pointer" runtime error #80
Comments
As I understand it, the TL;DR is that Go does not allow non-pointer values in pointer types such as |
Breaking change is okay if it's neccessary/unavoidable, as the current code is unusable. But it's a matter of figuring out whether that's the best fix. But this issue, isn't it the same/related to #71? |
Yep, this issue is related to #71, but it's somewhat simpler in that we are not required to change the OpenGL typedefs to change the Go type bindings. |
I agree with shurcooL. The sooner a fix can be made, the better, even if it is breaking. I also haven't had any success with GODEBUG=cgocheck=0. Only by setting GOGC=off are crashes eliminated entirely. |
Unfortunately our options here are limited by Go/cgo requirements. As I indicated before, Go does not allow non-pointer values in pointer types, so declaring a parameter that might take an offset as So where does that leave us? To start,
Both options require identifying parameters that are declared as Right now I'm leaning towards option 2, but I'd like to hear additional input. |
Thanks for the update and for the work on this package. I currently pass both pointers and offsets to DrawElements, but for the cases where I'm passing a pointer to indices, I could put the indices in a buffer and avoid passing pointers. A more complicated case is MultiDrawElements or MultiDrawElementsBaseVertex where the indices parameter type is "const GLvoid * const * indices", which can be a combination of true pointer and offsets. I'm passing the address of the first element of a list containing PtrOffsets. How would that work?
|
Aha, My takeaway is that simply assuming we can transform the API to use |
WithOffset methods would work for me. Thanks. |
Sounds like this thread has a potential resolution, adding |
Works for me too. |
Another person hit this on go-gl/example#72 Anyone able to cook up a fix? I'm a willing reviewer, just not implementer at this time. |
Hello there! The pull request go-gl/glow#107 is my proposal to add overload capabilities. This way To continue the discussion, the following is unclear to me:
I was able to do a minimal test with the three functions I used as a sample - though it was tedious;
|
I reckon strictly using suffixes makes this change more accessible because there is a good chance users will see both functions in auto completion in their IDEs and thus be more likely to learn of the situation and how to deal with it without an extra round-trip through this project's issue list or Stackoverflow. |
Thank you for the response. Meanwhile I figured as well fixed suffixes are better for this, as perhaps a standard To be sure though, the overload of |
The pull request was accepted for glow. Now to collect all the functions that need overloads. Does anyone have an idea which functions are affected? Would this be a group-effort and everyone contributes? |
I just looked at If we are going to miss a couple functions (as a compromise) we should definitely make a mention of the whole situation in the README. |
I'm sure you could publish a new version with just the three overloads already defined by @dertseha. They are enough for me, and I think many other: all the |
The difference from [go-gl](https://github.com/go-gl/gl) are: - WithOffset variants for some functions, so you don't have to pass pointers insteas of offsets (closes go-gl/gl issues [80](go-gl#80) and [124](go-gl#124)). Currently only functions `glDrawElements`, `glVertexAttribPointer`, `glGetVertexAttribPointerv` provide variants: let me know if you need more. - No need to use cgo under Windows (much faster build times).
In the meantime it gets fixed, you can use my fork. |
How can we get going in this matter? When I re-generate using Is there a canonical way to generate these files with |
Do you have an example PR/diff that demonstrates the issue (the include issue, that is)? (Also: full disclosure, it's been a while since I've actively worked in this space, and as much as I've love to dive in and fix this ASAP my time is pretty constrained these days.) |
Here's the current section that is mainly affected, for
When I run
It seems all the core As per https://www.khronos.org/registry/implementers_guide.html#headers , this file centralizes such logic and is meant for "all" APIs, although "stored" in EGL repo. I understand under Linux it's possibly solved as in #106 , yet I can't find a way to solve this on MS Windows (google-fu fails me here). |
Thanks for showing that diff. It does indeed appear that historically the GL types were defined in a self-contained way (e.g., here So, yes, it does seem like the fundamental problem to solve is how to make |
Looking at my go-to loader-builder for C-based environments glad, there the Seems like it's another problem to fix first. I'll have a look to extend glow to download and provide also this file when generating code. |
PRs for both As noted in the PR and other comments, this is a start for the necessary "override" functions. My proposal is to still close this issue here when the PRs are merged and accept corresponding issues/PRs on demand for further functions. I doubt that this task will ever be complete, so there's no point in keeping this issue open forever. |
I just learned this issue might be more severe than previously thought. To quote Ian Lance Taylor:
This could explain some performance issues I have been having, where after running the application for some time, the garbage collector began taking longer and longer to execute even though no new objects were being created. (Upwards of 4 milliseconds) I'll follow-up here with some more occurrences of functions which need a |
EDIT: using
GODEBUG=cgocheck=0
can disable these checks but seems like kind of a hacky-workaround, especially if you need runtime pointer checks for other packages.It seems that calling functions like
gl.DrawElements
usinggl.PtrOffset
to convert a gl buffer offset causes the Go runtime to intercept those offsets as if they were pointers into Go memory. This is just a toy example; I've run into this problem using large index/vertex buffers in other projects. Trying to index elements in the millions seems to semi-randomly throw errors.Drilling down a bit:
I'm already out of my depth here but I'm wondering why offsets have to be sent to OpenGL via CGO as unsafe.Pointer? Is there some obvious way around this error I'm missing?
Program to reproduce:
The text was updated successfully, but these errors were encountered: