Crash in InlineCollection::Clear() - related to reference counting?
Posted: 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:
So basically just a text block. I get a reference to the text block in C++ like this:
Then, when I want to set the text of the prompt I call
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:
Now, If I switch the text twice, the second call to inlineCollection->Clear(); will crash with the following info:
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!
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:
Code: Select all
<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>
Code: Select all
void HUDPrompt::OnLoaded(Noesis::BaseComponent* sender, const Noesis::RoutedEventArgs& args)
{
mTextBlock = FindName<Noesis::TextBlock>("PromptTextBlock");
BASIS_ASSERT(mTextBlock != nullptr);
mTextBlock->SetText("");
}
Code: Select all
Noesis::InlineCollection* inlineCollection = mTextBlock->GetInlines();
inlineCollection->Clear();
Code: Select all
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);
Code: Select all
Exception thrown at 0x00007FFC5834AABF (Noesis.dll) in Slide.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
I assume I am doing something wrong here with regards to ref counting but I cannot seem to figure out what. Any ideas?
Thanks!