-
Notifications
You must be signed in to change notification settings - Fork 74
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
Null terminate strings automatically in Strs() #77
Comments
This is a bit of a tricky case. |
i think the OpenGL API's allow non-null terminated IF they get an array of lengths, makes sense, but since Strs doesn't return the lengths, (and there would be issues with two parameters anyway), how could it ever work for non-null terminated strings? like its documented to be able to. why not just have Strs check and add Null's if not there? even just always add one, two wouldn't hurt. this was what i assumed it had to be doing, here is your example i was recommended to follow; i guess the example requires pre-null terminated strings to work. |
Yep, the example appends I think you're right that it should be (relatively) straightforward to have +@shurcooL to chime in once he's back. Just want a quick sanity check from another go-gl dev before committing to this feature. |
As far as I can tell, the way things work is that user passes a Go string with "\x00" suffix to As the example shows: @splace, can you clarify what the problem is? Is this a feature request? A problem in documentation? Broken functionality? |
I believe the feature request is to unconditionally append \x00 to the C strings produced by gl.Strs such that Go developers are not required to remember to append it themselves. |
Didn't we already do that via #46, go-gl/glow#71 and #49? |
My understanding is that the request here is to revisit the decision in #46 and make Strs more friendly by adding a null terminator to the passed in Go strings. |
But my memory of this is fuzzy, and it's possible I got some of the details wrong. Edit: Now that I've spent more time looking into this, most of what I said above is not accurate/relevant. Looking at the source of
Edit: Instead, #46 (comment) is what I was thinking of/trying to recall. I would imagine that a version of One of my concerns is having too many choices offered to a new user of Since my memory is fuzzy on the details, I'm open to corrections or hearing motivation why this would be a good change to make. But right now I don't see any motivation provided in this issue. |
Sorry for trigger happy comments, I'm coming back to this after a long time. To summarize my stance on this, I'm open to discussion if additional information and motivation is provided. I want to see sample code that demonstrates how user code would benefit from the proposed change. Then we can discuss trade-offs and various options. I don't want us to make changes to So, this issue is in "waiting for info" state for me. |
I've bit myself a couple times in unpleasant ways with this and end up doing stuff like
in my shader compiler cause null terminators aren't something I'm thinking about in Go, but it did occur to me things like gl.ShaderSource could check if the **uint8 is terminated if it's supposed to be and if not fix it, which wouldn't change the behavior of Strs and would eliminate the need for a Strs variant that adds a terminator. |
Just thinking.... might neaten this up by making use of the other form of the call, pointers into an array of strings, but with only the one string. |
Looks like this thread fizzled out. Is there anyone with a current strong opinion of what's needed? My reading of the thread is that:
If my reading is correct, are there any objections to implementing this, and is someone willing to do the work? I can't see why not, if it simplifies user code and makes things less error prone, with minimal additional runtime overhead. If my reading is incorrect, please let me know how. |
+1 to ensuring the string to end with |
[bump] just to clarify, the idea is to have any call with a string parameter translate into a single item string ARRAY call. the API seems to generally always support both ways AFAIK. doesn't this avoids nul termination and so is more Go'ish, not sure if it might even enable avoiding copying? |
It's unclear to me how an array helps, don't the individual Please can you shed some light on this, perhaps with a code sample (e.g. pick a specific OpenGL call and demonstrate the two alternatives?) |
forget what i said, i seem to have been mis-reading the spec.; i guess i was thinking that
|
I had the same problem with Go strings not being null terminated. Example:
I spent a couple hours debugging my application as it was producing undefined behavior where my shaders would randomly not render anything. The problem is fixed by adding a
Most newcomers like myself to this go-gl API will probably make this mistake. |
Can someone plse clarify the current status in a 1 or 2 liner, because as newbie I'm struggling with the 'createshader' and gl.Strs being null terminated or not issue right now. Thanks. |
@docuys I suggest looking at the examples in https://github.com/go-gl/example. |
lol! dmitshur, I actually did that and managed to get it going a couple of hours before your reply! Thank you very much for the reply in any case! (btw, I am writing in Skycoin's CX. See Skycoin/CX or Skycoin.net) |
O, and yes, I got the shader to compile without adding any 00's (per your link that is). |
However, notice there are 2 different functions used: gl.Str and gl.Strs. I used gl.Strs, so I will have to find out the exact differences. |
Strs func claims to work with go strings,(non null-terminated) but doesn't add x00, and shadersource requires them, if length not specified.
opengl doc for ShaderSource
The text was updated successfully, but these errors were encountered: