Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (428)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Error with vertex buffers.  (Read 2239 times)
0 Members and 1 Guest are viewing this topic.
Offline Alfryd

Junior Member





« Posted 2009-09-05 21:15:32 »

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

The meat of the code is here:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
  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?
Online Riven
« League of Dukes »

JGO Overlord


Medals: 612
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2009-09-05 23:01:37 »

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

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Online Riven
« League of Dukes »

JGO Overlord


Medals: 612
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2009-09-05 23:22:17 »

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.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Alfryd

Junior Member





« Reply #3 - Posted 2009-09-05 23:37:35 »

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.
Offline Alfryd

Junior Member





« Reply #4 - Posted 2009-09-07 00:13:06 »

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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
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...
Offline Alfryd

Junior Member





« Reply #5 - Posted 2009-09-07 08:03:27 »

buffer.clear() and buffer.flip() don't seem to have any useful effect, I'm afraid...
Online Riven
« League of Dukes »

JGO Overlord


Medals: 612
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2009-09-07 16:24:57 »

glClear the colorbuffer to some color

specify a drawing color with glColor3f

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Alfryd

Junior Member





« Reply #7 - Posted 2009-09-07 18:54:32 »


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...
Offline Alfryd

Junior Member





« Reply #8 - Posted 2009-10-08 20:50:39 »

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.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (79 views)
2014-04-15 18:08:23

BurntPizza (70 views)
2014-04-15 03:46:01

UprightPath (81 views)
2014-04-14 17:39:50

UprightPath (66 views)
2014-04-14 17:35:47

Porlus (82 views)
2014-04-14 15:48:38

tom_mai78101 (106 views)
2014-04-10 04:04:31

BurntPizza (166 views)
2014-04-08 23:06:04

tom_mai78101 (262 views)
2014-04-05 13:34:39

trollwarrior1 (212 views)
2014-04-04 12:06:45

CJLetsGame (221 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!