Daki
Topic Author
Posts: 57
Joined: 16 Aug 2013, 00:48

Crash when Destroying a Custom Control

15 Dec 2013, 06:42

I have a custom control that I modeled off of the CustomControl Tutorial example. It is working fine except when my game terminates and the renderer used with these controls goes out of scope and gets deleted I see a crash and in the call stack I can see it is due to calling the destructor on my control. I am using Ogre so the specific time of the error is at the end of the Noesis_Shutdown function. I am not sure if there is something wrong with the control or how I have my dll set up. Any help would be appreciated.

Here is the code for the control:

Header:
#include "stdafx.h"

#pragma warning(disable: 4275)
#pragma warning(disable: 4251)

#include <Noesis.h>
#include <NsGui/UserControl.h>
#include <NsGui/UIElementData.h>
#include <NsGui/FrameworkPropertyMetaData.h>
#include <NsGui/RoutedEvent.h>
#include <NsCore/ReflectionImplement.h>
#include <NsCore/TypeId.h>
#include <NsCore/Package.h>

using namespace Noesis;
using namespace Noesis::Core;
using namespace Noesis::Gui;

/*!
 * This class represents a common control to display information about a song in the songwheel
 */
class SongSelect: public UserControl
{
public:
	NS_DLL_EXPORT
	void setTitleText(const NsString& value);
	NS_DLL_EXPORT
	void setArtistText(const NsString& value);
	NS_DLL_EXPORT
	void setScoreText(const NsString& value);
	NS_DLL_EXPORT
	void setGradeText(const NsString& value);
	NS_DLL_EXPORT
	void setPackTitleText(const NsString& value);

	NS_DLL_EXPORT
	const NsString& getTitleText() const;
	NS_DLL_EXPORT
	const NsString& getArtistText() const;
	NS_DLL_EXPORT
	const NsString& getScoreText() const;
	NS_DLL_EXPORT
	const NsString& getGradeText() const;
	NS_DLL_EXPORT
	const NsString& getPackTitleText() const;

public:
    static const DependencyProperty* TitleTextProperty;
	static const DependencyProperty* ArtistTextProperty;
	static const DependencyProperty* ScoreTextProperty;
	static const DependencyProperty* GradeTextProperty;
	static const DependencyProperty* PackTitleTextProperty;

private:

	NS_IMPLEMENT_INLINE_REFLECTION(SongSelect, UserControl)
	{
		NsMeta<TypeId>("SongSelect");

		NsProp("TitleText", &SongSelect::getTitleText, &SongSelect::setTitleText);
		NsProp("ArtistText", &SongSelect::getArtistText, &SongSelect::setArtistText);
		NsProp("ScoreText", &SongSelect::getScoreText, &SongSelect::setScoreText);
		NsProp("GradeText", &SongSelect::getGradeText, &SongSelect::setGradeText);
		NsProp("PackTitleText", &SongSelect::getPackTitleText, &SongSelect::setPackTitleText);

		NsString source = "Gui/WKDX/song_select_element.xaml";

		Ptr<UIElementData> data = NsMeta<UIElementData>(TypeOf<SelfClass>());

		NsString defualtTitle		= "Title";
		NsString defualtArtist		= "Artist";
		NsString defualtScore		= "Score";
		NsString defualtGrade		= "Grade";
		NsString defualtPackTitle	= "Pack Title";

		data->RegisterProperty<NsString>(TitleTextProperty, "TitleText",
			FrameworkPropertyMetadata::Create(defualtTitle, FrameworkOptions_None));
		data->RegisterProperty<NsString>(ArtistTextProperty, "ArtistText",
			FrameworkPropertyMetadata::Create(defualtArtist, FrameworkOptions_None));
		data->RegisterProperty<NsString>(ScoreTextProperty, "ScoreText",
			FrameworkPropertyMetadata::Create(defualtScore, FrameworkOptions_None));
		data->RegisterProperty<NsString>(GradeTextProperty, "GradeText",
			FrameworkPropertyMetadata::Create(defualtGrade, FrameworkOptions_None));
		data->RegisterProperty<NsString>(PackTitleTextProperty, "PackTitleText",
			FrameworkPropertyMetadata::Create(defualtPackTitle, FrameworkOptions_None));
		
		data->OverrideMetadata<NsString>(UserControl::SourceProperty, "Source",
			FrameworkPropertyMetadata::Create(source, FrameworkOptions_None));
	}
};
CPP:
#include "stdafx.h"

#pragma warning(disable: 4275)
#pragma warning(disable: 4251)

#include "SongSelect.h"

using namespace Noesis;
using namespace Noesis::Core;
using namespace Noesis::Gui;

const DependencyProperty* SongSelect::TitleTextProperty;
const DependencyProperty* SongSelect::ArtistTextProperty;
const DependencyProperty* SongSelect::ScoreTextProperty;
const DependencyProperty* SongSelect::GradeTextProperty;
const DependencyProperty* SongSelect::PackTitleTextProperty;

NS_DLL_EXPORT
const NsString& SongSelect::getTitleText() const
{
    return DependencyObject::GetValue<NsString>(TitleTextProperty);
}

NS_DLL_EXPORT
void SongSelect::setTitleText(const NsString& value)
{
    DependencyObject::SetValue<NsString>(TitleTextProperty, value);
}

NS_DLL_EXPORT
const NsString& SongSelect::getArtistText() const
{
    return DependencyObject::GetValue<NsString>(ArtistTextProperty);
}

NS_DLL_EXPORT
void SongSelect::setArtistText(const NsString& value)
{
    DependencyObject::SetValue<NsString>(ArtistTextProperty, value);
}

NS_DLL_EXPORT
const NsString& SongSelect::getScoreText() const
{
    return DependencyObject::GetValue<NsString>(ScoreTextProperty);
}

NS_DLL_EXPORT
void SongSelect::setScoreText(const NsString& value)
{
    DependencyObject::SetValue<NsString>(ScoreTextProperty, value);
}

NS_DLL_EXPORT
const NsString& SongSelect::getGradeText() const
{
    return DependencyObject::GetValue<NsString>(GradeTextProperty);
}

NS_DLL_EXPORT
void SongSelect::setGradeText(const NsString& value)
{
    DependencyObject::SetValue<NsString>(GradeTextProperty, value);
}

NS_DLL_EXPORT
const NsString& SongSelect::getPackTitleText() const
{
    return DependencyObject::GetValue<NsString>(PackTitleTextProperty);
}

NS_DLL_EXPORT
void SongSelect::setPackTitleText(const NsString& value)
{
    DependencyObject::SetValue<NsString>(PackTitleTextProperty, value);
}
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Crash when Destroying a Custom Control

15 Dec 2013, 11:19

Hi,

Do you mean that your user control constructor is called after NsGetKernel()->Shutdown() (inside Noesis_Shutdown)?
Do you keep any global reference to your user control?
 
Daki
Topic Author
Posts: 57
Joined: 16 Aug 2013, 00:48

Re: Crash when Destroying a Custom Control

15 Dec 2013, 16:51

No my constructor is not called though I can see the destructor being called in the call stack. I do not keep any references to the control around. The control is also quite simple - it's just some TextBlocks and Rectanges so I suspect this may be a problem with how my dll is set up though I am unsure how to debug that.
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Crash when Destroying a Custom Control

17 Dec 2013, 16:33

Hi!

Could you send us the project in private? (or file a bug in the tracker and attach the project)

Thanks!
 
Daki
Topic Author
Posts: 57
Joined: 16 Aug 2013, 00:48

Re: Crash when Destroying a Custom Control

18 Dec 2013, 02:16

I've sent you the project. Thank you for taking a look at it!

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 89 guests