Structure.toArray needs to ensure memory is allocated and size
calculated before recalculating memory requirements. This has been
fixed on the trunk.
You can manually do this by calling "size()" prior to calling "toArray
()".
On Jan 22, 2008, at 7:30 AM, Niels van Eijck wrote:
Thanks to Timothy for solving my initial problems. I now run into
another problem where I get an exception using nested Structures:
interface Test extends Library {
class MyNumberPart extends Structure {
public int part;
}
class MyNumber extends Structure {
public int num;
public MyNumberPart[] parts;
public MyNumber() {
parts = (MyNumberPart[])new MyNumberPart().toArray(2);
}
}
int calculateSum(MyNumber[] numbers, int arraySize);
}
My test method:
public void TestMethod() {
MyNumber[] numbers = (MyNumber[])new MyNumber().toArray(2);
numbers[0].num = 4;
numbers[0].parts[0].part = 1;
numbers[0].parts[1].part = 2;
numbers[1].num = 3;
numbers[1].parts[0].part = 3;
numbers[1].parts[1].part = 4;
int sum = Test.calculateSum(numbers);
}
Then I get this exception:
java.lang.IndexOutOfBoundsException: Bounds exceeds available
space : size=12, offset=24
at com.sun.jna.Memory.boundsCheck(Memory.java:149)
at com.sun.jna.Memory.share(Memory.java:90)
at com.sun.jna.Structure.toArray(Structure.java:977)
at com.sun.jna.Structure.toArray(Structure.java:989)
Again, thanks for your help!
regards, Niels.