Fix potential error on vector property source.
This commit is contained in:
@@ -951,16 +951,22 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class VectorSrc : PropSrc.FixedBuffer {
|
public unsafe class VectorSrc : PropSrc.FixedBuffer {
|
||||||
|
const int MAX_DIMENSION = 8;
|
||||||
protected readonly Func<Vector> _cb;
|
protected readonly Func<Vector> _cb;
|
||||||
public VectorSrc(Func<Vector> cb) : base(PdtInternalType.Vector, 8 * sizeof(float) + sizeof(int)) { _cb = cb; }
|
public VectorSrc(Func<Vector> cb) : base(PdtInternalType.Vector, MAX_DIMENSION * sizeof(float) + sizeof(int)) {
|
||||||
protected override unsafe void InternalGet() {
|
_cb = cb;
|
||||||
|
fixed (byte* rptr = buf) {
|
||||||
|
var ptr = (float*)rptr;
|
||||||
|
*(int*)(ptr + MAX_DIMENSION) = PdtInternalType.Number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override void InternalGet() {
|
||||||
var v = _cb();
|
var v = _cb();
|
||||||
if (v.Dimension > 8) throw new NotSupportedException("Vector dimension too large");
|
if (v.Dimension > MAX_DIMENSION) throw new NotSupportedException("Vector dimension too large");
|
||||||
fixed (byte* rptr = buf) {
|
fixed (byte* rptr = buf) {
|
||||||
var ptr = (float*)rptr;
|
var ptr = (float*)rptr;
|
||||||
v.ToArray(ptr);
|
v.ToArray(ptr);
|
||||||
*(int*)(ptr + v.Dimension) = PdtInternalType.Number;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user