Closed tjfontaine closed 12 years ago
I'll double post this, I added some fprintf's since I couldn't convince gdb to let me break into ReadPointer and saw
ReadPointer 0x101816b00 + 0 -- 0x101816b00
Reinterpret_Cast 0x100a1a070
track 0 address 0x100a1a070
ReadPointer 0x101816b00 + 28 -- 0x101816b1c
Reinterpret_Cast 0xb7150000000001
track 1 address 0xb7150000000000
The proper way to do this is
var info = new Buffer(ref.sizeof.pointer);
var tracks = lib.libvlc_media_get_tracks_info(self.instance, info);
info = info.readPointer(0, TrackInfo.size * tracks);
for (i = 0; i < tracks; i++) {
ptr = ref.get(info, i * TrackInfo.size, TrackInfo);
}
In my libvlc bindings I need to call a function which allocates an array, I have no idea how large the array will be until after the function returns and I'm responsible for freeing the data (but we can tackle that in another ticket)
Here's the code, it works for the first item, the second item's address is out of whack and therefore reading in the struct predictably segfaults with exec_bad_access
output
For comparison here's C code of the same procedure, and it's output when processing the same file
You can see that the first struct for js matches the first struct returned by the c code, but instead of a reasonable 0x1C offset the second is positioned way out in the nether regions.