Sign up

Pages: 1 2 3

Segmentation fault when trying to apply global css using addProviderForScreen

Hi guys, i'm developing a small board game with gtkD wrapper.

When i try to apply CSS in a global context i get Segmentation fault. This issue occurs only for x86 pc while on amd64 systems there is no problem.
Here's the code

auto style = new CssProvider();
style.loadFromPath(gladePath ~ "grid.css");
Screen globalScreen = Screen.getDefault();
writeln("CSS DEBUG: ", style);
StyleContext.addProviderForScreen(globalScreen, style, GTK_STYLE_PROVIDER_PRIORITY_USER);

Doing some writeln debug, the crash occurs exactly when executing the addProviderForScreen call. I have verified that the default Screen isn't null.

Re: Segmentation fault when trying to apply global css using addProviderForScreen

On Wed, 23 Mar 2016 18:32:23 GMT, Emily wrote:

Hi guys, i'm developing a small board game with gtkD wrapper.

When i try to apply CSS in a global context i get Segmentation fault. This issue occurs only for x86 pc while on amd64 systems there is no problem.
Here's the code

auto style = new CssProvider();
style.loadFromPath(gladePath ~ "grid.css");
Screen globalScreen = Screen.getDefault();
writeln("CSS DEBUG: ", style);
StyleContext.addProviderForScreen(globalScreen, style, GTK_STYLE_PROVIDER_PRIORITY_USER);

Doing some writeln debug, the crash occurs exactly when executing the addProviderForScreen call. I have verified that the default Screen isn't null.

What OS are you using? Linux?

I can't reproduce this on 32bit windows, testing with an empty css file.

Re: Segmentation fault when trying to apply global css using addProviderForScreen

On Wed, 23 Mar 2016 22:03:29 GMT, Mike Wey wrote:

On Wed, 23 Mar 2016 18:32:23 GMT, Emily wrote:

Hi guys, i'm developing a small board game with gtkD wrapper.

When i try to apply CSS in a global context i get Segmentation fault. This issue occurs only for x86 pc while on amd64 systems there is no problem.
Here's the code

auto style = new CssProvider();
style.loadFromPath(gladePath ~ "grid.css");
Screen globalScreen = Screen.getDefault();
writeln("CSS DEBUG: ", style);
StyleContext.addProviderForScreen(globalScreen, style, GTK_STYLE_PROVIDER_PRIORITY_USER);

Doing some writeln debug, the crash occurs exactly when executing the addProviderForScreen call. I have verified that the default Screen isn't null.

What OS are you using? Linux?

I can't reproduce this on 32bit windows, testing with an empty css file.

Thanks for response, i'm using Linux Kubuntu 14.04 32bit on a pc and 64bit on another.

Re: Segmentation fault when trying to apply global css using addProviderForScreen

On 03/24/2016 12:54 AM, Emily wrote:

On Wed, 23 Mar 2016 22:03:29 GMT, Mike Wey wrote:

On Wed, 23 Mar 2016 18:32:23 GMT, Emily wrote:

Hi guys, i'm developing a small board game with gtkD wrapper.

When i try to apply CSS in a global context i get Segmentation fault. This issue occurs only for x86 pc while on amd64 systems there is no problem.
Here's the code

 auto style = new CssProvider();
 style.loadFromPath(gladePath ~ "grid.css");
 Screen globalScreen = Screen.getDefault();
 writeln("CSS DEBUG: ", style);
 StyleContext.addProviderForScreen(globalScreen, style, GTK_STYLE_PROVIDER_PRIORITY_USER);

Doing some writeln debug, the crash occurs exactly when executing the addProviderForScreen call. I have verified that the default Screen isn't null.

What OS are you using? Linux?

I can't reproduce this on 32bit windows, testing with an empty css file.

Thanks for response, i'm using Linux Kubuntu 14.04 32bit on a pc and 64bit on another.

can you post a more complete example?

The snippet doesn't cause any issues for me on 32 bit KUbuntu 14.04.

Re: Segmentation fault when trying to apply global css using addProviderForScreen

It is a very long code, this css setup is part of very big class
that creates the View of all game.

I will post part of the class, hoping this will not be a trouble:

class View : MainWindow
{
	private {
		string[] tokenImages;
		/*TODO: The reference to board information MUST be readonly otherwise we will violate the MVC pattern. 
		Only the controller and the engine should alter the game logic!*/
		/*immutable*/ Board board;
		Tid gui;
		Tid eListener;
		Tid chatSenderThread;
		Tid nTalker;
		string myPlayerName;
		
		Builder b;
		Grid grid;
		//Frame[numBoxes] tokenBoxes;
		//Box[numBoxes] tokenBoxes;
		boardBox[numBoxes] tokenBoxes;
		Image[string] token;
		Image[2] uiDices;
		PlayersList listModel;
		TreeView lstPlayers;
		TreeViewColumn icon;
		TreeViewColumn name;
		TreeViewColumn address;
		Button dice;
		Button jwt;
		Button sintex;
		Button shares;
		SpinButton nDices;
		Label msgBox;
		Label upCard;
		Label boxInfo;
		Label nProducts;
		Label nRawMat;
		Label nEnergy;
		Label nComputer;
		Label nJwt;
		Label nSintex;
		Label nMilano;
		Label nCash;
		Label nCredito;
		Label nRoma;
		EventBox msgBoxBg;
		EventBox upCardBg;
		EventBox boxInfoBg;
		TextView chat;
		Entry msgInputBox;
		Button sendMessage;
		Window w;
	}
	
	this(ref Board board, string myPlayerName) {
		this.board = /*TODO: cast(immutable)*/board;
		version(gtk) {
			super("Manager");
			tokenImages = ["blueToken.png", "redToken.png", "violetToken.png", "yellowToken.png", "greenToken.png", "cyanToken.png"];
			
			this.myPlayerName = myPlayerName;
			
			//assign token images to all players and refresh their status info
			int i;
			foreach(name, player; board.players)
				token[name] = new Image(gladePath ~ tokenImages[i++]);
			
			//Building the model for lstPlayers TreeView
			listModel = new PlayersList(true);
			foreach(player; board.players)
				listModel.addPlayer(player.name, player.addressPort, token[player.name]);
				
			b = new Builder();
			b.addFromFile(gladePath ~ "board.glade");
			
			setupBoard();
			setupPanel();
			setupStyle();
			
			renderAllPlayers(true);
			
			//Setting all objects event handlers
			dice.addOnClicked(&actionThrowDices);
			jwt.addOnClicked(&actionUseJwt);
			sintex.addOnClicked(&actionUseSintex);
			sendMessage.addOnClicked(&actionSendMessage!Button);
			msgInputBox.addOnActivate(&actionSendMessage!Entry);
			lstPlayers.addOnRowActivated(&actionSelectPlayer);
			nDices.addOnValueChanged(&actionSetDiceNum);
			shares.addOnClicked(&actionShowShares);
			
			w.showAll();
			
			gui = spawn(&guiThreadAdapter, cast(shared)this);
			register("guiThread", gui);
			eListener = locate("eListenerThread");
			chatSenderThread = locate("chatSenderThread");
			nTalker = locate("netTalker");
			//Lets wait for a moment that spawn starts the thread before idle a job otherwise we will get a bastard "Segmentation fault"
			Thread.sleep(dur!("seconds")(2));
			startGuiRequestService();
		}
	}
	
	//Gui thread idle service to execute incoming requests for graphics manipulation
	bool guiEngine() {
		//writeln("Gui scheduler: cpu acquired!");
		/*Tid nTalker = locate("netTalker");
		Tid eListenerThread = locate("eListenerThread");
		Tid chatSenderThread = locate("chatSenderThread");*/
		receiveTimeout(dur!("msecs")( guiSchedulerTimeout ),
				//Gui requests service (UIST: user interface service for threads)
				(int request, string data, Tid thread) {
					switch (request) {
						case UI.renderDices :
							int[] dices = deserialize!(int[])(data);
							renderDices(dices);
						break;
						case UI.renderMessage :
							chatMessage(data);
						break;
						case UI.printMessage :
							printMessage(data);
						break;
						case UI.enableUserButtons :
							enableUserButtons();
						break;
						case UI.enableDiceButton :
							enableDiceButton();
						break;
						case UI.enableServiceButtons :
							enableServiceButtons();
						break;
						case UI.disableUserButtons :
							disableUserButtons();
						break;
						case UI.disableDiceButton :
							disableDiceButton();
						break;
						case UI.disableServiceButtons :
							disableServiceButtons();
						break;
						case UI.printConjuncture :
							printConjuncture(data);
						break;
						case UI.showPopupMessage :
							PopupBox.information(data, "Information");
						break;
						case UI.refreshPlayerStatus :
							refreshStatus(board.players[data]);
						break;
						case UI.showPopupAskPath :
							bool input = SpecialPopupBox.yesNo(data, "Scegli", "Produzione", "Distribuzione");
							thread.send(input);
						break;
						case UI.showPopupAskLoan, UI.showPopupAskSellShare, UI.showAskServiceToken :
							bool input = PopupBox.yesNo(data, "Scegli");
							thread.send(input);
						break;
						case UI.showAskHowManyServiceTokens :
							uint input = to!uint(createGtkApp!AskNOfTokens(gladePath ~ "askNTokens.glade")[0]);
							thread.send(input);						
						break;
						default:
							writefln("guiEngine: gui request <%s> not handled", request);
					}
				},
				//Update last updated player (special system event)
				(shared Player playerToMove, Tid thread) {
					writeln("Received updatePlayer request");
					Player player = cast(Player)playerToMove;
					renderPlayer(player.name);
					writeln(player.pos());
				},
				(Variant data) {
					writeln("GuiThread: Signal not handled, received: ", data);
				}
		);
		//writeln("Gui scheduler: cpu released!");
		return true;
	}
	
	//Gui thread
	void guiThread() {
		string[] argv = null;
		Main.init(argv);
		Main.run();
	}
	
	private {
		
		//Idles the gtk event loop with the guiEngine service
		void startGuiRequestService() {
			auto service = new Idle(&guiEngine, GPriority.DEFAULT_IDLE, true);
			writeln("DEBUG");
		}
		
		void setupBoard() {
			w = cast(Window)b.getObject("window1");
			grid = cast(Grid)b.getObject("grid");
			msgBox = cast(Label)b.getObject("msgBox");
			msgBoxBg = cast(EventBox)b.getObject("msgBoxBg");
			upCardBg = cast(EventBox)b.getObject("upCardBg");
			boxInfoBg = cast(EventBox)b.getObject("boxInfoBg");
			msgBox.setLineWrap(true);
			upCard = cast(Label)b.getObject("upCard");
			upCard.setLineWrap(true);
			boxInfo = cast(Label)b.getObject("boxInfo");
			
			//Initialize and attach gtk boxes to the grid
			uint left, top;
			foreach (j, ref tokenBox; tokenBoxes) {
				//tokenBox = new Box(GtkOrientation.HORIZONTAL, 0);
				//tokenBox = new Frame(to!string(j + 1));
				tokenBox = boardBox(new Frame(to!string(j + 1)), 
						new Box(GtkOrientation.HORIZONTAL, 0));
				if (j == 0) {
					left = 7;
					top = 12;
				}
				else if (j <= 7)
					--left;
				else if (j <= 19)
					--top;
				else if (j <= choosePath - 1)
					++left;
				else if (j <= 37) {
					left = 7;
					++top;
				}
				else if (j == 38) {
					left = 8;
					top = 1;
				}
				else if (j <= 48)
					++top;
				//grid.attach(new Image(gladePath ~ "boxes/" ~ to!string(j + 1) ~ ".png"), left, top, 1, 1);
				auto boxImage = new Image();
				boxImage.setHalign(GtkAlign.CENTER);
				if (j == 0) {
					tokenBox.frame.setName(to!string(j + 1));
					/*boxImage.setFromFile(gladePath ~ "boxes/" ~ to!string(j + 1) ~ ".png");
					grid.attach(boxImage, left, top, 1, 1);*/
				}
				else
					grid.attach(new Image(gladePath ~ "empty.png"), left, top, 1, 1);
					
				//Conjuncture boxes n.1 and n.27 width is larger (2)	
				uint width = 1;
				if ((j == 0) || (j == (choosePath - 1)))
					width = 2;
				grid.attach(tokenBox.frame, left, top, width, 1);
			}
		}
		
		void setupPanel() {
			//Setup TreeView
			lstPlayers = cast(TreeView)b.getObject("lstPlayers");
			lstPlayers.getSelection().setMode(GtkSelectionMode.BROWSE);
			lstPlayers.setFixedHeightMode(false);
			lstPlayers.setModel(listModel);
			lstPlayers.getSelection().selectPath(new TreePath("0"));
			icon = new TreeViewColumn("Pedina", new CellRendererPixbuf(), "pixbuf", 0);
			lstPlayers.appendColumn(icon);
			name = new TreeViewColumn("Nome", new CellRendererText(), "text", 1);
			lstPlayers.appendColumn(name);
			address = new TreeViewColumn("Indirizzo", new CellRendererText(), "text", 2);
			lstPlayers.appendColumn(address);
			//Panel buttons
			dice = cast(Button)b.getObject("btnDice");
			jwt = cast(Button)b.getObject("btnJwt");
			sintex = cast(Button)b.getObject("btnSintex");
			shares = cast(Button)b.getObject("btnShares");
			//Panel status info
			nProducts = cast(Label)b.getObject("nProducts");
			nDices = cast(SpinButton)b.getObject("nDices");
			nRawMat = cast(Label)b.getObject("nRawMat");
			nEnergy = cast(Label)b.getObject("nEnergy");
			nComputer = cast(Label)b.getObject("nComputer");
			nJwt = cast(Label)b.getObject("nJwt");
			nSintex = cast(Label)b.getObject("nSintex");
			nMilano = cast(Label)b.getObject("nMilano");
			nCash = cast(Label)b.getObject("nCash");
			nCredito = cast(Label)b.getObject("nCredito");
			nRoma = cast(Label)b.getObject("nRoma");
			//Setup Chat
			chat = cast(TextView)b.getObject("chat");
			msgInputBox = cast(Entry)b.getObject("msgInputBox");
			sendMessage = cast(Button)b.getObject("sendMessage");
			//On default we show the client's player info
			refreshStatus(board.players[myPlayerName]);
		}
		
		void setupStyle() {
			//The global context css seems to work only for last versions of gtk so i will not use it for now
			auto style = new CssProvider();
			style.loadFromPath(gladePath ~ "grid.css");
			Screen globalScreen = Display.getDefault().getDefaultScreen();
			writeln("CSS DEBUG: ", style);
			StyleContext.addProviderForScreen(globalScreen, style, GTK_STYLE_PROVIDER_PRIORITY_USER);

		}
	}
}

Re: Segmentation fault when trying to apply global css using addProviderForScreen

I confirm you are right, i tested with a small program the first snippet in the 32bit Kubuntu and i haven't got the SegFault, i'm trying to imagine what should be the trouble, maybe in the multithreading i made.

Re: Segmentation fault when trying to apply global css using addProviderForScreen

On 03/24/2016 09:56 PM, Emily wrote:

It is a very long code, this css setup is part of very big class
that creates the View of all game.

I will post part of the class, hoping this will not be a trouble:

I can reproduce the segfault when i compile and run the application/game
from your github account.

It's gonna take some time to figure out how that differs from the
isolated snippet.

Re: Segmentation fault when trying to apply global css using addProviderForScreen

On Thu, 24 Mar 2016 23:32:20 +0100, Mike Wey wrote:

On 03/24/2016 09:56 PM, Emily wrote:

It is a very long code, this css setup is part of very big class
that creates the View of all game.

I will post part of the class, hoping this will not be a trouble:

I can reproduce the segfault when i compile and run the application/game
from your github account.

It's gonna take some time to figure out how that differs from the
isolated snippet.

I thank you for all help :)

One question, how did you find my github project? Simply curiosity :D

Re: Segmentation fault when trying to apply global css using addProviderForScreen

On 03/24/2016 11:24 PM, Emily wrote:

I confirm you are right, i tested with a small program the first snippet in the 32bit Kubuntu and i haven't got the SegFault, i'm trying to imagine what should be the trouble, maybe in the multithreading i made.

All the calls to GtkD / GTK should be coming from the same thread.

Re: Segmentation fault when trying to apply global css using addProviderForScreen

On Thu, 24 Mar 2016 23:39:11 +0100, Mike Wey wrote:

On 03/24/2016 11:24 PM, Emily wrote:

I confirm you are right, i tested with a small program the first snippet in the 32bit Kubuntu and i haven't got the SegFault, i'm trying to imagine what should be the trouble, maybe in the multithreading i made.

All the calls to GtkD / GTK should be coming from the same thread.

Indeed i created an Engine in guiThread to accept commands for Gtk manipulation from other threads, so its only guiThread that makes calls except for the construction of View class, made before guiThread spawn, that is made by the ownerTid (Main thread)

Pages: 1 2 3