Page 4 of 5

Re: A few questions about some features

Posted: 13 Mar 2015, 12:17
by sfernandez
Hi,

Sorry for the very late answer :oops:

I tried your sample and, once added serialization code (see below) to the InventoryTileModel class, it works as expected, inside XamlPlayer and in a external application.

Can I have a look at your serialization code? Mine looks like this:
void Serialize(Noesis::Core::SerializationData* data) const
{
    data->Serialize("ItemID", _itemID);
    data->Serialize("Quantity", _quantity);
}
void Unserialize(Noesis::Core::UnserializationData* data, NsUInt32 version)
{
    data->Unserialize("ItemID", _itemID);
    data->Unserialize("Quantity", _quantity);
} 
How do you initialize NoesisGUI and load this xaml in your application?

Have you registered the component in the ComponentFactory before loading the xaml?
extern "C" NS_DLL_EXPORT void NsRegisterReflection(ComponentFactory* factory, NsBool registerComponents)
{
    NS_REGISTER_COMPONENT(InventoryTileModel)
}
Anything you try in XamlPlayer should work the same way in your application, otherwise we have a bug in our code.

Re: A few questions about some features

Posted: 17 Mar 2015, 15:12
by ZanAlex
For my integration purpose, I've stopped creating data model from my xaml files. Therefore I don't have that problem anymore, but I'm looking at my code right now and it seems the Serialize/Unserialize methods are the same and the way I'm loading it from my application is strictly the same as presented in the tutorials, that's quite weird.

However, I'm facing a similar problem now. I have a UserControl with two properties I'd like to be able to set in my Xaml file.
[...]
static const Noesis::Gui::DependencyProperty* ValueProperty;

NS_IMPLEMENT_INLINE_REFLECTION([i][UserControl][/i], Noesis::Gui::UserControl)
{
    NsMeta<Noesis::Core::TypeId>("[i][UserControl][/i]");

    Noesis::Core::Ptr<Noesis::Gui::UIElementData> data = NsMeta<Noesis::Gui::UIElementData>(Noesis::Core::TypeOf<SelfClass>());

    // {TODO} Should be available from Xaml
    data->RegisterProperty<NsUInt32>(
        ValueProperty,
        "Value",
        Noesis::Gui::FrameworkPropertyMetadata::Create(5, Noesis::Gui::FrameworkOptions_None));
[...]
<[i][UserControl][/i]Value="10"/>
That leads to a crash in my application when trying to load the xaml file containing that line. Not mentioning Value in the line allows to load the Xaml file, with Value equals to its default value. I've followed the UserControl tutorial and read the DependencyProperty documentation and I don't see what I'm missing.
I figured out the NsProp("Value", [Getter], [Setter]) line is not required if I don't want to use particular accessor/mutator couple. Am I right?

Thanks!

Re: A few questions about some features

Posted: 18 Mar 2015, 16:28
by sfernandez
I suppose that every reference to
[i][UserControl][/i]
in the code you posted refers to your user control class name :)

Apart from that, when you are creating your own user control, one important thing you can't miss is to specify the xaml source when registering the class reflection:
[...]
static const Noesis::Gui::DependencyProperty* ValueProperty;

NS_IMPLEMENT_INLINE_REFLECTION(MyUserControl, Noesis::Gui::UserControl)
{
    NsMeta<Noesis::Core::TypeId>("MyUserControl");

    Noesis::Core::Ptr<Noesis::Gui::UIElementData> data = NsMeta<Noesis::Gui::UIElementData>(Noesis::Core::TypeOf<SelfClass>());

    NsString source = "assets/UI/UserControls/MyUserControl.xaml";

    data->OverrideMetadata<NsString>(
        UserControl::SourceProperty,
        "Source",
        Noesis::Gui::FrameworkPropertyMetadata::Create(source,
            Noesis::Gui::FrameworkOptions_None));

    data->RegisterProperty<NsUInt32>(
        ValueProperty,
        "Value",
        Noesis::Gui::FrameworkPropertyMetadata::Create((NsUInt32)5,
            Noesis::Gui::FrameworkOptions_None));
}
[...] 
Otherwise, when referencing the control in another xaml, it won't be able to load the associated xaml.

Anyway, if you are getting a crash you should be able to generate a crash dump. Please create a ticket in our bugtracker and attach the dump so we can investigate the origin of the crash.

Re: A few questions about some features

Posted: 18 Mar 2015, 18:42
by ZanAlex
Oops yes, that's what I meant :)

I did not forget to specify the source. Every files seem to be parsed correctly by the BuildTool, but when calling Noesis::Gui::GUI::LoadXaml (after a dozen other internal Noesis calls), the application crashes:
Unhandled exception at 0x000007FEEAEA4101 (Noesis.dll) in Dual_d.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
Removing the Value="10" part solves the problem.

Re: A few questions about some features

Posted: 20 Mar 2015, 10:18
by ZanAlex
In order to provide an actual integration test, I've used your DirectX11 Integration tutorial with a simple user control.

UserControlTest.h:
#pragma once

#include <NsGui/UserControl.h>
#include <NsGui/FrameworkPropertyMetadata.h>
#include <NsGui/UIElementData.h>

namespace NQ
{
    namespace Gui
    {
        class UserControlTest : public Noesis::Gui::UserControl
        {
        public:

            NsInt32 GetTest() const { return Noesis::Gui::DependencyObject::GetValue<NsInt32>(TestProperty); }
            void SetTest(NsInt32 in) { Noesis::Gui::DependencyObject::SetValue<NsInt32>(TestProperty, in); }

            static const Noesis::Gui::DependencyProperty* TestProperty;

        private:
            NS_IMPLEMENT_INLINE_REFLECTION(UserControlTest, Noesis::Gui::UserControl)
            {
                NsMeta<Noesis::Core::TypeId>("UserControlTest");

                NsProp("Test", &UserControlTest::GetTest, &UserControlTest::SetTest);

                NsString source = "usercontroltest.xaml";

                Noesis::Core::Ptr<Noesis::Gui::UIElementData> data = NsMeta<Noesis::Gui::UIElementData>(Noesis::Core::TypeOf<SelfClass>());

                data->RegisterProperty<NsInt32>(
                    TestProperty, 
                    "Test",
                    Noesis::Gui::FrameworkPropertyMetadata::Create((NsInt32)0, Noesis::Gui::FrameworkOptions_None));

                data->OverrideMetadata<NsString>(
                    UserControl::SourceProperty, 
                    "Source",
                    Noesis::Gui::FrameworkPropertyMetadata::Create(source, Noesis::Gui::FrameworkOptions_None));
            }
        };
    }
}
UserControlTest.cpp:
#include "UserControlTest.h"

const Noesis::Gui::DependencyProperty* NQ::Gui::UserControlTest::TestProperty;
devel_sample.xaml
<Border
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Name="Root"
  Background="#CC000000">
	
	<UserControlTest Test="220891"/>
	
</Border>
usercontroltest.xaml:
<UserControl
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="UserControlTest" x:Name="ROOT_UserControlTest">
	
	<Border HorizontalAlignment="Center" VerticalAlignment="Center">
	
		<TextBlock Text="{Binding Test, ElementName=ROOT_UserControlTest}"/> 
		
	</Border>
</UserControl>
Integration code:
SetupKeyMap();

Noesis::Gui::GUI::InitDirectX11(g_pd3dDevice, ErrorHandler);
Noesis::Gui::GUI::AddResourceProvider(".");
NsRegisterReflection(0, true);

Ptr<FrameworkElement> xaml = Noesis::GUI::LoadXaml<FrameworkElement>("devel_sample.xaml");
g_XamlRenderer = Noesis::GUI::CreateRenderer(xaml.GetPtr());
g_XamlRenderer->SetSize(g_Width, g_Height);
g_XamlRenderer->SetAntialiasingMode(Noesis::Gui::AntialiasingMode_PPAA);
I have no problem building each Xaml file and it works just fine in the XamlPlayer. However, the application crashes when reaching
Ptr<FrameworkElement> xaml = Noesis::GUI::LoadXaml<FrameworkElement>("devel_sample.xaml");
exactly as it does in my actual application.

I must be missing something here. I think I've followed exactly what is written in the UserControl tutorial. According to the page about DependencyProperty, I shouldn't have to write the NsProp line, but not putting it makes the XamlPlayer throwing a "Test not recognized error".

What am I missing?
Thank you for your help.

Re: A few questions about some features

Posted: 24 Mar 2015, 12:54
by jsantos
I have no problem building each Xaml file and it works just fine in the XamlPlayer. However, the application crashes when reaching
Ptr<FrameworkElement> xaml = Noesis::GUI::LoadXaml<FrameworkElement>("devel_sample.xaml");
exactly as it does in my actual application.
What kind of crashing are you getting. Is the ErrorHandler being invoked with an error description?

Re: A few questions about some features

Posted: 24 Mar 2015, 13:02
by jsantos
Also, is the NsRegisterReflection properly implemented? Could you paste it here? I don't see it in the sources you posted above.

More questions, does the code in our UserControl Tutorial work properly? (adapting it to v1.2, because that code is still for v1.1... sorry for that)

Thanks!

Re: A few questions about some features

Posted: 24 Mar 2015, 13:26
by ZanAlex
NsRegisterReflection implementation:
void NsRegisterReflection(Noesis::Core::ComponentFactory* factory, NsBool registerComponents)
{
    NS_REGISTER_COMPONENT(NQ::Gui::UserControlTest);
}
Testing the tutorial right now...

Re: A few questions about some features

Posted: 24 Mar 2015, 13:29
by jsantos
Also, please, place a breakpoint in the ErrorHandler. It should be getting invoked with a description about the error that is happening.

Re: A few questions about some features

Posted: 24 Mar 2015, 14:08
by ZanAlex
I've tried the UserControl tutorial in the application unsuccessfully. I've pretty much copy-pasted what alreay existed in the tutorial and it got compiled almost immediatly (some namespace issues here and there). However, the result is the same: the application crashes at:
Ptr<FrameworkElement> xaml = Noesis::GUI::LoadXaml<FrameworkElement>("sample.xaml");
and did not enter the ErrorHandler function.

Again, the xaml files got built without any error, I did not forget the NsRegisterReflection function...