digitalmars.D.learn - Odd behavior of darray.dup
- solidstate1991 (8/8) Feb 22 2019 If I want to copy an array of structs with .dup (cannot post the
- Bastiaan Veelo (4/12) Feb 23 2019 It works for me:
- solidstate1991 (8/11) Feb 23 2019 Still no luck, not even with memcpy.
- Bastiaan Veelo (22/35) Feb 24 2019 Sorry, I didn't realize that my link didn't work (due to issue
- Bastiaan Veelo (3/8) Feb 24 2019 Reported.
- Dmitriy (7/15) Feb 26 2019 got this response on
If I want to copy an array of structs with .dup (cannot post the link in question here at the moment due to non-working clipboard, it's Color from pixelperfectengine.graphics.common) I get all zeroes instead of the values from the original array. I haven't disabled post-blit to my knowledge. Is it some kind of a bug, or the .dup function has some behavior that's not currently documented on the site (such as needing a copy constructor)?
Feb 22 2019
On Friday, 22 February 2019 at 11:36:35 UTC, solidstate1991 wrote:If I want to copy an array of structs with .dup (cannot post the link in question here at the moment due to non-working clipboard, it's Color from pixelperfectengine.graphics.common) I get all zeroes instead of the values from the original array. I haven't disabled post-blit to my knowledge. Is it some kind of a bug, or the .dup function has some behavior that's not currently documented on the site (such as needing a copy constructor)?It works for me: https://run.dlang.io/gist/473b0021487275751accaebeb00be05c -- Bastiaan
Feb 23 2019
On Saturday, 23 February 2019 at 19:21:10 UTC, Bastiaan Veelo wrote:It works for me: https://run.dlang.io/gist/473b0021487275751accaebeb00be05c -- BastiaanStill no luck, not even with memcpy. There's even more mystery as I printed out the original static immutable array's content, which is different from the non-immutable one. Instead of the 32bit hex value of the given color in the format of "0x00000000", I get
Feb 23 2019
On Saturday, 23 February 2019 at 23:35:14 UTC, solidstate1991 wrote:On Saturday, 23 February 2019 at 19:21:10 UTC, Bastiaan Veelo wrote:Sorry, I didn't realize that my link didn't work (due to issue https://github.com/dlang-tour/core/issues/714). I have instead exported a Gist https://gist.github.com/run-dlang/965a2fb793bda7b1a82b0512d78973f3 that you should be able to use with the "Import Gist" button on https://run.dlang.io/. I have included the relevant bits from pixelperfectengine (slightly modified, see below). If you have further questions, you can do the same so it will be easier to see what is going on. Several things here: immutable Color because the `Color.toString()` method is not const (corrected in the Gist). This is a bug in pixelperfectengine. Likewise, getters like `green()` should be const. 2) Also note that `intToHex()` could simply be implemented using std.format, as row 127 illustrates. 3) You get all zeros because static data needs a static module constructor, added on line 111. 4) As an alternative to static data you could use compile time data (line 118) which does not need a constructor nor `.dup`. Beware that each time you use it though, its value gets copy-pasted into the code like a C #define. Hope this helps, Bastiaan.It works for me: https://run.dlang.io/gist/473b0021487275751accaebeb00be05c -- BastiaanStill no luck, not even with memcpy. There's even more mystery as I printed out the original static immutable array's content, which is different from the non-immutable one. Instead of the 32bit hex value of the given color in the format of "0x00000000", I get
Feb 24 2019
On Sunday, 24 February 2019 at 12:10:22 UTC, Bastiaan Veelo wrote:immutable Color because the `Color.toString()` method is not const (corrected in the Gist). This is a bug in pixelperfectengine. Likewise, getters like `green()` should be const.Reported. https://github.com/ZILtoid1991/pixelperfectengine/issues/8
Feb 24 2019
On Friday, 22 February 2019 at 11:36:35 UTC, solidstate1991 wrote:If I want to copy an array of structs with .dup (cannot post the link in question here at the moment due to non-working clipboard, it's Color from pixelperfectengine.graphics.common) I get all zeroes instead of the values from the original array. I haven't disabled post-blit to my knowledge. Is it some kind of a bug, or the .dup function has some behavior that's not currently documented on the site (such as needing a copy constructor)?got this response on https://run.dlang.io/gist/run-dlang/965a2fb793bda7b1a82b0512d78973f3?compiler=dmd: 0x00FF0000 0x00FF0000 0x00FF7B00 0xFF7B0000
Feb 26 2019