Bug 101464

Summary: PrimitiveRestartNV inside a render list causes a crash
Product: Mesa Reporter: Olivier Lauffenburger <o.lauffenburger>
Component: Mesa coreAssignee: mesa-dev
Status: RESOLVED FIXED QA Contact: mesa-dev
Severity: major    
Priority: medium    
Version: 17.0   
Hardware: x86-64 (AMD64)   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description Olivier Lauffenburger 2017-06-16 08:50:54 UTC
When using glDrawElements with glPrimitiveRestartIndexNV during the compilation of a render list, there is a crash when Mesa reaches the second restart index of the array.

The reason is that when PrimitiveRestartNV is called internally the first time, save_PrimitiveRestartNV() (in \src\mesa\vbo\vbo_save_api.c) is called. It executes _save_End() and _save_Begin(curPrim), but _save_Begin() is a noop function that merely raises an OpenGL error "Recursive glBegin".
Comment 1 Olivier Lauffenburger 2017-06-21 08:45:09 UTC
I have replaced the content of save_PrimitiveRestartNV() by the following code to make it work:

static void GLAPIENTRY
_save_PrimitiveRestartNV(void)
{
   GLenum curPrim;
   GET_CURRENT_CONTEXT(ctx);

   /* get current primitive mode */
   struct vbo_save_context *save = &vbo_context(ctx)->save;
   if (save->prim_count == 0) return;

   const GLuint i = save->prim_count - 1;

   curPrim = save->prim[i].mode;

   /* restart primitive */
   CALL_End(GET_DISPATCH(), ());
   vbo_save_NotifyBegin(ctx, (curPrim | VBO_SAVE_PRIM_WEAK
	   | VBO_SAVE_PRIM_NO_CURRENT_UPDATE));
}

Contrarily to what is stated, ctx->Driver.CurrentSavePrimitive is not correctly set before _save_PrimitiveRestartNV() is called, whence this intricate code to get the current primitive mode...
Comment 2 Brian Paul 2017-07-07 19:01:36 UTC
I've committed a patch based on your suggestion (commit f5c8bb1e00f358e05ed21f8ed69c9fc3803bf95f) plus an patch for another failure case (commit 9ac55e8219e1f6abeab3c779c8fe710c2bc25f2b).
Closing this bug.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.