fix memory access error in vbo_bind_vertex_list
[mesa.git] / src / mesa / vbo / vbo_save_api.c
index f339436f84c3b7e046e80ad33fb106c38a190f7a..f62be5c14cf4bb7960354998c52fb164861fa072 100644 (file)
@@ -67,19 +67,23 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
-#include "glheader.h"
-#include "context.h"
-#include "dlist.h"
-#include "enums.h"
-#include "macros.h"
-#include "api_validate.h"
-#include "api_arrayelt.h"
-#include "vtxfmt.h"
-#include "dispatch.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/dlist.h"
+#include "main/enums.h"
+#include "main/macros.h"
+#include "main/api_validate.h"
+#include "main/api_arrayelt.h"
+#include "main/vtxfmt.h"
+#include "glapi/dispatch.h"
 
 #include "vbo_context.h"
 
 
+#ifdef ERROR
+#undef ERROR
+#endif
+
 
 /*
  * NOTE: Old 'parity' issue is gone, but copying can still be
@@ -198,7 +202,7 @@ static GLfloat *map_vertex_store( GLcontext *ctx, struct vbo_save_vertex_store *
    assert(!vertex_store->buffer);
    vertex_store->buffer = (GLfloat *)ctx->Driver.MapBuffer(ctx, 
                                                           GL_ARRAY_BUFFER_ARB, /* not used */
-                                                          GL_STATIC_DRAW_ARB, /* not used */
+                                                          GL_WRITE_ONLY, /* not used */
                                                           vertex_store->bufferobj); 
 
    assert(vertex_store->buffer);
@@ -598,8 +602,6 @@ do {                                                                \
    if (save->active_sz[A] != N)                                \
       save_fixup_vertex(ctx, A, N);                            \
                                                                \
-   _mesa_printf("Attr %d, sz %d: %f %f %f %f\n", A, N, V0, V1, V2, V3 );       \
-                                                               \
    {                                                           \
       GLfloat *dest = save->attrptr[A];                        \
       if (N>0) dest[0] = V0;                                   \
@@ -837,10 +839,15 @@ static void GLAPIENTRY _save_OBE_DrawArrays(GLenum mode, GLint start, GLsizei co
    if (!_mesa_validate_DrawArrays( ctx, mode, start, count ))
       return;
 
+   _ae_map_vbos( ctx );
+
    vbo_save_NotifyBegin( ctx, mode | VBO_SAVE_PRIM_WEAK );
+
    for (i = 0; i < count; i++)
        CALL_ArrayElement(GET_DISPATCH(), (start + i));
    CALL_End(GET_DISPATCH(), ());
+
+   _ae_unmap_vbos( ctx );
 }
 
 /* Could do better by copying the arrays and element list intact and
@@ -855,6 +862,11 @@ static void GLAPIENTRY _save_OBE_DrawElements(GLenum mode, GLsizei count, GLenum
    if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices ))
       return;
 
+   _ae_map_vbos( ctx );
+
+   if (ctx->Array.ElementArrayBufferObj->Name)
+      indices = ADD_POINTERS(ctx->Array.ElementArrayBufferObj->Pointer, indices);
+
    vbo_save_NotifyBegin( ctx, mode | VBO_SAVE_PRIM_WEAK );
 
    switch (type) {
@@ -876,6 +888,8 @@ static void GLAPIENTRY _save_OBE_DrawElements(GLenum mode, GLsizei count, GLenum
    }
 
    CALL_End(GET_DISPATCH(), ());
+
+   _ae_unmap_vbos( ctx );
 }
 
 static void GLAPIENTRY _save_OBE_DrawRangeElements(GLenum mode,
@@ -1097,7 +1111,7 @@ static void _save_current_init( GLcontext *ctx )
       save->current[i] = ctx->ListState.CurrentAttrib[j];
    }
 
-   for (i = VBO_ATTRIB_FIRST_MATERIAL; i <= VBO_ATTRIB_MAT_FRONT_AMBIENT; i++) {
+   for (i = VBO_ATTRIB_FIRST_MATERIAL; i <= VBO_ATTRIB_LAST_MATERIAL; i++) {
       const GLuint j = i - VBO_ATTRIB_FIRST_MATERIAL;
       ASSERT(j < MAT_ATTRIB_MAX);
       save->currentsz[i] = &ctx->ListState.ActiveMaterialSize[j];