Skip to content

ImGui can't open Windows files in non-ASCII paths when compiling with MinGW #8300

Closed
@vircon32

Description

Version/Branch of Dear ImGui:

master

Back-ends:

Any backend

Compiler, OS:

Windows + MSYS/MinGW

Full config/build information:

No response

Details:

I am building Dear ImGui with MSYS2 and MinGW. I noticed it fails to open TTF files when their Windows path has non ASCII characters. Analyzing the code the problem seems to be in ImFileOpen, in this line:

imgui/imgui.cpp

Line 2285 in c798311

#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(__CYGWIN__) && !defined(__GNUC__)

The issue is that, when compiling with MinGW, the macro __GNUC__ is defined. So, despite being in Windows, and therefore needing to use _wfopen(), the plain fopen() gets used instead. In my system I just removed that from the #endif and it now opens files correctly.

Sorry that I don't submit a PR instead, but right now I'm not sure how the MinGW compiler should be properly detected.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

#include <imgui/imgui.h>
#include <string>

int main()
{
    // init ImGui
    ImGui::CreateContext();
    ImGui::GetIO().IniFilename = NULL;
    
    // add all the standard characters
    ImVector< ImWchar > GlyphRanges;
    ImFontGlyphRangesBuilder GlyphBuilder;
    GlyphBuilder.AddRanges( ImGui::GetIO().Fonts->GetGlyphRangesDefault() );
    GlyphBuilder.BuildRanges( &GlyphRanges );
    
    // load a TTF font from a non ascii path
    std::string FontPath = "C:\\Español\\GuiFont.ttf";
    ImFont* Font = ImGui::GetIO().Fonts->AddFontFromFileTTF( FontPath.c_str(), 16, NULL, GlyphRanges.Data );
    
    // this will now crash because Font is NULL
    ImGui::GetIO().Fonts->Build();
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions