我正在编写的WPF应用程序有问题。我有一个窗口,其中会加载个人资料图片,供用户在应用程序中设置帐户时选择。每张图片都被加载到用户控件中,并放置在堆栈面板中,这样,当用户单击图片时,它将触发用户控件中的代码,并自动设置其个人资料图片,而无需再单击任何内容。这个窗口可以在64位系统上正常加载。但是,在32位系统上加载时,整个应用程序崩溃。故障模块是wpfgfx_v0400.dll。我不知道为什么它崩溃了。请帮忙。
这是事件查看器中的错误:
wpf - 仅在32位系统上wpfgfx_v0400.dll上的APPCRASH-LMLPHP
这是相关窗口前端的XAML:

<Window x:Class="RandomApplication.Windows.ChooseProfilePic"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:RandomApplication.Windows"
    mc:Ignorable="d"
    WindowStartupLocation="CenterScreen"
    ContentRendered ="On_ContentRendered"
    Title="Choose A Picture" Height="515" Width="500" Background="Black" ResizeMode="CanMinimize">
<Grid Background="Black">
    <ScrollViewer VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto" Height="420" VerticalAlignment="Top" Margin="0,5,0,0">
        <StackPanel>
            <StackPanel Name="HeadsPanel" Orientation="Horizontal" Height="100" VerticalAlignment="Top"/>
            <StackPanel Name="AbstractPanel" Orientation="Horizontal" Height="100" VerticalAlignment="Top"/>
            <StackPanel Name="ShapesPanel" Orientation="Horizontal" Height="100" VerticalAlignment="Top"/>
            <StackPanel Name="MiscPanel" Orientation="Horizontal" Height="100" VerticalAlignment="Top"/>
        </StackPanel>
    </ScrollViewer>
    <Button Name="CancelButton"  VerticalAlignment="Bottom" Style="{DynamicResource RedButton}" Click="CancelButton_Click">Cancel</Button>
    <Border Name="LoadingBorder" Background="Black">
        <TextBlock Name="LoadingLabel" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,150" FontSize="20" FontWeight="Bold">
                <Run>Loading Pictures</Run>
                <LineBreak></LineBreak>
                <Run>Please Wait...</Run>
        </TextBlock>
    </Border>
</Grid>

这是窗口后面的代码:
namespace RandomApplication.Windows
{
public partial class ChooseProfilePic : Window
{
    private readonly BackgroundWorker _loadPictureWorker = new BackgroundWorker();

    public ChooseProfilePic()
    {
        InitializeComponent();
        Topmost = true;

        _loadPictureWorker.DoWork += LoadImages;
        _loadPictureWorker.RunWorkerCompleted += LoadImages_Completed;
    }

    private void On_ContentRendered(object sender, EventArgs e)
    {
        _loadPictureWorker.RunWorkerAsync();
    }

    private void CancelButton_Click(object sender, RoutedEventArgs e)
    {
        DialogResult = false;
        Close();
    }

    private void LoadImages(object sender, DoWorkEventArgs e)
    {
        try
        {
            var headsImagePath = AppDomain.CurrentDomain.BaseDirectory + @"Images\Profile Pics\Heads\";
            var abstractImagePath = AppDomain.CurrentDomain.BaseDirectory + @"Images\Profile Pics\Abstract\";
            var shapesImagePath = AppDomain.CurrentDomain.BaseDirectory + @"Images\Profile Pics\Shapes\";
            var miscImagePath = AppDomain.CurrentDomain.BaseDirectory + @"Images\Profile Pics\Misc\";

            List<string> headsImageList = GetImages(headsImagePath);
            List<string> abstractImageList = GetImages(abstractImagePath);
            List<string> shapesImageList = GetImages(shapesImagePath);
            List<string> miscImageList = GetImages(miscImagePath);

            Application.Current.Dispatcher.Invoke(() =>
            {
                LoadViewingPanel(headsImageList, HeadsPanel);
                LoadViewingPanel(abstractImageList, AbstractPanel);
                LoadViewingPanel(shapesImageList, ShapesPanel);
                LoadViewingPanel(miscImageList, MiscPanel);
            });
        }

        catch (Exception ex)
        {
            CustomMessageBox.Show("Could not load images. :-(", "Image Retrieval Failed", MessageBoxButton.OK,
                MessageBoxImage.Error);
            Helper.WriteException(Helper.ErrorLogs + "Error Loading Images.txt", ex);
        }
    }

    private void LoadImages_Completed(object sender, RunWorkerCompletedEventArgs e)
    {
        if (e.Error != null)
        {
            CustomMessageBox.Show("Could not load images. :-(", "Image Retrieval Failed", MessageBoxButton.OK,
                MessageBoxImage.Error);
            Helper.WriteException(Helper.ErrorLogs + "Error Loading Images.txt", e.Error);
        }

        else LoadingBorder.Visibility = Visibility.Hidden;
    }

    public List<string> GetImages(string imagePath)
    {
        var that = GetAllFiles(imagePath);
        return that.ToList();
    }

    private void LoadViewingPanel(List<string> list, StackPanel panel)
    {
        foreach (var imageString in list)
        {
            Helper.WriteLineToFile(Helper.ErrorLogs + "2nd Info Loading Images.txt", imageString);
            var thisUri = new Uri(imageString, UriKind.RelativeOrAbsolute);
            var pic = new ProfilePic {ProfilePicImage = {Source = new BitmapImage(thisUri)}};
            panel.Children.Add(pic);
        }
    }

    private IEnumerable<string> GetAllFiles(string path)
    {
        return Directory.EnumerateFiles(path, "*.jpg").Union(
            Directory.EnumerateDirectories(path).SelectMany(d =>
            {
                try
                {
                    return GetAllFiles(d);
                }
                catch
                {
                    return Enumerable.Empty<string>();
                }
            }));
    }
}
}
我已经研究了可能导致此特定dll问题的原因,但似乎都与我的问题无关。

最佳答案

因此,我找出了问题所在。显然,我尝试加载的图像太大。图片均为2048x2048像素,大小从180 KB到380 KB不等。显然这太多了。我将所有图片的大小调整为100x100像素(因为我只将图片以100x100的形式呈现给用户),这使每个文件的大小减小到7-10 KB。之后,他们加载得很好,没有崩溃问题。

关于wpf - 仅在32位系统上wpfgfx_v0400.dll上的APPCRASH,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/64238276/

10-11 23:01