unvestigate
Topic Author
Posts: 20
Joined: 17 Jan 2018, 09:55

Crash in InlineCollection::Clear() - related to reference counting?

17 Aug 2019, 09:21

Hi,

I am using Noesis 2.2.3 with C++ and I get a crash when running my game in debug mode. I think it has to do with reference counting but I am not sure. Basically I have a text block on the HUD where I want to mix text and images (eg. "Press <BUTTON> to activate" where BUTTON is an image of the button to press). I do this with a user control called HUDPrompt where the code looks like this:
<UserControl x:Class="Slide.HUDPrompt"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Slide"
             xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions"
             mc:Ignorable="d"
             x:Name="PromptControl"
             d:DesignHeight="1080" d:DesignWidth="1920">
    <Grid x:Name="LayoutRoot">
        <TextBlock x:Name="PromptTextBlock" FontSize="22" Foreground="#FFFFFFFF" Opacity="1" FontFamily="fonts/#Kimberley Alternate" noesis:Text.Stroke="#FF000000"
                noesis:Text.StrokeThickness="3">HUD Prompt</TextBlock>
    </Grid>
</UserControl>
So basically just a text block. I get a reference to the text block in C++ like this:
void HUDPrompt::OnLoaded(Noesis::BaseComponent* sender, const Noesis::RoutedEventArgs& args)
{
	mTextBlock = FindName<Noesis::TextBlock>("PromptTextBlock");
	BASIS_ASSERT(mTextBlock != nullptr);
	mTextBlock->SetText("");
}
Then, when I want to set the text of the prompt I call
Noesis::InlineCollection* inlineCollection = mTextBlock->GetInlines();
inlineCollection->Clear();
and then I pass the inline collection to a number of functions that add inlines to it. It seems the text (ie. run) addition works fine. The issue is with the images. The image adding looks like this:
Noesis::Ptr<Noesis::BitmapImage> bm = *new Noesis::BitmapImage(texturePath);

Noesis::Ptr<Noesis::Image> img = *new Noesis::Image();
img->SetSource(bm);

Noesis::Ptr<Noesis::InlineUIContainer> iuc = *new Noesis::InlineUIContainer(img);
inlineCollection->Add(iuc);
Now, If I switch the text twice, the second call to inlineCollection->Clear(); will crash with the following info:
Exception thrown at 0x00007FFC5834AABF (Noesis.dll) in Slide.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
If I add an reference to "iuc" before adding it to the inlineCollection the game no longer crashes but that gives me a large number of leaks on shutdown, as you would expect. This only occurs in debug builds. In release everything works as it should, though I assume bad things are going on under the hood.

I assume I am doing something wrong here with regards to ref counting but I cannot seem to figure out what. Any ideas?

Thanks!
 
unvestigate
Topic Author
Posts: 20
Joined: 17 Jan 2018, 09:55

Re: Crash in InlineCollection::Clear() - related to reference counting?

19 Aug 2019, 14:01

Small correction. I managed to reproduce this in release mode too. However, it seems to be a lot more random in release.
 
User avatar
sfernandez
Site Admin
Posts: 1628
Joined: 22 Dec 2011, 19:20

Re: Crash in InlineCollection::Clear() - related to reference counting?

20 Aug 2019, 20:38

Hi, I was able to reproduce the crash, could you please report it in our bugtracker and we will fix it for the next release.
Thanks for the collaboration.
 
unvestigate
Topic Author
Posts: 20
Joined: 17 Jan 2018, 09:55

Re: Crash in InlineCollection::Clear() - related to reference counting?

21 Aug 2019, 08:13

Added to mantis with ID 0001542.
 
User avatar
sfernandez
Site Admin
Posts: 1628
Joined: 22 Dec 2011, 19:20

Re: Crash in InlineCollection::Clear() - related to reference counting?

22 Aug 2019, 20:02

Thanks for the report, the fix will be included in the next release.

Who is online

Users browsing this forum: No registered users and 4 guests