wolfpld / tracy

Frame profiler
https://tracy.nereid.pl/
Other
9.27k stars 643 forks source link

Crash out of the box in freetype 2.11 dependency. #266

Closed rebelroad-reinhart closed 2 years ago

rebelroad-reinhart commented 3 years ago

This may be the wrong place for this, but the current out of the box build instructions for the profiler result in a null dereference crash inside afglobal.c, which is a part of freetype.

      if ( FT_ALLOC( metrics, writing_system_class->style_metrics_size ) )
        goto Exit;

writing_system_class is null.

Some research online leads me to believe that freetype 2.11, a recent release, is the culprit. vcpkg grabs whatever the latest version of a library available and it isn't clear to me (yet) how to instruct vcpkg to get 2.10 instead. I'm a cmake user and not really a vcpkg user.

As it stands, running install_vcpkg_dependencies.bat and then doing a build will result in the crash. If you have a previous release of freetype to link you'll be fine, but the one grabbed by vcpkg at this time of posting results in the crash.

wolfpld commented 3 years ago

Does 2a994f1c fix the issue?

rebelroad-reinhart commented 3 years ago

No, the crash happens above on line 536:

        const FT_Glyph_Metrics* metrics = src_tmp.Font.LoadGlyph(src_glyph.Codepoint); // crash here
        if (metrics == NULL)
            continue;

        // Render glyph into a bitmap (currently held by FreeType)
        const FT_Bitmap* ft_bitmap = src_tmp.Font.RenderGlyphAndGetInfo(&src_glyph.Info);
        if (ft_bitmap == NULL) // integrated fix 2a994f1 is here
            continue;

A stack is probably not super useful, but it looks like this:

Tracy.exe!af_face_globals_get_metrics(AFFaceGlobalsRec globals, unsigned int gindex, unsigned int options, AFStyleMetricsRec ametrics) Line 458 C Tracy.exe!af_loader_load_glyph(AFLoaderRec loader, AFModuleRec module, FTFaceRec face, unsigned int glyph_index, int load_flags) Line 306 C Tracy.exe!af_autofitter_load_glyph(AFModuleRec module, FTGlyphSlotRec slot, FTSizeRec size, unsigned int glyph_index, int load_flags) Line 489 C Tracy.exe!FT_Load_Glyph(FTFaceRec face, unsigned int glyph_index, int load_flags) Line 981 C Tracy.exe!`anonymous namespace'::FreeTypeFont::LoadGlyph(unsigned int codepoint) Line 228 C++ Tracy.exe!ImFontAtlasBuildWithFreeTypeEx(FTLibraryRec ft_library, ImFontAtlas atlas, unsigned int extra_flags) Line 536 C++ Tracy.exe!ImFontAtlasBuildWithFreeType(ImFontAtlas atlas) Line 754 C++ Tracy.exe!ImFontAtlas::Build() Line 2286 C++ Tracy.exe!ImFontAtlas::GetTexDataAsAlpha8(unsigned char out_pixels, int out_width, int out_height, int out_bytes_per_pixel) Line 2043 C++ Tracy.exe!ImFontAtlas::GetTexDataAsRGBA32(unsigned char out_pixels, int out_width, int out_height, int out_bytes_per_pixel) Line 2057 C++ Tracy.exe!ImGui_ImplOpenGL3_CreateFontsTexture() Line 524 C++ Tracy.exe!ImGui_ImplOpenGL3_CreateDeviceObjects() Line 772 C++ Tracy.exe!ImGui_ImplOpenGL3_NewFrame() Line 295 C++ Tracy.exe!DrawContents() Line 483 C++ Tracy.exe!WindowRefreshCallback(GLFWwindow window) Line 79 C++ Tracy.exe!_glfwInputWindowDamage(_GLFWwindow window) Line 129 C Tracy.exe!windowProc(HWND__ hWnd, unsigned int uMsg, unsigned int64 wParam, int64 lParam) Line 1084 C [External Code] Tracy.exe!_glfwPlatformPollEvents() Line 1950 C Tracy.exe!glfwPollEvents() Line 1073 C Tracy.exe!main(int argc, char argv) Line 378 C++ Tracy.exe!WinMain(HINSTANCE * hInstance, HINSTANCE hPrevInstance, char lpszCmd, int nCmd) Line 47 C++ [External Code]

LiterallyAClown commented 3 years ago

I had the same issue. The culprit is that a global array in freetype, af_writing_system_classes[], which is initialized using ungodly C preprocessor tricks is empty for some reason.

As a workaround, I locally reverted the vcpkg commit that integrated freetype 2.11, removed and reinstalled freetype:

(from vcpkg's directory) git revert dd6fd59ff22c6d924b637b7352751b5c244228d6 vcpkg remove --triplet x64-windows-static freetype vcpkg install --triplet x64-windows-static freetype

I then recompiled Tracy and now it works.

rebelroad-reinhart commented 3 years ago

Thanks zlodo. That works as a temporary workaround.

ghost commented 3 years ago

I am getting the same issue. I'm 'bout to try the zlodo solution.

wolfpld commented 3 years ago

A quick solution is to remove IMGUI_ENABLE_FREETYPE from the preprocessor defines list.

ghost commented 3 years ago

A quick solution is to remove IMGUI_ENABLE_FREETYPE from the preprocessor defines list.

So, I'm gonna try this now. I've been looking for a solution for hours

wolfpld commented 3 years ago

https://github.com/ocornut/imgui/issues/4567

tksuoran commented 2 years ago

While we are waiting for the freetype fixes to go through to vcpkg - Could we have a new release, or at least executable?

wolfpld commented 2 years ago

Sorry, no new releases for now. You can find a temporary workaround in the comments above.

wolfpld commented 2 years ago

Vcpkg now has a fixed freetype 2.11.

tksuoran commented 2 years ago

I am still struggling to make the build. I've done

vcpkg.exe remove --triplet x64-windows-static freetype glfw3 capstone[arm,arm64,x86]
vcpkg.exe install --triplet x64-windows-static freetype glfw3 capstone[arm,arm64,x86]

and tried to rebuild but I still get the same crash.

wolfpld commented 2 years ago

Have you pulled the changes from the vcpkg repo?

tksuoran commented 2 years ago

I got it working - thanks!