GTK+ 3 MessageBox

Hello everyone,

I've been trying to implement a simple messagebox in GTK+ 3 on Linux (32-bit Ubuntu). I use the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <gtk/gtk.h>

#include <iostream>

namespace Platform
{
    void Initialize(int argc, char* argv[])
    {
        gtk_init(&argc, &argv);
    }
    void ShowMessage(const char* msg)
    {
        std::cerr << msg << std::endl;
        GtkWidget* dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Error");
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", msg);
        gtk_dialog_run(GTK_DIALOG (dialog));
        gtk_widget_destroy(GTK_WIDGET(dialog));
    }
}


The code compiles without any errors. At runtime the code results in a segmentation fault. Using gdb I managed to find out that the line the application crashes on it the call to gtk_dialog_run. Does anyone know why this could be happening?
Does anyone know why this could be happening?

No idea, but FYI the code compiles and runs on 64-bit Debian with the addition of a main function.
The program entry point looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <GLFW/glfw3.h>

#include "config.h" //Configured constants
#include "platform.h" //Platform specific functions
//Further includes

int main(int argc, char* argv[])
{
    Platform::Initialize(argc, argv); //Initialize platform
    glfwInit(); //Initialize GLFW
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

    GLFWwindow* window = glfwCreateWindow(Config::WINDOWWIDTH, 
        Config::WINDOWHEIGHT, "Main window", nullptr, nullptr); //Create GLFW window
    if(window == nullptr)
    {
        Platform::ShowMessage("Failed to create the main window"); //Show message on failure
        glfwTerminate();
        return 1;
    }
    //Further code
    return 0;
}


Could it have something to do with the fact that I initialize GLFW after I initialize GTK? Maybe it uses GTK internally and it could be initialized twice?

EDIT:

It appears the call to glfwInit was the problem. Calling glfwInit after calling gtk_init seems to cause some parts of GTK3 to cause segmentation faults. The problem was solves by calling glfwInit before Platform::Initialize.

Thank you for your help. I thought GTK code was the problem.
Last edited on
Topic archived. No new replies allowed.