Skip to content

Segmentation fault in Magnum::GL::AbstractTexture::bind(int) in ImGui application after loading a font #476

@Xeverous

Description

@Xeverous

I have modified ImGui example application, adding following lines to platform constructor:

	_imgui = Magnum::ImGuiIntegration::Context([...]; // already present line

	// added code:
	ImGuiIO& io = ImGui::GetIO();
	_fontin_small_caps = io.Fonts->AddFontFromFileTTF("assets/fonts/Fontin-SmallCaps.otf", 24);
	_fontin_regular    = io.Fonts->AddFontFromFileTTF("assets/fonts/Fontin-Regular.otf", 24);
	IM_ASSERT(_fontin_small_caps);
	IM_ASSERT(_fontin_regular_caps);

	io.Fonts->Build(); // X
	IM_ASSERT(_fontin_small_caps->IsLoaded()); // X
	IM_ASSERT(_fontin_regular_caps->IsLoaded()); // X
	io.FontDefault = _fontin_regular; // X

	// renderer blend and minimal loop period further...

All of the added code is pretty much copy-pasted from https://github.com/ocornut/imgui/blob/master/docs/FONTS.md

Running on Windows (haven't tried elsewhere), the program crashes immediately upon startup:

Thread 1 received signal SIGSEGV, Segmentation fault.
(gdb) bt
#0  0x000000006334dc03 in Magnum::GL::AbstractTexture::bind(int) ()
#1  0x000000006df920de in Magnum::Shaders::Flat<2u>::bindTexture(Magnum::GL::Texture<2u>&) ()
#2  0x00000000628826f4 in Magnum::ImGuiIntegration::Context::drawFrame() ()
#3  0x0000000000403bbf in Magnum::Examples::Application::drawEvent() ()
#4  0x0000000000404a37 in Magnum::Platform::Sdl2Application::mainLoopIteration() [clone .part.0] ()
#5  0x00000000004062cf in Magnum::Platform::Sdl2Application::exec() ()
#6  0x000000000040f016 in main ()

If I comment out all 4 lines marked with X comment, then:

  • the executable does not crash
  • the UI uses built-in ImGui font
  • I can go to Demo Window->Tools->Style Editor->Fonts and select newly loaded font as default and everything works

So in summary, the crash happens only if immediately after loading a font I try to build it and set it as the default font.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions