Athos
Topic Author
Posts: 7
Joined: 17 May 2016, 18:57

Crash when releasing IView object

14 Aug 2017, 05:12

Hi,

I've implemented NoesisGUI with Urho3D and some of the samples (ImageAtlas.xaml and Palette.xaml) crashes the program during the destruction (mPtr->Release()) of the xamlView Ptr.
I compiled the D3D11 sample that came with the package and no crash ocurred. I couldn't find anything in the docs but do I need to do additional cleanup/handling of noesis objects ?

Here's the code I'm using:
Game::Game(Context* context) :
	Application(context),
	scene_(nullptr)
{
	// NoesisGUI is initialized here. Resources will be loaded from current working directory
	Noesis::GUI::Init(NoesisErrorHandler);
	Noesis::GUI::SetResourceProvider(".");
}
Game::~Game()
{
	// Shutdown Noesis Engine
	Noesis::GUI::Shutdown();
}


void Game::Start()
{
	Graphics* graphics = this->GetSubsystem<Graphics>(); // Urho3D Graphics Object

	// --------------------------------------------------
	// Noesis Context Initialization
	Noesis::Ptr<Noesis::D3D11RenderDevice> nsDevice = *new Noesis::D3D11RenderDevice(graphics->GetImpl()->GetDeviceContext());
	Noesis::Ptr<Noesis::VGContext> nsContext = Noesis::GUI::CreateVGContext(nsDevice.GetPtr(), Noesis::VGOptions());

	// Noesis Views
	Noesis::Ptr<Noesis::FrameworkElement> mainXaml = Noesis::GUI::LoadXaml<Noesis::FrameworkElement>("Samples\\ImageAtlas.xaml");
	this->nsMainView = Noesis::GUI::CreateView(mainXaml.GetPtr());
	this->nsMainView->GetRenderer()->Init(nsContext.GetPtr());
	this->nsMainView->SetSize(graphics->GetWidth(), graphics->GetHeight());
	this->nsMainView->SetAntialiasingMode(Noesis::AntialiasingMode::AntialiasingMode_PPAA);

	// --------------------------------------------------
	// Urho3D stuff
	// ...
}

void Game::Stop()
{
	this->nsMainView.Reset();
}


// ======================================================================
// Core events
// ======================================================================
void Game::OnUpdate(StringHash type, VariantMap &args)
{
	static double timestep = 0;
	timestep += args[Update::P_TIMESTEP].GetFloat();

	this->nsMainView->Update(timestep);
}


// ======================================================================
// Graphics events
// ======================================================================
void Game::OnScreenMode(StringHash type, VariantMap &args)
{
	int width = args[ScreenMode::P_WIDTH].GetInt();
	int height = args[ScreenMode::P_HEIGHT].GetInt();
	// ...
	
	this->nsMainView->SetSize(width, height);
}

void Game::OnBeginRendering(StringHash type, VariantMap &args)
{
	// Performs rendering operations.
	Noesis::IRenderer* nsRenderer = this->nsMainView->GetRenderer();

	// Applies changes to the render tree
	nsRenderer->UpdateRenderTree();

	// Renders offscreen textures. This step must be done before binding the main render target
	if (nsRenderer->NeedsOffscreen())
	{
		nsRenderer->RenderOffscreen();
	}
}

void Game::OnEndRendering(StringHash type, VariantMap &args)
{
	this->nsMainView->GetRenderer()->Render();
}
 
User avatar
ai_enabled
Posts: 231
Joined: 18 Jul 2013, 05:28
Contact:

Re: Crash when releasing IView object

14 Aug 2017, 06:57

Cannot find where you're calling Release() in the posted source code. Could you include this too?

In C#, we're calling Shutdown() for the renderer object in the view object first. It seems xamlView.Reset() is doing the same in C++. From NoesisGUI DX11 C++ sample:
// Free global resources and shutdown kernel
g_XamlView.Reset();
Noesis::GUI::Shutdown();
UPD. Ok I see you're calling nsMainView.Reset() in the Stop method. Please ensure it's called before Noesis::GUI::Shutdown().
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
 
nikobarli
Posts: 180
Joined: 26 Apr 2017, 06:23

Re: Crash when releasing IView object

14 Aug 2017, 07:47

Try attaching the debugger to see the call stack and what caused the crash (null pointer access etc).
If you are using a dedicated rendering thread, you may also want to check that. You need to make sure the thread is stopped before the clean up sequence.
 
Athos
Topic Author
Posts: 7
Joined: 17 May 2016, 18:57

Re: Crash when releasing IView object

14 Aug 2017, 16:00

@ai_enabled
The Game::Stop() method is called before the destructor, so the xamlView would be properly released before Noesis shutdown.

@nikobarli
Both Rendering/Update of the Game/Noesis happens in the main thread. Here's the callstack:
	First-chance exception at 0x00000000778F3290 (ntdll.dll) in Game_debug.exe: 0xC0000005: Access violation reading location 0x00000FD2B9959E58.
	
 	ntdll.dll!00000000778f3290()	Unknown
 	kernel32.dll!00000000777a300a()	Unknown
 	Noesis.dll!000007fede2b8a98()	Unknown
 	[External Code]	
 	Noesis.dll!000007feddfc1353()	Unknown
 	Noesis.dll!000007fede2ac53e()	Unknown
 	Noesis.dll!000007fede2ac4b4()	Unknown
 	Noesis.dll!000007feddfc1353()	Unknown
 	Noesis.dll!000007fede014bcf()	Unknown
 	Noesis.dll!000007feddfc1353()	Unknown
 	Noesis.dll!000007fede136a56()	Unknown
 	Noesis.dll!000007fede135efb()	Unknown
 	Noesis.dll!000007fede13529f()	Unknown
 	Noesis.dll!000007fede135164()	Unknown
 	Noesis.dll!000007feddfc1353()	Unknown
 	Noesis.dll!000007fede13369d()	Unknown
 	Noesis.dll!000007fede133524()	Unknown
 	Noesis.dll!000007feddfc1353()	Unknown
 	Noesis.dll!000007fede1a2cd6()	Unknown
 	Noesis.dll!000007fede1a2c54()	Unknown
 	Noesis.dll!000007feddfc1353()	Unknown
>	Game_debug.exe!Noesis::Core::Ptr<Noesis::Gui::IView>::Reset() Line 160	C++
 	Game_debug.exe!Game::Stop() Line 108	C++
 	[External Code]	
 	Game_debug.exe!RunApplication() Line 6	C++
 	Game_debug.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * prevInstance, char * cmdLine, int showCmd) Line 6	C++
 	[External Code]	
 
Wanderer
Posts: 168
Joined: 08 May 2017, 18:36

Re: Crash when releasing IView object

16 Aug 2017, 15:25

If I understand, you want exit program without crash?
If yes, you need reset everything from Noesis, not only IView.
That means all:
FrameworkElements
IViews
RenderDevices (OpenGL, DX, or another)
Contexts

If it is not this case, please explain when you call IView.reset() and why you call it.
 
Athos
Topic Author
Posts: 7
Joined: 17 May 2016, 18:57

Re: Crash when releasing IView object

18 Aug 2017, 19:26

Yes, I want to terminate the program without crashes.
I tested all of the samples and the ones that are crashing is using <ImageBrush> in the xaml.
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Crash when releasing IView object

19 Aug 2017, 21:35

Hi,

I just tried the D3D11 sample that comes with the C++ SDK, added some Image elements and ImageBrushes to the test xaml and it closes without crashes.
Please make sure you are releasing all the resources allocated by the render device before calling Noesis::GUI::Shutdown(). You can also force to end all pending rendering commands in Noesis Renderer by calling this->nsMainView->GetRenderer()->Shutdown() before the global Shutdown.

Let me know if any of this works.
 
Athos
Topic Author
Posts: 7
Joined: 17 May 2016, 18:57

Re: Crash when releasing IView object

20 Aug 2017, 15:48

I tried calling the IRenderer::Shutdown() and unfortunately, it throws the same exception.

Everything but D3D context (It's using Urho3D's context) is the same as the project sample included in the Noesis package.
Is there anything specific that has to be set in the D3D context?
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Crash when releasing IView object

23 Aug 2017, 19:48

Could you please create a ticket in our bugtracker and add a link to your project data so we can debug it and see where exactly the crash is happening?

Who is online

Users browsing this forum: No registered users and 89 guests