erebus
diff liberebus/src/erebus.cc @ 31:53a98c148bf8
- introduced SurfaceGeometry to carry all the geometric information input to
BRDF sampling and evaluation functions.
- made Reflectance keep an (optional) pointer to its material
- simplified PhongRefl::sample_dir, with the help of SurfaceGeometry
- worked around microsoft's broken std::thread implementation's deadlock on join
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 07 Jun 2014 09:14:17 +0300 |
parents | 0ced900e15a7 |
children | b1fc96c71bcc |
line diff
1.1 --- a/liberebus/src/erebus.cc Sat Jun 07 06:10:21 2014 +0300 1.2 +++ b/liberebus/src/erebus.cc Sat Jun 07 09:14:17 2014 +0300 1.3 @@ -22,11 +22,13 @@ 1.4 1.5 struct erebus *erb_init(void) 1.6 { 1.7 - struct erebus *ctx; 1.8 + struct erebus *ctx = 0; 1.9 try { 1.10 ctx = new struct erebus; 1.11 + ctx->tpool = new ThreadPool; 1.12 } 1.13 catch(...) { 1.14 + delete ctx; 1.15 return 0; 1.16 } 1.17 1.18 @@ -47,7 +49,11 @@ 1.19 1.20 void erb_destroy(struct erebus *ctx) 1.21 { 1.22 - delete ctx; 1.23 + if(ctx) { 1.24 + // make sure the threadpool stops BEFORE destroying the framebuffers etc in ctx 1.25 + delete ctx->tpool; 1.26 + delete ctx; 1.27 + } 1.28 } 1.29 1.30 void erb_setopti(struct erebus *ctx, enum erb_option opt, int val) 1.31 @@ -154,9 +160,9 @@ 1.32 1.33 int erb_render_rect(struct erebus *ctx, int x, int y, int width, int height, long timeout) 1.34 { 1.35 - while(ctx->tpool.pending()) { 1.36 + while(ctx->tpool->pending()) { 1.37 if(timeout > 0) { 1.38 - long wait_interval = ctx->tpool.wait(timeout); 1.39 + long wait_interval = ctx->tpool->wait(timeout); 1.40 timeout -= wait_interval; 1.41 } else { 1.42 return 1; 1.43 @@ -180,7 +186,7 @@ 1.44 blk.sample = ctx->cur_sample; 1.45 blk.frame = ctx->cur_frame; 1.46 1.47 - ctx->tpool.add_work(std::bind(render_block, ctx, blk)); 1.48 + ctx->tpool->add_work(std::bind(render_block, ctx, blk)); 1.49 1.50 x += BLKSZ; 1.51 } 1.52 @@ -188,7 +194,7 @@ 1.53 } 1.54 1.55 ++ctx->cur_sample; 1.56 - ctx->tpool.wait(timeout); // wait for completion 1.57 + ctx->tpool->wait(timeout); // wait for completion 1.58 return ctx->cur_sample > erb_getopti(ctx, ERB_OPT_MAX_SAMPLES) ? 0 : 1; 1.59 } 1.60