FloatBuffer.put() bug...

by Patrick » Fri, 23 Jan 2009 04:51:24 GMT


Sponsored Links
 There seems to be a bug where calling FloatBuffer.put() on a buffer
create as such :

ByteBuffer bufferVerts = ByteBuffer.allocateDirect(numVerts * 3 * 4);
bufferVerts.order(ByteOrder.nativeOrder());
m_bufferVerts = bufferVerts.asFloatBuffer();
m_bufferVerts.position(0);

does not properly write. Basically, calling :

m_bufferVerts.put(-0.5f);
m_bufferVerts.put(0.5f);
m_bufferVerts.put(0.0f);

does not give a vert at that location. The vert location is random
(Changes each time I run the app), indicating that put did not write
anything, leaving memory to whatever garbage it initially had.

However, calling

m_bufferVerts.put(0, -0.5f);
m_bufferVerts.put(1, 0.5f);
m_bufferVerts.put(2, 0.0f);

works.

I can keep my own position counter, but since FloatBuffer claims to
have one internally, shouldn't those two pieces of code have the same
result?

--~--~---------~--~----~------------~-------~--~----~



FloatBuffer.put() bug...

by fadden » Fri, 23 Jan 2009 06:53:52 GMT


 


There are some known problems with the 1.0 implementation, e.g.:

   http://code.google.com/p/android/issues/detail?id=1585 

Can you provide a stand-alone class that exercises the problem, with
expected vs. actual output?  (If it's a stand-alone main() we can run
it under a desktop VM and under Dalvik and compare the results.)

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


FloatBuffer.put() bug...

by Patrick » Fri, 23 Jan 2009 10:06:38 GMT


 As a standalone app, it might be difficult, since the problem does not
seem to occur if we look at content of the buffer through java code.
But it does have a problem if openGL tries to access it to render, so
to get the bug requires a lot of code around it.

To get the bug to repro, in the API demos, in Cube.java :

- Remove line 75.
mVertexBuffer.put(vertices);

- After the call to mVertexBuffer.position(0), add the following
code :

        for (int i = 0; i < vertices.length; i ++)
                mVertexBuffer.put(vertices[i]);

Essentially adding vert data one entry at a time, instead of in one
shot.

You'll see the "cube" displayed is not a cube at all. The verts are
messed up. But how it's messed up is different each time you run it.

--~--~---------~--~----~------------~-------~--~----~



FloatBuffer.put() bug...

by Woerf » Mon, 26 Jan 2009 20:15:46 GMT


 When you move that loop behind mVertexBuffer.position(0) you'll pass
the buffer with position at the end in the draw method. You have to
reset the position after you put values into the buffer. If you do
that the demo doesn't show the errors anymore.

If this should actually even work the way you described it, then I
guess the methods that get called later should handle this. To me it
seems like openGL just reads outside the buffer that was passed. I'm
not sure if this should be tolerated.



--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. how can i store a view in a .png file in emulator sdcard

i had created a view and wanted to store it as a image in the sdcard
of the emulator
how can i do this?/?
please tell as soon as possible

-- 

2. Not detecting soft keyboard keypresses

I have an EditText. I have set a OnKeyListener to listen to key
presses.
I get proper info when I use the keyboard in the emulator.
If i try to use the "soft keyboard" I dont receive any events.
Is this behavior normal? If so, How do I get the soft keyboard key
presses?

Cheers,
Earlence

-- 

3. Enabling wifi tethering mode

4. What is Context and what is its use?

5. ActivityManager Pause error

6. Wifi cpu utilization

7. Want to confirm that app is in background due to Home Key press