{"record":{"id":"c7266050ca52f3f3","repo":"emilk/egui","slug":"failed-to-construct-c-string-from-string-for-gl-pr","errorCode":null,"errorMessage":"failed to construct C string from string for gl proc address","messagePattern":"failed to construct C string from string for gl proc address","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/eframe/src/native/glow_integration.rs","lineNumber":227,"sourceCode":"\n        let mut glutin_window_context = unsafe {\n            GlutinWindowContext::new(egui_ctx, winit_window_builder, native_options, event_loop)?\n        };\n\n        // Creates the window - must come before we create our glow context\n        glutin_window_context.initialize_window(ViewportId::ROOT, event_loop)?;\n\n        {\n            let viewport = &glutin_window_context.viewports[&ViewportId::ROOT];\n            let window = viewport.window.as_ref().unwrap(); // Can't fail - we just called `initialize_all_viewports`\n            epi_integration::apply_window_settings(window, window_settings);\n        }\n\n        let gl = unsafe {\n            profiling::scope!(\"glow::Context::from_loader_function\");\n            Arc::new(glow::Context::from_loader_function(|s| {\n                let s = std::ffi::CString::new(s)\n                    .expect(\"failed to construct C string from string for gl proc address\");\n\n                glutin_window_context.get_proc_address(&s)\n            }))\n        };\n\n        let painter = egui_glow::Painter::new(\n            gl,\n            \"\",\n            native_options.glow_options.shader_version,\n            native_options.dithering,\n        )?;\n\n        Ok((glutin_window_context, painter))\n    }\n\n    fn init_run_state(\n        &mut self,\n        event_loop: &ActiveEventLoop,","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/emilk/egui/blob/d802a982ce959839d92f4f6718fdffa41143110e/crates/eframe/src/native/glow_integration.rs#L209-L245","documentation":"eframe builds a glow::Context from a loader closure; for every GL function name glow passes in, eframe converts it with std::ffi::CString::new, which fails if the string contains an interior NUL byte ('\\0'). Real GL function names ('glGetString', 'glGenBuffers', ...) are plain ASCII literals and can never contain NUL, so this expect is effectively a defensive assert: firing it means the name supplied to the loader was corrupted or came from a mismatched/patched glow.","triggerScenarios":"Calling run_native with the Glow renderer makes glow query many proc addresses through this closure. The panic only triggers if one of those names contains an embedded NUL byte, which stock glow never produces.","commonSituations":"Practically never observed. Theoretically reachable with version-skewed forks of glow/egui_glow that pass non-literal names, or with heap corruption caused by unrelated unsafe code in the process.","solutions":["Report the panic upstream to egui with the full backtrace and glow/egui versions.","Verify the glow and egui_glow versions come from the same release: cargo tree -p glow -p egui_glow.","Audit any custom unsafe FFI code in your binary for memory corruption."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Last-resort boundary for an eframe-internal panic:\nlet result = std::panic::catch_unwind(|| {\n    eframe::run_native(\"app\", options, Box::new(|cc| Box::new(App::new(cc))))\n});\nif result.is_err() {\n    log::error!(\"renderer boot panicked; check glow/egui version skew\");\n}","preventionTips":["Keep egui, egui_glow and glow on the same release line (cargo tree -p glow -p egui_glow).","Treat any hit of this expect as memory corruption or a fork bug and capture a backtrace (RUST_BACKTRACE=1).","Avoid patching glow's loader naming; eframe relies on NUL-free literal names."],"tags":["rust","ffi","c-string","opengl","glow","panic"],"backgroundTag":"c-string-nul-byte","analyzedSha":"d802a982ce959839d92f4f6718fdffa41143110e","analyzedAt":"2026-08-16T20:07:53.954Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}