Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (683)
Games in Android Showcase (196)
games submitted by our members
Games in WIP (750)
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 2985 times)
0 Members and 1 Guest are viewing this topic.
Offline Alfryd

Junior Devvie





« Posted 2009-09-05 19: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?
Offline Riven
Administrator

« JGO Overlord »


Medals: 1228
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2009-09-05 21: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!
Offline Riven
Administrator

« JGO Overlord »


Medals: 1228
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2009-09-05 21: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 Devvie





« Reply #3 - Posted 2009-09-05 21: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 Devvie





« Reply #4 - Posted 2009-09-06 22: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 Devvie





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

buffer.clear() and buffer.flip() don't seem to have any useful effect, I'm afraid...
Offline Riven
Administrator

« JGO Overlord »


Medals: 1228
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2009-09-07 14: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 Devvie





« Reply #7 - Posted 2009-09-07 16: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 Devvie





« Reply #8 - Posted 2009-10-08 18: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.

 
orrenravid (182 views)
2016-07-16 03:57:23

theagentd (252 views)
2016-07-11 14:28:54

Hydroque (335 views)
2016-07-06 05:56:57

Hydroque (487 views)
2016-07-03 08:52:54

GrandCastle (369 views)
2016-07-01 09:13:47

GrandCastle (360 views)
2016-07-01 09:09:45

CopyableCougar4 (415 views)
2016-06-25 16:56:52

Hydroque (397 views)
2016-06-22 02:17:53

SwampChicken (360 views)
2016-06-20 13:22:57

SwampChicken (297 views)
2016-06-20 13:22:49
Making a Dynamic Plugin System
by Hydroque
2016-06-25 00:13:25

Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42

FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17
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!