02-22-2005, 07:36 PM
The following indexing code crashes (can't read memory error):
But doesn't with a minor change to print the values as they're being set:
What's wrong? :o
Code:
Type Vert
x As Single
y As Single
z As Single
End Type
Type Tri
verts(2) As Vert
End Type
Type Object
numoftris As Integer
tris As Tri Ptr
End Type
Dim obj As Object
With obj
.numoftris = 7
.tris = Allocate(.numoftris * Len(Tri))
For i = 0 To .numoftris
For v = 0 To 2
.tris[i].verts(v).x = Rnd * 23
.tris[i].verts(v).y = Rnd * 75
.tris[i].verts(v).z = Rnd * 51
Next v
Next i
End With
Print obj.numoftris, obj.tris[0].verts(0).y '<- Error here
Sleep
But doesn't with a minor change to print the values as they're being set:
Code:
Type Vert
x As Single
y As Single
z As Single
End Type
Type Tri
verts(2) As Vert
End Type
Type Object
numoftris As Integer
tris As Tri Ptr
End Type
Dim obj As Object
With obj
.numoftris = 7
.tris = Allocate(.numoftris * Len(Tri))
For i = 0 To .numoftris
For v = 0 To 2
.tris[i].verts(v).x = Rnd * 23
.tris[i].verts(v).y = Rnd * 75
.tris[i].verts(v).z = Rnd * 51
Print .tris[i].verts(v).x '<- Change
Next v
Next i
End With
Print obj.numoftris, obj.tris[0].verts(0).y '<- Reads fine with print in loop
Sleep
What's wrong? :o