Re: X Window System error



Hi,

I'm using Gtkmm with ogre as embedded window...and everything is wokrinh fine...a send you code that I use

Trigve

----- Original Message ----
From: jams.biz <jams biz free fr>
To: gtkmm-list gnome org
Sent: Wednesday, January 24, 2007 12:58:06 AM
Subject: X Window System error

Hi,
I've made an application using gtkmm for GUI and Ogre3D to ember 3D rendering inside the GUI. Everything works fine up to gtkmm 2.8.8 (and corresponding dependency). But it crash systematically when using more recent version (for exemple current stable version gtkmm 2.10 and glibmm 2.12).

Here is message I get :
The program '********' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadMatch (invalid parameter attributes)'.
  (Details: serial 229 error_code 8 request_code 152 minor_code 1)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)

To embed Ogre3D into gtkmm, I derive a class from Gtk::Socket and here is a part of the code :


mGdkWindow = get_window();
if(!mGdkWindow) throw std::runtime_error("OgreWidget gdkwindow was not created in time\n");
GdkWindow* parent = mGdkWindow->gobj();
GdkDisplay* display = gdk_drawable_get_display(GDK_DRAWABLE(parent));
GdkScreen* screen = gdk_drawable_get_screen(GDK_DRAWABLE(parent));

Display* xdisplay = GDK_DISPLAY_XDISPLAY(display);
Screen* xscreen = GDK_SCREEN_XSCREEN(screen);
int screen_number = XScreenNumberOfScreen(xscreen);
// XID xid_parent = (XID)get_id();
XID xid_parent = GDK_WINDOW_XWINDOW(parent);

And here is the string I give to Ogre to create its rendering window :

         sprintf(Xembed, "%d:%d:%d", xdisplay, screen_number, xid_parent);

Any help would be really appriciated !
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list



Want to start your own business? Learn how on Yahoo! Small Business.
#include "stdafx.h"

#include "GtkOgreWidget.h"
#ifdef WIN32
#else
#include<gdk/gdkx.h>
#endif




int GtkOgreWidget::m_ID = 0;



GtkOgreWidget::GtkOgreWidget(void)

    : Glib::ObjectBase("GtkOgre"), Gtk::Widget(), m_pWindow(NULL)

{

    set_flags(Gtk::NO_WINDOW);

    //This shows the GType name, which must be used in the RC file.

    std::cout << "GType name: " <<G_OBJECT_TYPE_NAME(gobj()) << std::endl;

    

}



GtkOgreWidget::~GtkOgreWidget(void)

{

}



void GtkOgreWidget::on_size_request(Gtk::Requisition* requisition)

{

    //Initialize the output parameter:

    *requisition = Gtk::Requisition();



    //Discover the total amount of minimum space needed by this widget.



    //Let's make this simple example widget always need 50 by 50:

    requisition->height = 200;

    requisition->width = 200;

}



void GtkOgreWidget::on_size_allocate(Gtk::Allocation& allocation)

{

    std::cout << "GtkOgreWidget::on_size_allocate" << std::endl;

    //Do something with the space that we have actually been given:

    //(We will not be given heights or widths less than we have requested, though we might get more)



    //Use the offered allocation for this container:

    set_allocation(allocation);



    if(m_refGdkWindow)

        m_refGdkWindow->move_resize(allocation.get_x(), allocation.get_y(), allocation.get_width(), allocation.get_height());



    
    if (m_pWindow)
    {
        /* Let Ogre update the viewport dimensions. */
#ifdef WIN32
        getRenderWindow()->windowMovedOrResized();
#else
        getRenderWindow()->resize(allocation.get_width(), allocation.get_height());
//        getRenderWindow()->windowMovedOrResized();
#endif
//        std::cout << "Width:" << getRenderWindow()->getWidth() << ", Height:" << getRenderWindow()->getHeight() << std::endl;
        on_expose_event(NULL);
    }

}



void GtkOgreWidget::on_map()

{

    //Call base class:

    Gtk::Widget::on_map();

}



void GtkOgreWidget::on_unmap()

{

    //Call base class:

    Gtk::Widget::on_unmap();

}



void GtkOgreWidget::on_realize()

{

    //Call base class:

    Gtk::Widget::on_realize();

    if(!m_refGdkWindow)

    {

        //Create the GdkWindow:

        GdkWindowAttr attributes;

        memset(&attributes, 0, sizeof(attributes));



        Gtk::Allocation allocation = get_allocation();



        //Set initial position and size of the Gdk::Window:

        attributes.x = allocation.get_x();

        attributes.y = allocation.get_y();

//        attributes.width = allocation.get_width();

        attributes.width = 200;
//        attributes.height = 200;
        attributes.height = allocation.get_height();

//        attributes.event_mask = Gdk::ALL_EVENTS_MASK;
        attributes.event_mask = GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
        attributes.window_type = GDK_WINDOW_CHILD;

        attributes.wclass = GDK_INPUT_OUTPUT;



        m_refGdkWindow = Gdk::Window::create(get_window(), &attributes, GDK_WA_X | GDK_WA_Y);

//        m_refGdkWindow = Gdk::Window::create(get_parent_window(), &attributes, GDK_WA_X | GDK_WA_Y);

        Ogre::NameValuePairList params;

#ifdef WIN32

        params["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned long)GDK_WINDOW_HWND(m_refGdkWindow->gobj()));

    

#else

        Display *p_xdisplay = GDK_DISPLAY_XDISPLAY(m_refGdkWindow->get_display()->gobj());

        Screen *p_xscreen = GDK_SCREEN_XSCREEN(m_refGdkWindow->get_screen()->gobj());

        int screen_number = XScreenNumberOfScreen(p_xscreen);

        Window xid_window = GDK_WINDOW_XWINDOW(m_refGdkWindow->gobj());
        Visual *p_visual = GDK_VISUAL_XVISUAL(get_visual()->gobj());
        XVisualInfo info;
        memset(&info, 0, sizeof(XVisualInfo));
        info.visual = p_visual;
        info.visualid = XVisualIDFromVisual(p_visual);
        info.screen = screen_number;
        info.depth = 24;
        params["externalWindowHandle"] =

            Ogre::StringConverter::toString(reinterpret_cast<unsigned long>(p_xdisplay)) + ":" +

            Ogre::StringConverter::toString(static_cast<unsigned int>(screen_number)) + ":" +
            Ogre::StringConverter::toString(static_cast<unsigned long>(xid_window)) + ":" +
            Ogre::StringConverter::toString(reinterpret_cast<unsigned long>(&info));

#endif

        



        m_pWindow = Ogre::Root::getSingleton().createRenderWindow("GtkOgreWidget" + Ogre::StringConverter::toString(++m_ID),
            allocation.get_width(), allocation.get_height(), false, &params);
//        std::cout << "Is auto aupdate:" << m_pWindow->isAutoUpdated() << std::endl;
        m_pWindow->setAutoUpdated(false);
        

        unset_flags(Gtk::NO_WINDOW);

        set_window(m_refGdkWindow);

//        m_refGdkWindow->set_events(Gdk::ALL_EVENTS_MASK);
        set_double_buffered(false);

        //make the widget receive expose events

        m_refGdkWindow->set_user_data(gobj());

        m_refGdkWindow->set_back_pixmap(Glib::RefPtr<Gdk::Pixmap>(), false);

        //Allocate a GC for use in on_expose_event():

    }

}



void GtkOgreWidget::on_unrealize()

{

     m_refGdkWindow.clear();



     //Call base class:

     Gtk::Widget::on_unrealize();

}



bool GtkOgreWidget::on_expose_event(GdkEventExpose* event)

{

//    std::cout << "GtkOgreWidget::onExpose" << std::endl;

    //Draw on the Gdk::Window:

//    m_refGdkWindow->clear();
    if(getRenderWindow() != NULL)
    {
        getRenderWindow()->update();
    }
//    std::cout << "Width:" << getRenderWindow()->getWidth() << ", Heiht:" << getRenderWindow()->getHeight() << std::endl;

    return true;

}



Ogre::RenderWindow* GtkOgreWidget::getRenderWindow(void) throw()

{

//    assert(m_pWindow);

    return m_pWindow;

}



#ifdef WIN32

unsigned long GtkOgreWidget::getHWND(void) throw()

{

    return (unsigned long)GDK_WINDOW_HWND(m_refGdkWindow->get_parent()->gobj());

}

#endif

#pragma once



#include <gtkmm/widget.h>

#include <Ogre.h>



class GtkOgreWidget : public Gtk::Widget

{

    // Attributes

private:

    //! GDK window.

    Glib::RefPtr<Gdk::Window> m_refGdkWindow;

    //! Ogre render window.

    Ogre::RenderWindow* m_pWindow;

    //! ID of window.

    static int m_ID;



    // Operations

public:

    //! Get ogre render window.

    Ogre::RenderWindow* getRenderWindow(void) throw();



#ifdef WIN32

    //! Get win32 HANDLE to window.

    unsigned long getHWND(void) throw();

#endif



protected:

    virtual void on_size_request(Gtk::Requisition* requisition);

    virtual void on_size_allocate(Gtk::Allocation& allocation);

    virtual void on_map();

    virtual void on_unmap();

    virtual void on_realize();

    virtual void on_unrealize();

    virtual bool on_expose_event(GdkEventExpose* event);

    



    // Construction/Destruction

public:

    GtkOgreWidget(void);

    virtual ~GtkOgreWidget(void);

};




Don't be flakey. Get Yahoo! Mail for Mobile and
always stay connected to friends.
#include "stdafx.h"
#include "GtkOgreWidget.h"
#ifdef WIN32
#else
#include<gdk/gdkx.h>
#endif


int GtkOgreWidget::m_ID = 0;

GtkOgreWidget::GtkOgreWidget(void)
	: Glib::ObjectBase("GtkOgre"), Gtk::Widget(), m_pWindow(NULL)
{
	set_flags(Gtk::NO_WINDOW);
	//This shows the GType name, which must be used in the RC file.
	std::cout << "GType name: " <<G_OBJECT_TYPE_NAME(gobj()) << std::endl;
	
}

GtkOgreWidget::~GtkOgreWidget(void)
{
}

void GtkOgreWidget::on_size_request(Gtk::Requisition* requisition)
{
	//Initialize the output parameter:
	*requisition = Gtk::Requisition();

	//Discover the total amount of minimum space needed by this widget.

	//Let's make this simple example widget always need 50 by 50:
	requisition->height = 200;
	requisition->width = 200;
}

void GtkOgreWidget::on_size_allocate(Gtk::Allocation& allocation)
{
	std::cout << "GtkOgreWidget::on_size_allocate" << std::endl;
	//Do something with the space that we have actually been given:
	//(We will not be given heights or widths less than we have requested, though we might get more)

	//Use the offered allocation for this container:
	set_allocation(allocation);

	if(m_refGdkWindow)
		m_refGdkWindow->move_resize(allocation.get_x(), allocation.get_y(), allocation.get_width(), allocation.get_height());

	
	if (m_pWindow)
	{
		/* Let Ogre update the viewport dimensions. */
#ifdef WIN32
		getRenderWindow()->windowMovedOrResized();
#else
		getRenderWindow()->resize(allocation.get_width(), allocation.get_height());
//		getRenderWindow()->windowMovedOrResized();
#endif
//		std::cout << "Width:" << getRenderWindow()->getWidth() << ", Height:" << getRenderWindow()->getHeight() << std::endl;
		on_expose_event(NULL);
	}
}

void GtkOgreWidget::on_map()
{
	//Call base class:
	Gtk::Widget::on_map();
}

void GtkOgreWidget::on_unmap()
{
	//Call base class:
	Gtk::Widget::on_unmap();
}

void GtkOgreWidget::on_realize()
{
	//Call base class:
	Gtk::Widget::on_realize();
	if(!m_refGdkWindow)
	{
		//Create the GdkWindow:
		GdkWindowAttr attributes;
		memset(&attributes, 0, sizeof(attributes));

		Gtk::Allocation allocation = get_allocation();

		//Set initial position and size of the Gdk::Window:
		attributes.x = allocation.get_x();
		attributes.y = allocation.get_y();
//		attributes.width = allocation.get_width();
		attributes.width = 200; 
//		attributes.height = 200; 
		attributes.height = allocation.get_height();
//		attributes.event_mask = Gdk::ALL_EVENTS_MASK;
		attributes.event_mask = GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
		attributes.window_type = GDK_WINDOW_CHILD;
		attributes.wclass = GDK_INPUT_OUTPUT;

		m_refGdkWindow = Gdk::Window::create(get_window(), &attributes, GDK_WA_X | GDK_WA_Y);
//		m_refGdkWindow = Gdk::Window::create(get_parent_window(), &attributes, GDK_WA_X | GDK_WA_Y);
		Ogre::NameValuePairList params; 
#ifdef WIN32
		params["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned long)GDK_WINDOW_HWND(m_refGdkWindow->gobj()));
	
#else
		Display *p_xdisplay = GDK_DISPLAY_XDISPLAY(m_refGdkWindow->get_display()->gobj());
		Screen *p_xscreen = GDK_SCREEN_XSCREEN(m_refGdkWindow->get_screen()->gobj());
		int screen_number = XScreenNumberOfScreen(p_xscreen);
		Window xid_window = GDK_WINDOW_XWINDOW(m_refGdkWindow->gobj());
		Visual *p_visual = GDK_VISUAL_XVISUAL(get_visual()->gobj());
		XVisualInfo info;
		memset(&info, 0, sizeof(XVisualInfo));
		info.visual = p_visual;
		info.visualid = XVisualIDFromVisual(p_visual);
		info.screen = screen_number;
		info.depth = 24;
		params["externalWindowHandle"] = 
			Ogre::StringConverter::toString(reinterpret_cast<unsigned long>(p_xdisplay)) + ":" +
			Ogre::StringConverter::toString(static_cast<unsigned int>(screen_number)) + ":" +
			Ogre::StringConverter::toString(static_cast<unsigned long>(xid_window)) + ":" +
			Ogre::StringConverter::toString(reinterpret_cast<unsigned long>(&info));
#endif
		

		m_pWindow = Ogre::Root::getSingleton().createRenderWindow("GtkOgreWidget" + Ogre::StringConverter::toString(++m_ID),
			allocation.get_width(), allocation.get_height(), false, &params);
//		std::cout << "Is auto aupdate:" << m_pWindow->isAutoUpdated() << std::endl;
		m_pWindow->setAutoUpdated(false);
		
		unset_flags(Gtk::NO_WINDOW);
		set_window(m_refGdkWindow);
//		m_refGdkWindow->set_events(Gdk::ALL_EVENTS_MASK);
		set_double_buffered(false);
		//make the widget receive expose events
		m_refGdkWindow->set_user_data(gobj());
		m_refGdkWindow->set_back_pixmap(Glib::RefPtr<Gdk::Pixmap>(), false);
		//Allocate a GC for use in on_expose_event():
	}
}

void GtkOgreWidget::on_unrealize()
{
	 m_refGdkWindow.clear();

	 //Call base class:
	 Gtk::Widget::on_unrealize();
}

bool GtkOgreWidget::on_expose_event(GdkEventExpose* event)
{
//	std::cout << "GtkOgreWidget::onExpose" << std::endl;
	//Draw on the Gdk::Window:
//    m_refGdkWindow->clear();
	if(getRenderWindow() != NULL)
	{
		getRenderWindow()->update();
	}
//	std::cout << "Width:" << getRenderWindow()->getWidth() << ", Heiht:" << getRenderWindow()->getHeight() << std::endl;
	return true;
}

Ogre::RenderWindow* GtkOgreWidget::getRenderWindow(void) throw()
{
//	assert(m_pWindow);
	return m_pWindow;
}

#ifdef WIN32
unsigned long GtkOgreWidget::getHWND(void) throw()
{
	return (unsigned long)GDK_WINDOW_HWND(m_refGdkWindow->get_parent()->gobj());
}
#endif
#pragma once

#include <gtkmm/widget.h>
#include <Ogre.h>

class GtkOgreWidget : public Gtk::Widget
{
	// Attributes
private:
	//! GDK window.
	Glib::RefPtr<Gdk::Window> m_refGdkWindow;
	//! Ogre render window.
	Ogre::RenderWindow* m_pWindow;
	//! ID of window.
	static int m_ID;

	// Operations
public:
	//! Get ogre render window.
	Ogre::RenderWindow* getRenderWindow(void) throw();

#ifdef WIN32
	//! Get win32 HANDLE to window.
	unsigned long getHWND(void) throw();
#endif

protected:
	virtual void on_size_request(Gtk::Requisition* requisition);
	virtual void on_size_allocate(Gtk::Allocation& allocation);
	virtual void on_map();
	virtual void on_unmap();
	virtual void on_realize();
	virtual void on_unrealize();
	virtual bool on_expose_event(GdkEventExpose* event);
	

	// Construction/Destruction
public:
	GtkOgreWidget(void);
	virtual ~GtkOgreWidget(void);
};


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]