Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-14 Thread Sven Barth via fpc-pascal
Am 10.09.2022 um 01:41 schrieb James Richters: I thought I would make my own IncArray() function: Procedure IncArray(Var TheArray); Begin SetLength(TheArray,Length(TheArray)+1); End; But I get a 'Type Mismatch' Any ideas how this could be done? Is this even possible without specifying

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-09 Thread James Richters via fpc-pascal
>With FPC 3.2.0 and newer you can do "Concat(MyArray, [TheNewElement])" or (if >modeswitch ArrayOperators is active) "MyArray := MyArray + [TheNewElement]". I have a lot of arrays of records, but I just build the record into the array elements, like this:

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-09 Thread Sven Barth via fpc-pascal
Luca Olivetti via fpc-pascal schrieb am Fr., 9. Sep. 2022, 15:29: > I don't know if it is more or less efficient than using a dynamic array > but I think it's nicer. > It internally uses a dynamic array as well, but duplicates the size with each growth and keeps track of a separate count of

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-09 Thread Sven Barth via fpc-pascal
James Richters via fpc-pascal schrieb am Fr., 9. Sep. 2022, 14:58: > I still end up with a lot of > SetLength(MyArray,Length(MyArray)+1); > Every time I want to add one more thing to the array. > With FPC 3.2.0 and newer you can do "Concat(MyArray, [TheNewElement])" or (if modeswitch

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-09 Thread Luca Olivetti via fpc-pascal
El 9/9/22 a les 14:58, James Richters via fpc-pascal ha escrit: Is there some nifty way to increase a dynamic array by 1 that is more elegant? Inc(MyArray); would sure be nice If I know that I have to regularly add a single element to an array, instead of using a dynamic array I just use a

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-09 Thread James Richters via fpc-pascal
I only recently learned about using Low() and High() and it is so much nicer than For I:= 0 to Length(MyArray)-1 Do That I actually went though all my code replacing the Length() - 1's with High() I still end up with a lot of SetLength(MyArray,Length(MyArray)+1); Every time I want to add one

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-09 Thread Luca Olivetti via fpc-pascal
El 8/9/22 a les 16:53, Anthony Walter via fpc-pascal ha escrit: > curious minds want to know: what was the fix? In a separate part of the pool table initialization, I was precalculating the midpoints and normals for bumper rails. I had carelessly written this code:   for I := 0 to

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-09 Thread Adriaan van Os via fpc-pascal
Peter B via fpc-pascal wrote: I suggest trying without optimisations and/or using cmem, to see if that changes the outcome. I would rather use a system memory debugger to find the cause of the corruption. Regards, Adriaan van Os

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-08 Thread Anthony Walter via fpc-pascal
> curious minds want to know: what was the fix? In a separate part of the pool table initialization, I was precalculating the midpoints and normals for bumper rails. I had carelessly written this code: for I := 0 to Length(Rails) do RailInit(Rails[I], I);

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-08 Thread wkitty42--- via fpc-pascal
On 9/8/22 9:54 AM, Anthony Walter via fpc-pascal wrote: Please ignore this post. I fixed the issue. curious minds want to know: what was the fix? -- NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list where it belongs!*

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-08 Thread Anthony Walter via fpc-pascal
Please ignore this post. I fixed the issue. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-08 Thread Peter B via fpc-pascal
I suggest trying without optimisations and/or using cmem, to see if that changes the outcome. Also, if the array is corrupted prior to the setlength, then iterating the array with a trivial   with... Writeln(Color) or whatever, should trigger an exception. That could then be used at various

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-08 Thread Jonas Maebe via fpc-pascal
On 2022-09-08 09:30, Anthony Walter via fpc-pascal wrote: Is there a known edge case issue connected to setting the length of dynamic arrays? No, and the location where you're getting the crash suggests an issue in your program that has corrupted the heap manager state. Jonas

[fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-08 Thread Anthony Walter via fpc-pascal
Is there a known edge case issue connected to setting the length of dynamic arrays? I have a program that simulates a billiards game, and during the rerack balls method of TPoolTable the number of pool balls on the table varies based on the rerack option used. Currently, I am having a problem