ex-makina / marklight-issues

Public bug and issue tracker for MarkLight
1 stars 0 forks source link

Creating a dynamic via ViewData.CreateView<T> is not working #68

Open khalilovcmd opened 7 years ago

khalilovcmd commented 7 years ago

This doesn't work:

ViewData.LoadXuml ("<MyExample>\n<Panel>\n \n</Panel>\n</MyExample>", "MyExample");
ViewData.CreateView<MyExample> ( this.LayoutParent, Parent);

In class ViewData.cs, function LoadViewXuml, we are:

var viewTypeData = new ViewTypeData();
viewPresenter.ViewTypeDataList.Add(viewTypeData);

Then when creating a view, we try in class ViewPresenter.cs function GetViewTypeData:

if (_viewTypeDataDictionary == null )
{
  LoadViewTypeDataDictionary();
}

ViewTypeData viewTypeData;
if (!_viewTypeDataDictionary.TryGetValue(viewTypeName, out viewTypeData))
{
  Debug.LogError(String.Format("[MarkLight] Can't find view type \"{0}\".", viewTypeName));
                return null;
}

So I believe this was recently introduced for performance improvements, but _viewTypeDataDictionary is not going to have all the records as ViewTypeDataList in both need to be synchronised.

khalilovcmd commented 7 years ago

A quick fix would be synchronizing both as:

if (_viewTypeDataDictionary == null || _viewTypeDataDictionary.Count < ViewTypeDataList.Count)
{
  LoadViewTypeDataDictionary();
}