❔ Problem with Dictionary<ulong, Image> (Strange work of memory access)
Concept of my system: A system that draws a picture with stickers, each of the stickers can be moved, there can be an unlimited number of stickers.
Code with explanations in comments:
Problem:
Each time you use this function, a new picture should appear with ALL stickers and the sticker that we moved to a new location. However, it happens that the sticker is duplicated and there are several of them.
The suggestion line
image.Mutate(x => x.DrawImage(stickerImage, new Point(sticker.PositionX, sticker.PositionY), 1f));
updates the Dictionary directly, though it shouldn't be, presumably because C# has a memory bug here.
I am using .NET 7.07 Replies
where do itemId and args come from?
updates the Dictionary directly, though it shouldn't be
Do you mean it shouldn't update the instance of image saved in the Dictionary?
You're only doing this operation if image == null, so the dictionary isn't effectedTake it like a constant
Yes, i know that dictionary isn't effected and it's can't be updated
but it is
That looks a lot like imagesharp, and as far as I can remember, imagesharp works in-place, so it will mutate the existing Image reference
If you want to make a copy of what you have instead of mutating it in-place, you should be able to use the .Clone(...) method
That will return a cloned image which won't affect the original reference
How does
DrawProfileExceptStickerAsync
work?@Sossenbinder Thank you very much! It works!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.