Quote Originally Posted by User137
Quote Originally Posted by M109uk
I have changed the code to use pointers instead, however i am getting an access violation error when i add data to the pointer (around the 20th item to be added)

am i doing something wrong...

heres the code im using:
[pascal]//---- add data to pointers
procedure AddToMem(Cloud: TVolumetricCloud; v2: TVector2f; v3: TVector3f; v4a,v4b: TVector4f);
begin
Cloud.vBuffer^ := v3;
Inc(Cloud.vBuffer); <-------------- ERROR HERE
Cloud.cBuffer^ := v4a;
Inc(Cloud.cBuffer);
Cloud.IcBuffer^ := v4b;
Inc(Cloud.IcBuffer);
Cloud.tBuffer^ := v2;
Inc(Cloud.tBuffer);
end;[/pascal]
im sure i've missed something really dumb..
Propably That code is trying to increase pointers by 1 like you showed in class definition. Try
Inc(Cloud.vBuffer^);
etc...
*sigh* I wasn't really thinking clearly when i wrote that :lol: procedure AddToMem says something about what you want to do in it... Original procedure propably did something only C can do, now in pascal you likely need a new approach completely. So.. i think plan is to add 1 vertex to array and same time make preparations so next call will also add 1 after it. Need to make sure the array is resized and update some Count variable, then assign parameter info to vBuffer[Count-1] that is last index.

And about sorting, this is 1 efficient structure:
[pascal]for i:=0 to Count-2 do
for j:=i+1 to Count-1 do
// Compare here and swap if needed

// Notice how it ignores all useless calls, like this way would make final compare to item itself, not to mention amount of extra calls it there wasn't i+1
for i:=0 to Count-1 do
for j:=i+1 to Count-1 do[/pascal]
But still there exist faster ways, i'm not very much familiarized with them and they are propably made for certain kinds of arrays.

Edit: Ok i take my words back a bit, it is all propably possible in pascal too, but this line
Inc(Cloud.vBuffer);
was actually made to increase the pointer (the place that array starts, note you would need to revert it backwards too if want to use it), and likely not by 1, but 12 that is sizeof(TVector3f). Maybe something like (i'm not sure):
pointer(Cloud.vBuffer):=pointer(integer(Cloud.vBuf fer)+12);