Fixed bounds checking to work with .sliced mapped objects.

This commit is contained in:
Ioannis Tsakpinis 2011-07-12 13:44:13 +00:00
parent 585549f1f1
commit fa31e0f9cb
2 changed files with 19 additions and 2 deletions

View File

@ -89,17 +89,34 @@ public class MappedObjectTests1 {
vecs.view = 0;
}
// test bound check
// test bounds checking
{
assert (vecs.view == 0);
try {
vecs.view = 49;
assert vecs.view == 49;
vecs.view = 0;
vecs.view = 50;
System.out.println("org.lwjgl.util.mapped.Checks is false or there is a bug in bounds checking.");
vecs.view = 0;
} catch (IndexOutOfBoundsException e) {
// expected, ignore
}
assert (vecs.view == 0);
try {
vecs.view = 10;
MappedFloat vecs2 = vecs.slice();
vecs.view = 0;
vecs2.view = 39;
assert vecs2.view == 39;
vecs2.view = 40;
System.out.println("org.lwjgl.util.mapped.Checks is false or there is a bug in bounds checking.");
} catch (IndexOutOfBoundsException e) {
// expected, ignore
}
}
// test dup

View File

@ -97,7 +97,7 @@ public class MappedObject {
}
final void checkAddress(final long address) {
if ( preventGC.capacity() < (address + stride - baseAddress) )
if ( preventGC.capacity() < (address - MappedObjectUnsafe.getBufferBaseAddress(preventGC) + stride) )
throw new IndexOutOfBoundsException();
}