Re: Why am I getting segfaults when doing `foreach` with arrays of references?

2024-03-09 Thread Liam McGillivray via Digitalmars-d-learn
On Saturday, 9 March 2024 at 07:49:52 UTC, Liam McGillivray wrote: But that begs the question; why? Don't dynamic arrays always start with a length of 0? If the array was only extended when valid objects were appended using the append operator `~=`, and none of those objects were deleted (as I

Re: Why am I getting segfaults when doing `foreach` with arrays of references?

2024-03-09 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 09/03/2024 8:49 PM, Liam McGillivray wrote: But that begs the question; why? Don't dynamic arrays always start with a length of 0? If the array was only extended when valid objects were appended using the append operator |~=|, and none of those objects were deleted (as I the destructor was

Re: Why am I getting segfaults when doing `foreach` with arrays of references?

2024-03-08 Thread Liam McGillivray via Digitalmars-d-learn
On Saturday, 9 March 2024 at 06:37:02 UTC, Richard (Rikki) Andrew Cattermole wrote: Something that I have noticed that you are still doing that was pointed out previously is having a pointer to a class reference. Stuff like ``Tile* currentTile;`` when it should be ``Tile currentTile;`` A

Re: Why am I getting segfaults when doing `foreach` with arrays of references?

2024-03-08 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
Something that I have noticed that you are still doing that was pointed out previously is having a pointer to a class reference. Stuff like ``Tile* currentTile;`` when it should be ``Tile currentTile;`` A class reference is inherently a pointer. So when you checked for nullability in the

Why am I getting segfaults when doing `foreach` with arrays of references?

2024-03-08 Thread Liam McGillivray via Digitalmars-d-learn
With [my game project](https://github.com/LiamM32/Open_Emblem), I have been getting segmentation faults that are unexplainable at my knowledge level. They seem to happen when doing a "foreach" loop through an array of references. Skip to the bolded text if you don't want to read too much, as