c++ console App with wxmemorydc On Linux

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
ljapc
In need of some credit
In need of some credit
Posts: 7
Joined: Sun Jun 03, 2018 2:52 pm

c++ console App with wxmemorydc On Linux

Post by ljapc »

Hi there ~

I made a console app in windows and linux with wxMemoryDC.

when I run my sample app, In Windows, No Problem
but In Linux I saw this err Message.

Code: Select all

(process:7670): Gdk-CRITICAL **: gdk_screen_get_width: assertion 'GDK_IS_SCREEN (screen)' failed

(process:7670): Gdk-CRITICAL **: gdk_screen_get_height: assertion 'GDK_IS_SCREEN (screen)' failed

(process:7670): Gdk-CRITICAL **: gdk_screen_get_width_mm: assertion 'GDK_IS_SCREEN (screen)' failed

(process:7670): Gdk-CRITICAL **: gdk_screen_get_height_mm: assertion 'GDK_IS_SCREEN (screen)' failed

(process:7670): Gdk-CRITICAL **: gdk_screen_get_width: assertion 'GDK_IS_SCREEN (screen)' failed

(process:7670): Gdk-CRITICAL **: gdk_screen_get_height: assertion 'GDK_IS_SCREEN (screen)' failed

(process:7670): Gdk-CRITICAL **: gdk_screen_get_width_mm: assertion 'GDK_IS_SCREEN (screen)' failed

(process:7670): Gdk-CRITICAL **: gdk_screen_get_height_mm: assertion 'GDK_IS_SCREEN (screen)' failed

(process:7670): Gdk-CRITICAL **: gdk_screen_get_root_window: assertion 'GDK_IS_SCREEN (screen)' failed

(process:7670): Gdk-CRITICAL **: gdk_cairo_create: assertion 'GDK_IS_WINDOW (window)' failed

(process:7670): Gdk-CRITICAL **: gdk_window_get_width: assertion 'GDK_IS_WINDOW (window)' failed

(process:7670): Gdk-CRITICAL **: gdk_window_get_height: assertion 'GDK_IS_WINDOW (window)' failed

(process:7670): GLib-GObject-WARNING **: invalid (NULL) pointer instance

(process:7670): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

(process:7670): Gtk-ERROR **: Can't create a GtkStyleContext without a display connection
Trace/breakpoint trap (core dumped)
when I use a only wxMemoryDC, there are error messages.
I don't know how to fix.

Give me a tip Please

Thank you in advance

this is a my sample code.

Code: Select all

#include <wx/wx.h>
#include <iostream>
using namespace std;

void Paint(const char *pszFilePath);

int main(int argc, char **argv)
{
	wxInitializer initializer;
	if (!initializer)
	{
		fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
		return -1;
	}

	wxInitAllImageHandlers();

	Paint("D:/test2.png");				// Windows
	//Paint("/home/test/test2.png");	// Linux

	cout << "OK" << endl;

	return 0;
}

void Paint(const char *pszFilePath)
{
	wxMemoryDC wMemDC;
	wxBitmap wBitmap(256, 256);
	wMemDC.SelectObject(wBitmap);
	wMemDC.SetBackground(*wxYELLOW_BRUSH);
	wMemDC.Clear();

	wxBitmap bitmap(40, 40);
	//bitmap.UseAlpha();
	wxMemoryDC imagememDC;
	imagememDC.SelectObject(bitmap);
	imagememDC.SetBackground(*wxWHITE_BRUSH);
	imagememDC.Clear();
	//imagememDC.SetBrush(*wxTRANSPARENT_BRUSH);
	imagememDC.SetPen(*wxRED_PEN);
	imagememDC.DrawRectangle(wxRect(0, 0, 20, 20));

	imagememDC.SelectObject(wxNullBitmap);

	wxBrush brush;
	brush.SetStyle(wxBRUSHSTYLE_STIPPLE_MASK);
	brush.SetStipple(bitmap);
	brush.SetColour(*wxWHITE);

	wxBitmap drawing(110, 110);
	imagememDC.SelectObject(drawing);
	imagememDC.SetPen(*wxGREEN_PEN);
	imagememDC.SetBrush(brush);

	imagememDC.DrawRectangle(wxRect(10, 10, 100, 100));


	wxBitmap drawingMask(110, 110);
	imagememDC.SelectObject(drawingMask);
	imagememDC.Clear();
	imagememDC.DrawRectangle(wxRect(10, 10, 100, 100));
	imagememDC.SelectObject(wxNullBitmap);
	drawing.SetMask(new wxMask(drawingMask, *wxWHITE));

	wMemDC.DrawBitmap(drawing, 10, 10, true);

	wMemDC.SetPen(wxNullPen);
	wMemDC.SetBrush(wxNullBrush);
	wMemDC.SelectObject(wxNullBitmap);

	wBitmap.SaveFile(pszFilePath, wxBITMAP_TYPE_PNG);
}
Last edited by DavidHart on Mon Jul 09, 2018 10:10 am, edited 1 time in total.
Reason: Added code tags
DavidHart
Site Admin
Site Admin
Posts: 4254
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: c++ console App with wxmemorydc On Linux

Post by DavidHart »

Hi,

Since you are getting gdk/gtk assertions, I suspect your code has crossed the border from needing only a console build to requiring a full gui one. As you are using (though not displaying) a wBitmap, that sounds reasonable to me.

Have you tried running your code in e.g. the 'minimal' sample? If it works OK there, try a standard IMPLEMENT_APP(MyApp) program with your code inside MyApp::OnInit, but no frame.

Regards,

David
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: c++ console App with wxmemorydc On Linux

Post by ONEEYEMAN »

Hi,
I don't think you can create a console application and call any GUI function.
I believe this is a nature of the *nix GUI system - be it X or Wayland. If you are accessing GUI the application has to be GUI.

It is unfortunate, but this is the way it is.

Thank you.
Post Reply