summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-08-05 12:20:51 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-08-05 12:41:33 -0700
commitb80c4aa12eb9e0c5042872a2717a65b2d5483791 (patch)
tree9b9d7551dc29126fa37ac3c65e7f5e915aaf908c
parent287ddfc25ee60955e2bfc8ba8193309747639f4f (diff)
main: handle NULL res_setup a la "none" builtin
This will just quietly exit successfully if "none" is provided as the root rendering module. It's not really a case worth bothering with doing something more about... the user did this pointless thing on purpose. Let's just not crash. While here I may have fixed a bug surrounding til_quiesce() not being called on the teardown path.
-rw-r--r--src/main.c79
1 files changed, 42 insertions, 37 deletions
diff --git a/src/main.c b/src/main.c
index 1abae80..fbbd14a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -390,46 +390,51 @@ int main(int argc, const char *argv[])
exit_if(r && print_setup_as_args(&setup, !rototiller.args.gogogo) < 0,
"unable to print setup");
- exit_if(!(rototiller.module = til_lookup_module(til_settings_get_value_by_idx(setup.module_settings, 0, NULL))),
- "unable to lookup module from settings \"%s\"", til_settings_get_value_by_idx(setup.module_settings, 0, NULL));
-
- exit_if((r = til_fb_new(fb_ops, setup.title, setup.video_setup, NUM_FB_PAGES, &rototiller.fb)) < 0,
- "unable to create fb: %s", strerror(-r));
-
- exit_if(!(rototiller.stream = til_stream_new()),
- "unable to create root stream");
-
- exit_if(!fps_setup(),
- "unable to setup fps counter");
-
- gettimeofday(&rototiller.start_tv, NULL);
- exit_if((r = til_module_create_context( rototiller.module,
- rototiller.stream,
- setup.seed,
- get_ticks(&rototiller.start_tv,
- &rototiller.start_tv,
- rototiller.ticks_offset),
- 0,
- setup.module_setup,
- &rototiller.module_context)) < 0,
- "unable to create module context: %s", strerror(-r));
-
- pexit_if(pthread_create(&rototiller.thread, NULL, rototiller_thread, &rototiller) != 0,
- "unable to create dispatch thread");
-
- while (til_stream_active(rototiller.stream)) {
- if (til_fb_flip(rototiller.fb) < 0)
- break;
-
- fps_fprint(rototiller.fb, stderr);
+ if (setup.module_setup) { /* the "none" builtin produces a NULL setup successfully */
+ exit_if(!(rototiller.module = til_lookup_module(til_settings_get_value_by_idx(setup.module_settings, 0, NULL))),
+ "unable to lookup module from settings \"%s\"", til_settings_get_value_by_idx(setup.module_settings, 0, NULL));
+
+ exit_if((r = til_fb_new(fb_ops, setup.title, setup.video_setup, NUM_FB_PAGES, &rototiller.fb)) < 0,
+ "unable to create fb: %s", strerror(-r));
+
+ exit_if(!(rototiller.stream = til_stream_new()),
+ "unable to create root stream");
+
+ exit_if(!fps_setup(),
+ "unable to setup fps counter");
+
+ gettimeofday(&rototiller.start_tv, NULL);
+ exit_if((r = til_module_create_context( rototiller.module,
+ rototiller.stream,
+ setup.seed,
+ get_ticks(&rototiller.start_tv,
+ &rototiller.start_tv,
+ rototiller.ticks_offset),
+ 0,
+ setup.module_setup,
+ &rototiller.module_context)) < 0,
+ "unable to create module context: %s", strerror(-r));
+
+ pexit_if(pthread_create(&rototiller.thread, NULL, rototiller_thread, &rototiller) != 0,
+ "unable to create dispatch thread");
+
+ while (til_stream_active(rototiller.stream)) {
+ if (til_fb_flip(rototiller.fb) < 0)
+ break;
+
+ fps_fprint(rototiller.fb, stderr);
+ }
+
+ pthread_cancel(rototiller.thread);
+ pthread_join(rototiller.thread, NULL);
+ til_quiesce();
+
+ til_module_context_free(rototiller.module_context);
+ til_stream_free(rototiller.stream);
+ til_fb_free(rototiller.fb);
}
- pthread_cancel(rototiller.thread);
- pthread_join(rototiller.thread, NULL);
til_shutdown();
- til_module_context_free(rototiller.module_context);
- til_stream_free(rototiller.stream);
- til_fb_free(rototiller.fb);
return EXIT_SUCCESS;
}
© All Rights Reserved