0

For many years I have been using this code to get a GdkWindow, but now it doesn't seem to return a result that can be used in other gdk functions. Any suggestions?

  GdkWindow *Tvgintf_wx::getSurface (Point2D sizeParam) {
    dcbuffer = new wxBitmap(sizeParam.getX(), sizeParam.getY());
    wxMemoryDC memory (*dcbuffer);
    GdkWindow* result = (GdkWindow*)memory.GetHandle();
    memory.SelectObject( wxNullBitmap);
    return result;
  }
  • what DOES it return? NULL? Anything else? – Igor Oct 06 '20 at 19:38
  • it returns a valid pointer, but the pointer isn't accepted as GdkWindow by other functions.The debugger won't dereference the pointer because the class is not defined (within accessible code). – user620009 Oct 07 '20 at 15:44
  • you mean the call to `wxMemoryDC::GetHandle()`? That call is not to get the `window handle`. Or you refer to something else? – Igor Oct 07 '20 at 16:11
  • yes, GetHandle returns the pointer and it has worked in the past. The current documentation says: "For example, on Windows the return value is an HDC, on OSX it is a CGContextRef and on wxGTK it will be a GdkDrawable". GtkWindow is a GdkDrawable. – user620009 Oct 07 '20 at 20:20

1 Answers1

0

wxDC::GetHandle() not always makes sense, so not always returns a valid pointer.

For your case, wxMemoryDC::GetHandle() in GTK+ returns a GdkPixmap*. And according to GDK docs a GdkPixmap is a GdkDrawable, not a GdkWindow (which derives from GdkDrawable as GdkPixmap does).

So, the line

GdkWindow* result = (GdkWindow*)memory.GetHandle();

should be

GdkDrawable* result = (GdkDrawable*)memory.GetHandle();

I don't know why your (erroneous) code worked for you in past years. Likely, the common parts of GdkWindow and GdkDrawable structs were hidding the consequences of the unsafe casting, and now something in newer gdk/gtk or the functions you use rise the issue.

Ripi2
  • 7,031
  • 1
  • 17
  • 33
  • ok, thanks. but if you know, how can i use the wxBitMap (dcbuffer) to create a cairo context? – user620009 Oct 09 '20 at 01:42
  • actually, GdkDrawable is not defined in gtk3, so what does wxDC.GetHandle return? A pointer to an undefined class is useless. There has to be some way to get a GdkWindow or there is no way to get cairo to write to a wxWindow and that would blow up a lot of vector graphics software. – user620009 Oct 13 '20 at 14:00