Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: wxWidgets sample segfault  (Read 2994 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 18
    • View Profile
wxWidgets sample segfault
« on: March 18, 2011, 04:53:31 am »
I am currently designing a program which uses the wxWidgets windowing library. I have a need for a 3D renderer in my program, and so I decided to use SFML for this as I had had prior experience with SFML and found it very useful and simple. I found the tutorial on integration with wxWidgets, and, erm...based my code off of it, shall we say? I have changed it and made it significantly different. However, it is still a class called wxSFMLCanvas, and the constructor is the same (aside from the debug calls to cout and the call to my function Setup() at the end):

Code: [Select]
wxSFMLCanvas::wxSFMLCanvas(wxWindow* Parent, wxWindowID Id, const wxPoint& Position, const wxSize& Size, long Style) :
wxControl(Parent, Id, Position, Size, Style)
    std::cout << "wxSFMLCanvas constructor entered." << std::endl;
    #ifdef __WXGTK__

        // GTK implementation requires to go deeper to find the
        // low-level X11 identifier of the widget
        std::cout << "Realizing wxWidget window." << std::endl;
        std::cout << "Removing double-buffering from GTK." << std::endl;
        gtk_widget_set_double_buffered(m_wxwindow, false);
        std::cout << "Getting X11 handle." << std::endl;
        GdkWindow* Win = GTK_PIZZA(m_wxwindow)->bin_window;
        std::cout << "Flushing buffer." << std::endl;
        std::cout << "Creating RenderWindow." << std::endl;
        std::cout << "Created RenderWindow from X11 widget." << std::endl;


        // Tested under Windows XP only (should work with X11
        // and other Windows versions - no idea about MacOS)
        std::cout << "Created RenderWindow from handle." << std::endl;


I am currently using wxGTK on a Linux system for this. I added the calls to cout after I discovered this problem. When the constructor is called, "wxSFMLCanvas constructor entered." and "Realizing wxWidget window." are printed, but then I get a segfault on the line gtk_widgets_realize(m_wxwindow); I am not familiar with the GTK+ libraries, or that function at all. I assume it's a problem with my m_wxwindow being a NULL pointer.

If this is something I should rather be asking in the wxWidgets forums than here, please let me know. I'm not really aware of how that code works at all or what it does, and would really appreciate any help that can be given. If anyone has come across this before, or can tell why it would occur from the code, I am willing to try just about anything. I've been working on this project for several months now and would like to see it running.

EDIT: Never mind, I appear to have solved it. It was a problem with my code. gtk_widgets_realize() was, at some point, telling it the size had changed, and so it was calling my OnSize function. The OnSize function has a few OpenGL calls, but since my RenderWindow was never initialise,d, there was no rendering context on which OpenGL could operate, leading to the segfault.