Fusee icon indicating copy to clipboard operation
Fusee copied to clipboard

MeshChanged EventHandler is not called when single array elements are changed, arrays as attributes inside Mesh.cs

Open wrestledBearOnce opened this issue 3 years ago • 6 comments

Example:


var cube = new Cube();
cube.Colors[2] = (uint)ColorUint.Red; // no event handler

var tmpArr = new uint[] { (uint)ColorUint.Red, (uint)ColorUint.Blue, ... }
cube.Colors = tmpArr; // event handler is called

Possible solution: Observable Collection

may fix: #456

wrestledBearOnce avatar Jun 20 '22 12:06 wrestledBearOnce

To make things even worse:

CA1819: Properties should not return arrays

https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1819?view=vs-2019

Arrays returned by properties are not write-protected, even if the property is read-only. To keep the array tamper-proof, the property must return a copy of the array.

wrestledBearOnce avatar Jun 20 '22 15:06 wrestledBearOnce

After consulting with @RedImp1470 pushed directly to develop with 66eece2f9769f08bb2a22108b38a03f708b7ea2d and f8ed74c4cc8d0e4261c311a18371c290921c30f7

The AABB is now being updated automatically.

wrestledBearOnce avatar Jun 20 '22 15:06 wrestledBearOnce

Reversed commits as these changes are too broad to merge without review!

New feature branch.

wrestledBearOnce avatar Jun 21 '22 11:06 wrestledBearOnce

I've implemented an ObservableArray<T> which can be used the same way as the arrays could be used before, however all Mesh attributes are now readonly to prevent any shenanigans with vanishing EventListeners when assigning a new array to an attribute. To assign a new value, a user needs to call the Assign() method, which takes care of everything, as the implicit operator needs to be static and can't be used in this case.

wrestledBearOnce avatar Jun 21 '22 11:06 wrestledBearOnce

Second try: #533

wrestledBearOnce avatar Jun 24 '22 13:06 wrestledBearOnce

See #605

RedImp1470 avatar Aug 18 '22 06:08 RedImp1470