--- ray/src/rt/raypcalls.c 2020/04/06 21:49:16 2.31 +++ ray/src/rt/raypcalls.c 2024/04/30 22:25:46 2.38 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: raypcalls.c,v 2.31 2020/04/06 21:49:16 greg Exp $"; +static const char RCSid[] = "$Id: raypcalls.c,v 2.38 2024/04/30 22:25:46 greg Exp $"; #endif /* * raypcalls.c - interface for parallel rendering using Radiance @@ -147,7 +147,7 @@ static const char RCSid[] = "$Id: raypcalls.c,v 2.31 2 #include "selcall.h" #ifndef RAYQLEN -#define RAYQLEN 96 /* # rays to send at once */ +#define RAYQLEN 24 /* # rays to send at once */ #endif #ifndef MAX_RPROCS @@ -212,7 +212,7 @@ ray_pflush(void) /* send queued rays to idle childre for (i = ray_pnprocs; nc && i--; ) { if (r_proc[i].npending > 0) continue; /* child looks busy */ - n = (r_send_next - sfirst)/nc--; + n = (r_send_next - sfirst) / nc--; if (!n) continue; /* smuggle set size in crtype */ @@ -456,6 +456,8 @@ ray_popen( /* open the specified # processes */ nadd = MAX_NPROCS - ray_pnprocs; if (nadd <= 0) return; + if (nobjects <= 0) + error(CONSISTENCY, "ray_popen() called before scene loaded"); ambsync(); /* load any new ambient values */ if (shm_boundary == NULL) { /* first child process? */ preload_objs(); /* preload auxiliary data */ @@ -510,20 +512,25 @@ ray_pclose( /* close one or more child processes */ static int inclose = 0; RAY res; int i, status = 0; + /* check no child / in child */ + if (ray_pnprocs <= 0) + return; /* check recursion */ if (inclose) return; inclose++; - /* check no child / in child */ - if (ray_pnprocs <= 0) - return; /* check argument */ if ((nsub <= 0) | (nsub > ray_pnprocs)) nsub = ray_pnprocs; /* clear our ray queue */ + i = r_send_next; + r_send_next = 0; while (ray_presult(&res,0) > 0) - ; - r_send_next = 0; /* hard reset in case of error */ + ++i; + if (i) { + sprintf(errmsg, "dropped %d rays in ray_pclose()", i); + error(WARNING, errmsg); + } r_recv_first = r_recv_next = RAYQLEN; /* close send pipes */ for (i = ray_pnprocs-nsub; i < ray_pnprocs; i++) @@ -537,6 +544,10 @@ ray_pclose( /* close one or more child processes */ for (i = 0; i < nsub; ) { int j, mystatus; RT_PID pid = wait(&mystatus); + if (pid < 0) { + status = 127<<8; + break; + } for (j = ray_pnprocs-nsub; j < ray_pnprocs; j++) if (r_proc[j].pid == pid) { if (mystatus)