Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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  
  FloatBuffers  (Read 2293 times)
0 Members and 1 Guest are viewing this topic.
Offline karatemarkel

Junior Member





« Posted 2004-03-21 11:27:14 »

This has been pissing me off all weekend, to say the least  Cheesy

I'm working through the red book and I'm trying to implement lighting on a object I've loaded, looking through the lwjgl source it appears I have to use Floatbuffers to get this working, so a done a bit of searching as I had no idea how to create them.

Anyhoo, I found this bit of code (and a nice debate on the subject  Grin) over at the lwjgl forums, however I still can't get them to work, the console just spits out a big error log if I use this method to create a Floatbuffer, any ideas what I'm doing wrong here?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
float[] matSpec       = new float[] {1f, 1f, 1f, 1f };
FloatBuffer mat_spec   = createFloatBuffer(matSpec);

        FloatBuffer createFloatBuffer(float[] array)
      {
            FloatBuffer fbuff = ByteBuffer.allocateDirect(16)
            .order(ByteOrder.nativeOrder()).asFloatBuffer();
            fbuff.put(array).flip();
            return fbuff;
      }

cheers all.
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2004-03-21 12:28:44 »

What error?
We have a new Util class in LWJGL that creates native buffers of various sorts for you as well Smiley It's in CVS.

Cas Smiley

Offline karatemarkel

Junior Member





« Reply #2 - Posted 2004-03-21 13:35:12 »

Here's the error, seems a bit odd  Smiley
If I comment out all the functions that use floatbuffers, it runs fine.

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  
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x2E76725
Function=Java_org_lwjgl_input_Keyboard_nPoll+0x5
Library=C:\j2sdk1.4.2_01\jre\lib\ext\lwjgl.dll

Current Java thread:
      at org.lwjgl.input.Keyboard.nPoll(Native Method)
      at org.lwjgl.input.Keyboard.poll(Keyboard.java:338)
      at ftw.processKeyboard(ftw.java:195)
      at ftw.mainLoop(ftw.java:156)
      at ftw.execute(ftw.java:116)
      at ftw.main(ftw.java:523)

Dynamic libraries:
0x00400000 - 0x00406000       C:\j2sdk1.4.2_01\bin\java.exe
0x77F50000 - 0x77FF7000       C:\WINDOWS\System32\ntdll.dll
0x77E60000 - 0x77F46000       C:\WINDOWS\system32\kernel32.dll
0x77DD0000 - 0x77E5D000       C:\WINDOWS\system32\ADVAPI32.dll
0x78000000 - 0x7807E000       C:\WINDOWS\system32\RPCRT4.dll
0x77C10000 - 0x77C63000       C:\WINDOWS\system32\MSVCRT.dll
0x08000000 - 0x08136000       C:\j2sdk1.4.2_01\jre\bin\client\jvm.dll
0x77D40000 - 0x77DCC000       C:\WINDOWS\system32\USER32.dll
0x77C70000 - 0x77CB0000       C:\WINDOWS\system32\GDI32.dll
0x76B40000 - 0x76B6C000       C:\WINDOWS\System32\WINMM.dll
0x10000000 - 0x10007000       C:\j2sdk1.4.2_01\jre\bin\hpi.dll
0x00390000 - 0x0039E000       C:\j2sdk1.4.2_01\jre\bin\verify.dll
0x003A0000 - 0x003B8000       C:\j2sdk1.4.2_01\jre\bin\java.dll
0x003C0000 - 0x003CD000       C:\j2sdk1.4.2_01\jre\bin\zip.dll
0x02E60000 - 0x02EC0000       C:\j2sdk1.4.2_01\jre\lib\ext\lwjgl.dll
0x72280000 - 0x722A8000       C:\WINDOWS\System32\DINPUT.dll
0x5ED00000 - 0x5EDC6000       C:\WINDOWS\System32\OPENGL32.dll
0x68B20000 - 0x68B3E000       C:\WINDOWS\System32\GLU32.dll
0x51000000 - 0x51047000       C:\WINDOWS\System32\DDRAW.dll
0x73BC0000 - 0x73BC6000       C:\WINDOWS\System32\DCIMAN32.dll
0x77C00000 - 0x77C07000       C:\WINDOWS\system32\VERSION.dll
0x5AD70000 - 0x5ADA4000       C:\WINDOWS\System32\uxtheme.dll
0x74720000 - 0x74764000       C:\WINDOWS\System32\MSCTF.dll
0x69500000 - 0x6986B000       C:\WINDOWS\System32\nvoglnt.dll
0x688F0000 - 0x688F9000       C:\WINDOWS\System32\HID.DLL
0x76670000 - 0x76757000       C:\WINDOWS\System32\SETUPAPI.DLL
0x76C90000 - 0x76CB2000       C:\WINDOWS\system32\imagehlp.dll
0x6D510000 - 0x6D58D000       C:\WINDOWS\system32\DBGHELP.dll
0x76BF0000 - 0x76BFB000       C:\WINDOWS\System32\PSAPI.DLL

Heap at VM Abort:
Heap
 def new generation   total 576K, used 377K [0x10010000, 0x100b0000, 0x104f0000)
  eden space 512K,  61% used [0x10010000, 0x1005e470, 0x10090000)
  from space 64K,  99% used [0x100a0000, 0x100afff8, 0x100b0000)
  to   space 64K,   0% used [0x10090000, 0x10090000, 0x100a0000)
 tenured generation   total 1408K, used 75K [0x104f0000, 0x10650000, 0x14010000)
   the space 1408K,   5% used [0x104f0000, 0x10502e38, 0x10503000, 0x10650000)
 compacting perm gen  total 4096K, used 1434K [0x14010000, 0x14410000, 0x18010000)
   the space 4096K,  35% used [0x14010000, 0x14176910, 0x14176a00, 0x14410000)

Local Time = Sun Mar 21 15:25:26 2004
Elapsed Time = 0
#
# The exception above was detected in native code outside the VM
#
# Java VM: Java HotSpot(TM) Client VM (1.4.2_01-b06 mixed mode)
#


Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #3 - Posted 2004-03-21 20:17:49 »

that crash is a bit odd, and especially together with the example code you posted since they're not related at all. Have you enabled buffering or translation on the keyboard?

Offline karatemarkel

Junior Member





« Reply #4 - Posted 2004-03-22 11:57:27 »

The code I'm using is pretty much the same as the FullScreenWindowedTest, so I've just been relying on that for keyboard creation, haven't looked at that area of lwjgl yet.

Just found out what line of the code is causing the problems after a bit of commenting out fun Smiley

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
float[] mat_spec       = new float[] {1f, 1f, 1f, 1f };
float[] mat_shine       = new float[] { 50f };
FloatBuffer matSpec;
FloatBuffer matShine;

//then in the constructor, using the same method as above

matSpec = createFloatBuffer(mat_spec);
matShine = createFloatBuffer(mat_shine);

//in glInit()
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, matSpec);        
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SHININESS, matShine);//if I comment out this line the prog runs fine


So there seems to be a problem if I create a float buffer from an array of zero length, why it starts banging on about the keyboard I have no idea.
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2004-03-22 12:42:49 »

Hm, looks like we have a memory clobbering problem going on there causing a spurious crash elsewhere. The 0 length buffer is a clue.

Cas Smiley

Offline karatemarkel

Junior Member





« Reply #6 - Posted 2004-03-22 18:12:13 »

Bummer, I was hoping it was something I'd done  Smiley

Just a few more things that may be of help, in the initialize method, the order was as follows,

findDisplayMode();      
Window.create();
glInit();                              
Keyboard.create();

I changed this around so that glInit was the last method to be called, and the code ran without any errors, but the lighting was none existent, as the object loaded was drawn in solid colour.

Ahh, the joy of ByteBuffers  Grin

Good look fixing it.

Wink
Offline karatemarkel

Junior Member





« Reply #7 - Posted 2004-03-30 18:35:20 »

Any news on this problem, has it been fixed yet or is there a work around?

Don't want to sound too pushy or impatient (sure your all very busy), it's just meant that I've had to tinker about in jogl whilst learning some simple lighting, it's just not the same with jogl Smiley

I'm not even sure if it's something I'll be using when I finally get around to writing a game, but as far as I can see from *flicking* through the lighting chapter in the red book '0' length arrays seem to be used quite a bit for setting up lighting and it would be a pity if this problem was around for longer than necessary.

Btw, has anyone else had this problem lwjgl?, if not I'm getting a new gfx card this weekend  Grin

Cheers
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #8 - Posted 2004-03-30 20:09:47 »

Quote
Any news on this problem, has it been fixed yet or is there a work around?

Well, Elias committed a patch against Keyboard, so that it always checks the size of the supplied buffer when created. However this is an unrelated issue to what you have posted.

Since you haven't told us what
Quote
matShine = createFloatBuffer(mat_shine);

exactly does, I am fairly certain that any buffer issues from using you createFloatBuffer method lies in that method, because it fails to rewind the buffer.

I typically use these two methods:
Quote
 /**
  * Creates a float buffer to hold specified floats
  * - strictly a utility method
  *
  * @param size how many floats to contain
  * @return created FloatBuffer
  */
 protected FloatBuffer createFloatBuffer(int size) {
   ByteBuffer temp = ByteBuffer.allocateDirect(4 * size);
   temp.order(ByteOrder.nativeOrder());

   return temp.asFloatBuffer();
 }
 
 /**
  * Creates a float buffer to hold specified float array
  * - strictly a utility method
  *
  * @param array to hold
  * @return created FloatBuffer
  */
 protected FloatBuffer createFloatBuffer(float[] data) {
   FloatBuffer temp = createFloatBuffer(data.length).put(data);
   temp.flip();
   return temp;
 }


do they help?

if not, could you please post the full code, alternatively send it to matzon@lwjgl.org

Offline karatemarkel

Junior Member





« Reply #9 - Posted 2004-03-31 14:26:04 »

Hi Matzon, I just tried using your methods to create FloatBuffers (rather than the method I posted in the first post of this thread) but the problem is still there.
You can get the source here: http://mysite.freeserve.com/shooterspace/testFB.java

As I mentioned, the bulk of the code is from FullScreenWindowedTest.java, I have been relying on that for window and keyboard creation.

There's not much I can add that I haven't pointed out already, the offending line of code in commented on in the glInit() method.

Cheers Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline elias

Senior Member





« Reply #10 - Posted 2004-03-31 14:42:12 »

I tried it on my SuSE 9 (after fixing some compile compile errors against current CVS) and it gave this error:

java.lang.IllegalArgumentException: Number of remaining buffer elements is 1, must be at least 4
       at org.lwjgl.opengl.BufferChecks.checkBuffer(Unknown Source)
       at org.lwjgl.opengl.BufferChecks.checkBuffer(Unknown Source)
       at org.lwjgl.opengl.GL11.glMaterial(Unknown Source)
       at testFB.glInit(testFB.java:232)
       at testFB.initialize(testFB.java:102)
       at testFB.execute(testFB.java:81)
       at testFB.main(testFB.java:303)

Then I padded the offending buffer so it became 4 floats instead of one, and then it ran  without problems (I saw a gray box of some kind).

- elias

Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #11 - Posted 2004-03-31 14:51:46 »

yeah, what he said Smiley

Offline karatemarkel

Junior Member





« Reply #12 - Posted 2004-03-31 15:30:45 »

Odd Cheesy, funnily enough I've never had that error report but I have tried that hack before and it did run, but the lighting was always very dark. But yep, that seems to do the trick, in the testFB example anyway.

The none problem now is that my old example (which the testFB was copied from) is *still* displaying the object incorrectly lit, even though all the gl code and buffer creation code is exactly the same?

I think I'll browse through them both later on, see if I can spot what the problem is/was, damn curiosity Smiley

Cheers guys  Smiley
Offline karatemarkel

Junior Member





« Reply #13 - Posted 2004-03-31 16:06:07 »

Doh, if anyone's interested I just found out why the original was version (after hack) was incorrectly lit and all dark'n'stuff, I was scaling the Modelview matrix  Roll Eyes

Btw, are all 0 length buffers going to be created like this? It's not a big problem but I can see it causing some confusion for newcomers like myself, so it might be worth mentioning in the FAQ, but then again if the new version has the problem caught and reported with an exception, no problem.

Cheers Smiley
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #14 - Posted 2004-03-31 17:33:02 »

Crash now fixed.
That's what you get for using asserts in the wrong situation :/

Cas Smiley

Offline karatemarkel

Junior Member





« Reply #15 - Posted 2004-04-01 11:56:03 »

Quote
Crash now fixed.
That's what you get for using asserts in the wrong situation :/

Cas Smiley


I was with you right up until you mentioned "asserts", but now I'm all lost  Smiley
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.

Riven (12 views)
2014-07-29 18:09:19

Riven (8 views)
2014-07-29 18:08:52

Dwinin (9 views)
2014-07-29 10:59:34

E.R. Fleming (26 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!