GeomVertexRewriter Reading Bad Values

I’m trying to use GeomVertexRewriter to update some values and I need to read values from the array at the same time, which is why I’m using GeomVertexRewriter. I’ve found that if I try to read values (getData1i) from locations I’ve already written (addData1i), it will sometimes fail.

Here’s some code I’m using to test with:

origstart = nextTriangleIndex
for i in range(5):
    indexrewriter.setRow(nextTriangleIndex)
    print 'setting row', indexrewriter.getWriteRow(), 'to', i
    indexrewriter.addData1i(i)
    nextTriangleIndex += 1
indexrewriter.setRow(origstart)
for i in range(5):
    print 'reading row', indexrewriter.getReadRow(),
    val = indexrewriter.getData1i()
    print 'got value', val
    assert(val == i)

This works fine and prints:

setting row 5682 to 0
setting row 5683 to 1
setting row 5684 to 2
setting row 5685 to 3
setting row 5686 to 4
reading row 5682 got value 0
reading row 5683 got value 1
reading row 5684 got value 2
reading row 5685 got value 3
reading row 5686 got value 4

But if I change range(5) to something larger, e.g. range(200), I get:

setting row 5682 to 0
setting row 5683 to 1
setting row 5684 to 2
setting row 5685 to 3
setting row 5686 to 4
...
...
setting row 5880 to 198
setting row 5881 to 199
reading row 5682 got value 22752
    assert(val == i)
AssertionError

Any idea what I’m doing wrong?

Update:
If I create a new GeomVertexReader each time I want to read a value like this:

indexreader = GeomVertexReader(indexdata)
indexreader.setColumn(0)
indexreader.setRow(vals[1])
oldval = indexreader.getData1i()
del indexreader

it works, but I think it’s a lot slower than if I could use the GeomVertexRewriter.

Hmm, would you mind testing this in the buildbot version? I recently fixed a few minor bugs in the GeomVertexData that could have caused this symptom, and I’d like to know if that’s the same thing you’re seeing.

David

Sure. It looks like the panda3d1.8 package in the ubuntu archive is updated daily. If I install that, is that the latest build?

Um, yes? I’m not 100% sure about that, but it sounds likely.

David

I installed this maverick-dev ubuntu package:

and the invalid memory locations with GeomVertexRewriter go away. It’s also much faster than my workaround that creates a new GeomVertexReader every time I need to read a location.

Another question - I’m seeing memory go up and up as I add and remove data from my vertex arrays. Are they supposed to be garbage collected when arrays are copied? I’m not keeping any references around (it’s function scope), so any idea why memory isn’t being reclaimed?

There is an internal cache used for rendering, which perhaps you’re seeing fill up. It’s quite large by default. Try setting:

geom-cache-size 0

to see if the memory stops accumulating. (If this works, though, you should probably remove that setting, safe in the knowledge that it’s a cache and not a leak–you’ll want the performance benefit of the caching.)

David

That did it. Thanks!