после изменения шрифта в определенном месте имгуи крашит игру

William_Roses

Активный
Автор темы
260
26
Версия MoonLoader
.026-beta
1669055384497.png
код:
Lua:
  local glyph_ranges = imgui.GetIO().Fonts:GetGlyphRangesCyrillic()
cum = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\Arial.ttf', 16, nil, glyph_ranges) -- Arial.ttf - Название шрфита, 16 - размер
            imgui.PushFont(cum)
              if imgui.Button(u8'Проверить на обновления', imgui.ImVec2(570, 33)) then
                CheckUpdate()
                imgui.PopFont()
             end
в чем может быть проблема?
 
Решение
тоже краш
---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Assertion failed!

Program: ...ILLBOX HILL [REBUILT]\moonloader\lib\MoonImGui.dll
File: d:\dev\sources\moon-imgui\moon-imgui\imgui\imgui.cpp
Line: 4917

Expression: font && font->IsLoaded()

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts

(Press Retry to debug the application - JIT must be enabled)
---------------------------
Прервать Повтор Пропустить
---------------------------
Загружать шрифт надо в imgui.OnBeforeFrame()
Как бы ты его не пытался загружать во время рендеринга, он не загрузится

nishino akane

Участник
21
6
код:
Lua:
  local glyph_ranges = imgui.GetIO().Fonts:GetGlyphRangesCyrillic()
cum = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\Arial.ttf', 16, nil, glyph_ranges) -- Arial.ttf - Название шрфита, 16 - размер
            imgui.PushFont(cum)
              if imgui.Button(u8'Проверить на обновления', imgui.ImVec2(570, 33)) then
                CheckUpdate()
                imgui.PopFont()
             end
в чем может быть проблема?
imgui.PopFont() надо вне if блока
Lua:
local glyph_ranges = imgui.GetIO().Fonts:GetGlyphRangesCyrillic()
cum = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\Arial.ttf', 16, nil, glyph_ranges) -- Arial.ttf - Название шрфита, 16 - размер
imgui.PushFont(cum)
if imgui.Button(u8'Проверить на обновления', imgui.ImVec2(570, 33)) then
    CheckUpdate()
end
imgui.PopFont()
 

RedHolms

Известный
Проверенный
617
360
шрифт нужно загружать перед кадром
для мун имгуи и меня ничего нет, но есть для мимгуи:
( код не просто копипастить, а просмотреть и понять что да как делать )
Lua:
do -- fonts loader
   local _fonts_loaded = {}

   ImGuiLoadFont = function(font_load_desc, font_size)
      local font_name = (font_load_desc.name or table.find(ImGuiFonts, font_load_desc) or "Unknown Font")
      local font_id = font_name .. "@" .. tostring(font_size)

      if not _fonts_loaded[font_id] then
         debug("new font in _fonts_loaded with id ", font_id)
         debugf("now it's seted up to default font (%s)", tostring(ImGui.GetIO().Fonts.Fonts.Data[0]))
         debug("will be loaded at the next frame")
         _fonts_loaded[font_id] = {
            loading = true,
            try_load_again_at = 0,
            name = font_name,
            data_type = font_load_desc.data_type,
            data = font_load_desc.data,
            size = font_size,
            glyph_ranges = font_load_desc.glyph_ranges,
            font = ImGui.GetIO().Fonts.Fonts.Data[0] -- default font
         }
      end

      return _fonts_loaded[font_id].font
   end

   ImGui.OnFrame(
      function() return true end,
      function()
         for font_id, font_info in pairs(_fonts_loaded) do
            if font_info.loading then
               if timeGetTime() < font_info.try_load_again_at then goto continue end

               debugf("loading font '%s' (%s) with size %i", font_info.name, font_id, font_info.size)

               local FontAtlas = ImGui.GetIO().Fonts

               if font_info.data_type == FONT_DATATYPE_BASE85 then
                  -- todo
               elseif font_info.data_type == FONT_DATATYPE_FILE then
                  debugf("loading from file '%s'", font_info.data)

                  if not doesFileExist(font_info.data) then
                     debugf("file of font '%s' doesnt exist, try again after %i milliseconds", font_info.name, CFG_WAIT_FOR_FONT_FILE)
                     font_info.try_load_again_at = timeGetTime() + CFG_WAIT_FOR_FONT_FILE
                     goto continue
                  else
                     ImGuiPushDefaultFontToFontAtlas(font_info.size)

                     local glyph_ranges = ffi.new("const char*", font_info.glyph_ranges)
                     local font_config = ImGui.ImFontConfig()
                     font_config.MergeMode = true
                     font_info.font = FontAtlas:AddFontFromFileTTF(font_info.data, font_info.size, font_config, ffi.cast("const wchar_t*", glyph_ranges))

                     FontAtlas:Build()
                     ImGui.InvalidateFontsTexture()
                  end
               end

               font_info.loading = false
               debug("font loaded: ", font_info.font)
            ::continue:: end
         end
      end,
      function(pl) pl.HideCursor = true end
   )
end
 
  • Нравится
Реакции: William_Roses

William_Roses

Активный
Автор темы
260
26
imgui.PopFont() надо вне if блока
Lua:
local glyph_ranges = imgui.GetIO().Fonts:GetGlyphRangesCyrillic()
cum = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\Arial.ttf', 16, nil, glyph_ranges) -- Arial.ttf - Название шрфита, 16 - размер
imgui.PushFont(cum)
if imgui.Button(u8'Проверить на обновления', imgui.ImVec2(570, 33)) then
    CheckUpdate()
end
imgui.PopFont()
тоже краш
---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Assertion failed!

Program: ...ILLBOX HILL [REBUILT]\moonloader\lib\MoonImGui.dll
File: d:\dev\sources\moon-imgui\moon-imgui\imgui\imgui.cpp
Line: 4917

Expression: font && font->IsLoaded()

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts

(Press Retry to debug the application - JIT must be enabled)
---------------------------
Прервать Повтор Пропустить
---------------------------
 

RedHolms

Известный
Проверенный
617
360
тоже краш
---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Assertion failed!

Program: ...ILLBOX HILL [REBUILT]\moonloader\lib\MoonImGui.dll
File: d:\dev\sources\moon-imgui\moon-imgui\imgui\imgui.cpp
Line: 4917

Expression: font && font->IsLoaded()

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts

(Press Retry to debug the application - JIT must be enabled)
---------------------------
Прервать Повтор Пропустить
---------------------------
Загружать шрифт надо в imgui.OnBeforeFrame()
Как бы ты его не пытался загружать во время рендеринга, он не загрузится