vexe / VFW

MIT License
492 stars 67 forks source link

SelectEnum on Dictionaries #42

Closed jonhartnett closed 9 years ago

jonhartnett commented 9 years ago

The SelectEnum popup window fails to change the value of a Dictionary key or value when applied via PerKey or PerValue.

This does not appear to be an isolated problem with SelectEnum, it also applies to a number of other attributes. I believe these issues are caused by the use of a temporary copy of the dictionary in DictionaryDrawer.

vexe commented 9 years ago

Just tried:

[PerKey, SelectEnum]
public Dictionary<KeyCode, int> dictionary2;

and seemed to be changing the key properly. Are you talking about persistency? Can you give a concrete example replicating what you're saying?

jonhartnett commented 9 years ago

It is possible that this behavior changed in 1.3.3. I'm still on 1.3.2, I will update and get back to you.

jonhartnett commented 9 years ago

On unity 5.1.1f1 personal and vfw 1.3.3, the following class produces the bug:

using UnityEngine;
using Vexe.Runtime.Types;
using System.Collections.Generic;

public class Test : BetterBehaviour
{
    [PerKey, SelectEnum]
    public Dictionary<KeyCode, int> dictionary2;
}
vexe commented 9 years ago

Right. You said that this applied to a number of other attributes, like what?

Cause Popup seems to work:

[PerKey, Popup("GetValues", TextField = true)]
public Dictionary<string, int> dictionary2;

string[] GetValues() { return new string[] { "One", "Two", "Three" }; }

If one of them works, it might mean that it doesn't have to do with the temp structure in DictionaryDrawer.

vexe commented 9 years ago

Seems that the 'write' block is not running after the value is set from the window - So, the temp kvp list has the updated value, but the original dictionary does not. If we do not write, then the next time we read we'll clear the contents of the temp list and read from the original dictionary again, reading the old value. DictionaryDrawer still proves to be the most challenging drawer to get right.

vexe commented 9 years ago

I did a dirty hack to fix it. Let me know of the other attributes you said to be problematic too so I can try out this hack on them.

Seems that I should really invest in eliminating the temp list and find a way to directly deal with the dictionary itself instead.

jonhartnett commented 9 years ago

Actually I don't believe there are any other attributes that have problems, some of my diagnostic code was interfering with the drawer.