Bug 101464 - PrimitiveRestartNV inside a render list causes a crash
Summary: PrimitiveRestartNV inside a render list causes a crash
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Mesa core (show other bugs)
Version: 17.0
Hardware: x86-64 (AMD64) All
: medium major
Assignee: mesa-dev
QA Contact: mesa-dev
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-16 08:50 UTC by Olivier Lauffenburger
Modified: 2017-07-07 19:01 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

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.