Skip to content

Commit 12f45a5

Browse files
authored
Merge pull request #229 from Sebanisu/fix-dropdown-redbox-error
Bug: Fix red ImGui error window in combobox. Fix Duplicate case insensitive paths on Windows. Fix Nullptr deref.
2 parents 1af0958 + 1a1e505 commit 12f45a5

3 files changed

Lines changed: 43 additions & 7 deletions

File tree

src/opengl/main/generic_combo.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ class GenericCombo
17331733
// want, outside or inside your objects
17341734
if (std::ranges::empty(string))
17351735
{
1736-
return;
1736+
continue;
17371737
}
17381738
const char *c_str_value = std::ranges::data(string);
17391739
{

src/opengl/main/gui/gui.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ void gui::hovered_tiles_panel()
12061206
}
12071207
void gui::combo_coo()
12081208
{
1209-
bool remaster = m_field->is_remaster_from_fl_paths();
1209+
bool remaster = m_field && m_field->is_remaster_from_fl_paths();
12101210
if (!remaster)
12111211
{
12121212
return;
@@ -2447,7 +2447,7 @@ void gui::file_menu()
24472447
{
24482448
return;
24492449
}
2450-
bool remaster = m_field->is_remaster_from_fl_paths();
2450+
bool remaster = m_field && m_field->is_remaster_from_fl_paths();
24512451
if (remaster && ImGui::BeginMenu(gui_labels::language.data()))
24522452
{
24532453
const auto end_menu1 = glengine::ScopeGuard(&ImGui::EndMenu);
@@ -4245,7 +4245,8 @@ gui::gui(GLFWwindow *const window)
42454245
});
42464246

42474247
m_filter_window.register_is_remaster_callback(
4248-
[this]() -> bool { return m_field->is_remaster_from_fl_paths(); });
4248+
[this]() -> bool
4249+
{ return m_field && m_field->is_remaster_from_fl_paths(); });
42494250

42504251
if (m_field)
42514252
{

src/opengl/main/utilities.hpp

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,47 @@ concept erasable_range = std::ranges::range<R> && requires(R &r) {
5656
} -> std::same_as<typename R::iterator>;
5757
};
5858

59+
inline std::filesystem::path
60+
normalize_for_compare(const std::filesystem::path &p)
61+
{
62+
auto norm = p.lexically_normal();
63+
64+
#if defined(_WIN32)
65+
66+
// Windows: case-insensitive
67+
auto s = norm.native();
68+
std::ranges::transform(
69+
s,
70+
s.begin(),
71+
[](const auto ch)
72+
{
73+
return static_cast<std::remove_cvref_t<decltype(ch)>>(
74+
std::tolower(ch));
75+
});
76+
return std::filesystem::path{ s };
77+
#else
78+
// Linux / others: case-sensitive
79+
return norm;
80+
#endif
81+
}
82+
5983
template<erasable_range... R>
6084
constexpr inline bool sort_and_remove_duplicates(R &...ranges) noexcept
6185
{
62-
bool changed = false;
63-
const auto projection
64-
= [](const auto &values) { return std::get<0>(values); };
86+
bool changed = false;
87+
const auto projection = [](const auto &values)
88+
{
89+
using value_t = std::remove_cvref_t<decltype(std::get<0>(values))>;
90+
91+
if constexpr (std::is_same_v<value_t, std::filesystem::path>)
92+
{
93+
return normalize_for_compare(std::get<0>(values));
94+
}
95+
else
96+
{
97+
return std::get<0>(values);
98+
}
99+
};
65100
auto zip_view = std::ranges::views::zip(ranges...);
66101
if (!std::ranges::is_sorted(zip_view, {}, projection))
67102
{

0 commit comments

Comments
 (0)