Received signal SIGSEGV, Segmentation fault. 0x00007ffff7049d26 in g_slice_alloc ()


I’m working on Multi Windowed GTK3 application in C. I’m getting

received signal SIGSEGV, Segmentation fault 0x00007ffff7049d26 in g_slice_alloc ()

During restart of my application.

My application flow goes like this.

// IniT GTK
if (!gtk_init_check (nullptr, nullptr)) [[unlikely]]
    return false;

// Create GTK Application
app = gtk_application_new ("world.tally", G_APPLICATION_FLAGS_NONE); 

// Start Event loop
g_application_run (G_APPLICATION (TWGtkApplicationWrapper::GetGtkAppPtr ()), 0, nullptr);

// Create a  invisible window just to keep the event loop running even if there are no visible window from the applicataion
sInvisibleWindow = gtk_application_window_new (sGtkApplicationPtr);

// Create visible window and its contents

With this we have our window and its interaction up and running. But when we restart we will close all the visible windows with


we will keep our invisible window so that the event loop does not quit. And then we follow the same way as earlier to bring up the new window.

But after the window comes up after restart, when i interact on the window i get

Thread 1 “TWTallySCPNativ” received signal SIGSEGV, Segmentation fault.
0x00007ffff7049d26 in g_slice_alloc () from /lib/x86_64-linux-gnu/

This error comes in different point of time, it come if I Click on Window or sometime click outside window or immediately after the window is visible

Not able to pin point where the error is from. Below are the call stack of the errors which occurred in different point of time

I can understand something is wrong with the memory but not able to find what went wrong.

Need help in fixing this error

That’s unnecessarily complicated. You can use g_application_hold() to explicitly increase the use count.

1 Like

This will block until:

  • the last window is closed
  • the application instance is freed

which means by the time the control flow reaches the next line after this one, you’ll have to restart the application.

Shoving all the logic of your application inside a single function is not how things work; you’re supposed to create the application instance, connect to the “activate” signal, and once you’re inside that callback you can create an application window.

1 Like

Hi @ebassi, yes we are following that. We are building a multithreaded application. The info to create a visible window comes from other worker threads. So till we get that info we are keeping the main thread blocked with event loop, and we use g_idle_add to switch to main thread and create the visible window

And we are connecting to activate signal and creating the invisible window there.

Apologies for the confusion, i just wanted to mention about the invisible window so i wrapped everything into single funtion

HI @fmuellner, thank you for pointing it out. ill use this to hold the event loop