Repository: microsoft/terminal
File: src/cascadia/TerminalApp/TerminalPage.cpp (C++)

Code before:
                        return themeDictionary.Lookup(key);
                    }
                }
            }

            // We didn't find it in the requested dict, fall back to the default dictionary.
            return res.Lookup(key);
        };

        // Use our helper to lookup the theme-aware version of the resource.
        const auto tabViewBackgroundKey = winrt::box_value(L"TabViewBackground");
        const auto backgroundSolidBrush = lookup(res, requestedTheme, tabViewBackgroundKey).as<Media::SolidColorBrush>();

        til::color bgColor = backgroundSolidBrush.Color();

        if (_settings.GlobalSettings().UseAcrylicInTabRow())
        {
            const til::color backgroundColor = backgroundSolidBrush.Color();
            const auto acrylicBrush = Media::AcrylicBrush();
            acrylicBrush.BackgroundSource(Media::AcrylicBackgroundSource::HostBackdrop);
            acrylicBrush.FallbackColor(bgColor);
            acrylicBrush.TintColor(bgColor);
            acrylicBrush.TintOpacity(0.5);

            TitlebarBrush(acrylicBrush);
        }
        else if (theme.TabRow())
        {
            if (const auto tabRowBg{ _activated ? theme.TabRow().Background() :
                                                  theme.TabRow().UnfocusedBackground() })
            {
                const auto terminalBrush = [this]() -> Media::Brush {
                    if (const auto& control{ _GetActiveControl() })
                    {
                        return control.BackgroundBrush();
                    }
                    else if (auto settingsTab = _GetFocusedTab().try_as<TerminalApp::SettingsTab>())
                    {
                        return settingsTab.Content().try_as<Settings::Editor::MainPage>().BackgroundBrush();
                    }
                    return nullptr;
                }();

                const auto themeBrush{ tabRowBg.Evaluate(res, terminalBrush, true) };
                bgColor = ThemeColor::ColorFromBrush(themeBrush);
                TitlebarBrush(themeBrush);
            }
        }
        else
        {
            // Nothing was set in the theme - fall back to our original `TabViewBackground` color.

Review comment (bug):
This call is causing a crash on startup in the current build of main with the error `Access violation reading location 0x0000000000000000` (just did a git pull, clean and tried to run)

Code after:
                        return themeDictionary.Lookup(key);
                    }
                }
            }

            // We didn't find it in the requested dict, fall back to the default dictionary.
            return res.Lookup(key);
        };

        // Use our helper to lookup the theme-aware version of the resource.
        const auto tabViewBackgroundKey = winrt::box_value(L"TabViewBackground");
        const auto backgroundSolidBrush = lookup(res, requestedTheme, tabViewBackgroundKey).as<Media::SolidColorBrush>();

        til::color bgColor = backgroundSolidBrush.Color();

        if (_settings.GlobalSettings().UseAcrylicInTabRow())
        {
            const auto acrylicBrush = Media::AcrylicBrush();
            acrylicBrush.BackgroundSource(Media::AcrylicBackgroundSource::HostBackdrop);
            acrylicBrush.FallbackColor(bgColor);
            acrylicBrush.TintColor(bgColor);
            acrylicBrush.TintOpacity(0.5);

            TitlebarBrush(acrylicBrush);
        }
        else if (const auto tabRowBg{ _activated ? theme.TabRow().Background() :
                                                   theme.TabRow().UnfocusedBackground() };
                 tabRowBg != nullptr && theme.TabRow() != nullptr)
        {
            const auto terminalBrush = [this]() -> Media::Brush {
                if (const auto& control{ _GetActiveControl() })
                {
                    return control.BackgroundBrush();
                }
                else if (auto settingsTab = _GetFocusedTab().try_as<TerminalApp::SettingsTab>())
                {
                    return settingsTab.Content().try_as<Settings::Editor::MainPage>().BackgroundBrush();
                }
                return nullptr;
            }();

            const auto themeBrush{ tabRowBg.Evaluate(res, terminalBrush, true) };
            bgColor = ThemeColor::ColorFromBrush(themeBrush);
            TitlebarBrush(themeBrush);
        }
        else
        {
            // Nothing was set in the theme - fall back to our original `TabViewBackground` color.
            TitlebarBrush(backgroundSolidBrush);
        }