~henesy/smolvm

25e36a89c6b887e356a766d9d891e8179f1fa6fe — henesy 4 months ago c3aea94 master
fix double recv on pixchan (thanks kvik) - reminder that alt will auto-receive
2 files changed, 3 insertions(+), 11 deletions(-)

M main.c
M plan9_gui.c
M main.c => main.c +1 -1
@@ 49,8 49,8 @@ threadmain(int argc, char *argv[])
	// Draw a checkered cross across the middle of the window
	int i;
	for(i = 0; i < width; i++){
		drawpx(width / 2, i, i % 2);
		drawpx(i, width / 2, i % 2);
		drawpx(width / 2, i, i % 2);
	}
	
	sleep(50000);

M plan9_gui.c => plan9_gui.c +2 -10
@@ 99,8 99,6 @@ drawer(void *v)
		{pixchan, &pix, CHANRCV},
		{nil, nil, CHANEND},
	};
	
	int n ;

	// Draw loop
	for(;;){


@@ 108,11 106,7 @@ drawer(void *v)

		switch(alt(alts)){
		case 0:
			n = recv(pixchan, &pix);
			if(!n)
				print("drawer = %d\n", n);
			pixels[pix.y][pix.x] = pix.color;
			fprint(2, "drawer: (%d,%d) → %p\n", pix.x, pix.y, pix.color);
			break;

		// TODO - force draw chan?


@@ 167,7 161,7 @@ startgui(uint w)
	
	flushimage(display, 1);

	pixchan = chancreate(sizeof (Coordinate), 30);
	pixchan = chancreate(sizeof (Coordinate), width * width);
	proccreate(drawer, pixchan, 4096);

	return;


@@ 188,12 182,10 @@ drawpx(uint x, uint y, int on)
	Coordinate pix = (Coordinate){
						(Point){x,y}, 
						c};
		
	fprint(2, "drawpx: (%d,%d) → %p\n", pix.x, pix.y, pix.color);
	
	int n = send(pixchan, &pix);
	if(!n)
		print("drawpx = %d\n", n);
		print("fail: drawpx send → %d\n", n);
}

// Called by event(2) on screen resize events