@@ -22,13 +22,17 @@ extern twin_backend_t g_twin_backend;
2222 */
2323twin_context_t * twin_create (int width , int height )
2424{
25+ /* Runtime check for missing backend */
26+ if (!g_twin_backend .init ) {
27+ log_error ("Backend not registered - no init function" );
28+ return NULL ;
29+ }
30+
2531 assert (g_twin_backend .init && "Backend not registered" );
2632
2733 twin_context_t * ctx = g_twin_backend .init (width , height );
2834 if (!ctx ) {
29- #ifdef CONFIG_LOGGING
30- log_error ("Failed to initialize Twin context (%dx%d)" , width , height );
31- #endif
35+ log_error ("Backend initialization failed (%dx%d)" , width , height );
3236 }
3337 return ctx ;
3438}
@@ -42,10 +46,18 @@ twin_context_t *twin_create(int width, int height)
4246 */
4347void twin_destroy (twin_context_t * ctx )
4448{
49+ if (!ctx )
50+ return ;
51+
52+ /* Runtime check for missing backend */
53+ if (!g_twin_backend .exit ) {
54+ log_error ("Backend not registered - no exit function" );
55+ return ;
56+ }
57+
4558 assert (g_twin_backend .exit && "Backend not registered" );
4659
47- if (ctx )
48- g_twin_backend .exit (ctx );
60+ g_twin_backend .exit (ctx );
4961}
5062
5163/**
@@ -57,11 +69,24 @@ void twin_destroy(twin_context_t *ctx)
5769 *
5870 * @ctx : Twin context to run
5971 * @init_callback : Application initialization function (called once before
60- * event loop)
72+ * event loop)
6173 */
6274void twin_run (twin_context_t * ctx , void (* init_callback )(twin_context_t * ))
6375{
76+ /* Validate context parameter */
77+ if (!ctx ) {
78+ log_error ("NULL context passed to twin_run" );
79+ return ;
80+ }
81+
6482 assert (ctx && "NULL context passed to twin_run" );
83+
84+ /* Runtime check for missing start function */
85+ if (!g_twin_backend .start ) {
86+ log_error ("Backend has no start function - main loop not running" );
87+ return ;
88+ }
89+
6590 assert (g_twin_backend .start && "Backend start function not registered" );
6691
6792 g_twin_backend .start (ctx , init_callback );
0 commit comments