Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFix Unity plugin crash and add debug assertions #197
Closed
+17
−0
Conversation
|
Cool, thanks for digging in. My Metal changes in my |
|
Oh cool, sounds good! |
|
@toolness I just pushed the Metal changes. Want to try again? |
|
Yes, this works perfectly and logs no weird GL warnings either!! Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
toolness commentedJun 15, 2019
Okay, I did some investigating into #178 and discovered a few things.
Right now, the Unity plugin instantiates a
Rendereronly once and reuses it every frame (instantiating one every frame seemed excessive, but I can alter this behavior if you want). However, as of acf666b, thequad_vertex_indices_bufferis only bound toGL_ELEMENT_ARRAY_BUFFERwhen the renderer is instantiated--not every frame.This seems fine if we assume that other GL code hasn't changed the binding since the renderer was instantiated. I think this is what's going on with the Unity plugin: because the plugin has to share the same GL context with Unity's own renderer, it's likely that Unity is changing the
GL_ELEMENT_ARRAY_BUFFERbinding when it's doing its own drawing.Furthermore, the stack trace mentioned at #178 (comment) is happening because the
indicesparameter ofglDrawElementsInstanced()is defined in a confusing way: ifGL_ELEMENT_ARRAY_BUFFERis bound, then it's interpreted as an offset index into an array (which is how we're using it), but if it's not bound anymore--as is the case when running in Unity--it's interpreted as a pointer value, in which case the program will segfault.I'm not really sure what the best solution is here. I've added a debug assertion called
assert_element_array_buffer_is_bound()to make us panic with a helpful error instead of causing a null pointer dereference, which will hopefully help us catch errors like this in the future, but I'm not sure what the best strategy to ensure the proper buffer binding is. If we only plan to ever bindquad_vertex_positions_buffertoGL_ELEMENT_ARRAY_BUFFERthen we could just bind it once duringRenderer::begin_scene(), but otherwise we may need to bind it immediately before we callglDrawElementsInstanced()or anything else that needs it.For now I've just done the minimal possible required to make the minimal canvas example work in the Unity plugin, but it's possible the ideal solution is something different. I'm open to suggestions, this PR is really just my way of starting the conversation.