commit a081072a224f1f1788b0db23709132b85ccaa5c8
parent d18a34bddc3b152866dd5c08bcfee95b7a924f80
Author: rpa <rpa@grass>
Date: Tue, 9 Jan 2024 18:26:19 +0000
src/noise: don't forget to check menuhit for cancel, stop killing threads
Diffstat:
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/src/noise/main.c b/src/noise/main.c
@@ -18,15 +18,17 @@ struct FPSWidget {
Rectangle r;
} fps;
-long OT, NT, DT;
+int killdraw;
+
void
procdraw(void *v)
{
+ long OT, NT, DT;
Scene *sp = v;
threadsetname("draw-loop");
OT = nsec();
- for (;;) {
+ for (killdraw = 0; killdraw == 0;) {
lockdisplay(display);
if (sp->draw != nil) sp->draw(sp->aux);
draw(screen, rectaddpt(fps.r, screen->r.min), fps.img, nil, ZP);
@@ -42,7 +44,6 @@ procdraw(void *v)
}
flushimage(display, 1);
unlockdisplay(display);
- yield();
}
}
@@ -93,18 +94,24 @@ threadmain(int, char **)
switch(alt(alts)) {
case 0: // mouse
if (mouse.buttons == 1) {
- threadkill(dtid);
lockdisplay(display);
int hit = menuhit(1, mctl, &menu, nil);
unlockdisplay(display);
- if (cs->stop != nil) cs->stop(cs->aux);
- cs = plist[hit];
- if (cs->init != nil) cs->init(cs->aux);
- dtid = proccreate(procdraw, cs, 8 * 1024);
+ if (hit >= 0) {
+ // threadkill(dtid);
+ killdraw = 1;
+ lockdisplay(display);
+ unlockdisplay(display);
+ if (cs->stop != nil) cs->stop(cs->aux);
+ cs = plist[hit];
+ if (cs->init != nil) cs->init(cs->aux);
+ dtid = proccreate(procdraw, cs, 8 * 1024);
+ }
}
break;
case 1: // resize
- threadkill(dtid);
+ // threadkill(dtid);
+ killdraw = 1;
lockdisplay(display);
if (getwindow(display, Refnone) < 0)
sysfatal("resize failed: %r");