Error with vertex buffers.

I think that’s the problem anyway. All I get out as an error message in eclipse is this:

[quote]Invalid memory access of location 01678824 eip=1acda200
[/quote]
The meat of the code is here:


  private static void flushGeometry() {
    if (numPolys == 0) return ;
    GL11.glMatrixMode(GL11.GL_MODELVIEW) ;
    GL11.glLoadIdentity() ;
    textBuffer.rewind() ;
    normBuffer.rewind() ;
    vertBuffer.rewind() ;
    huesBuffer.rewind() ;
    textBuffer.put(textArray, 0, numPolys * 6) ;
    normBuffer.put(normArray, 0, numPolys * 9) ;
    vertBuffer.put(vertArray, 0, numPolys * 9) ;
    huesBuffer.put(huesArray, 0, numPolys * 9) ;
    textBuffer.rewind() ;
    normBuffer.rewind() ;
    vertBuffer.rewind() ;
    huesBuffer.rewind() ;
    GL11.glTexCoordPointer(2, GL11.GL_FLOAT, textBuffer) ;
    GL11.glNormalPointer(GL11.GL_FLOAT, normBuffer) ;
    GL11.glVertexPointer(3, GL11.GL_FLOAT, vertBuffer) ;
    GL11.glColorPointer(3, GL11.GL_FLOAT, huesBuffer) ;
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, numPolys * 3) ;
    numPolys = 0 ;
  }

If I comment out the second-last line (the call to drawArrays,) there’s no error (but of course, nothing renders.) Any clue what’s happening here?

buffer.clear();
buffer.put(…);
buffer.flip();

Update:
I realise that can’t trigger the crash… I’ll try to make a more useful post later

Did you disable all unused client states properly?

Say, if you enabled texcoord-buffers (earlier) in texunit 2 (multitexturing) and you don’t specify a glTexcoordBuffer for texunit 2, you can/will get bufferoverflows.

I don’t recall using multitexturing at any point, and I’m pretty sure I enabled all the relevant client states- pointers for colour/vertex/normal/and UV data.

Well, maybe you could help with a related problem. I’ve tried out a very basic demo program for drawing using vertex arrays, and I can’t seem to get anything display on-screen. This is the entirety of the relevant code:


package test ;
import java.nio.FloatBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.* ;


public class BasicTest {
  
  
  public static void main (String args[]) {
    BasicTest test = new BasicTest() ;
    test.init() ;
  }
  
  void init() {
    setDisplayMode() ;
    doRenderLoop() ;
  }

  private static FloatBuffer
    vertBuffer = BufferUtils.createFloatBuffer(9) ;
  
  private void doRenderLoop() {
    while (true) {
      
      GL11.glMatrixMode(GL11.GL_PROJECTION) ;
      GL11.glLoadIdentity() ;
      GL11.glOrtho(-2, 2,  -2, 2,  -1, 1) ;
      GL11.glMatrixMode(GL11.GL_MODELVIEW) ;
      GL11.glLoadIdentity() ;
      
      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY) ;
      vertBuffer.rewind() ;
      vertBuffer.put(new float[] { 0, 0, 0,  1, 0, 0,  1, 1, 0 }) ;
      vertBuffer.rewind() ;
      GL11.glVertexPointer(3, GL11.GL_FLOAT, vertBuffer) ;
      GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3) ;
      Display.update() ;
      
      if (Display.isCloseRequested()) {
        Display.destroy() ;
        System.exit(0) ;
      }
    }
  }
  

  private boolean setDisplayMode() {
    try {
      DisplayMode chosen = Display.getAvailableDisplayModes()[0] ;
      final int
        wide = chosen.getWidth(),
        high = chosen.getHeight() ;
      Display.setDisplayMode(chosen) ;
      Display.setFullscreen(false) ;
      Display.create() ;
    }
    catch (Exception e) {
      e.printStackTrace() ;
    }
    return false ;
  }
}

I’ll also try playing around with those buffer methods you suggested. …Thanks either way.

EDIT: Whoops, slight ommision in the code- Display.update(). I still don’t see anything, though…

buffer.clear() and buffer.flip() don’t seem to have any useful effect, I’m afraid…

glClear the colorbuffer to some color

specify a drawing color with glColor3f

Actually, I’ve been able to narrow down the problem a bit. Like you said, LWJGL apparently expects you to clear() the buffer before you put(), then flip(), rather than rewind()… that lets me render basic geometry, colours, and lighting, no problem now.

The crash only happens when I try to enable textures, but I"m still at a loss as to why…

Fixed now! I never found out exactly what the problem was, but I think it had something to do with the glDrawArrays method, basically, putting in 0 instead of GL.GL_FLOAT seemed to clear things up. (Also, I wasn’t using native buffers correctly for lighting.) Anyways- thanks for the help.