id: cc08684fcdf94dd08403b339ab641bdd
parent_id: 80718eb9653b493ebb48e37f5f5e01b1
item_type: 1
item_id: 6c0dcb2a567348fd9796f50c790082e4
item_updated_time: 1780467205678
title_diff: "[]"
body_diff: "[{\"diffs\":[[0,\"EmmyLua \"],[-1,\"plugin \"],[0,\"|\\\n| **Lo\"]],\"start1\":6255,\"start2\":6255,\"length1\":23,\"length2\":16},{\"diffs\":[[0,\"|\\\n\\\n---\\\n\\\n\"],[1,\"## 13. CSP Lua App Architecture & Debugging\\\n\\\n*Added 2026-06-03 — debugging blank window issue*\\\n\\\n### How CSP Lua App Windows Work\\\n\\\nCSP (Custom Shaders Patch) loads Lua apps from two locations:\\\n- **`apps/lua/<appname>/`** — user-facing apps that appear in the in-game app bar (use `[WINDOW_...]` manifest sections)\\\n- **`extension/lua/<category>/`** — system scripts (tools, game modes, cameras, FFB, PP filters) loaded by category\\\n\\\nThe window lifecycle:\\\n1. CSP reads `manifest.ini` and creates window frames from `[WINDOW_...]` sections\\\n2. For each window, CSP calls the `FUNCTION_MAIN` callback (e.g., `script.windowMain(dt)`) every frame\\\n3. If the callback function doesn't exist (because the script crashed at load time), the window frame appears but is **completely blank**\\\n\\\n### Diagnosis: Why Both Apps Show Blank Windows\\\n\\\n#### `ac-telemetry-plugin` — Likely LuaSocket failure\\\n\\\nThe script loads at the top of `src/telemetry.lua`:\\\n```lua\\\nlocal socket = require(\\\"socket.udp\\\")\\\nlocal udp = socket()\\\n```\\\n\\\nThis runs **at module load time**, not inside a function. If LuaSocket's `socket.udp` module is not available in the CSP LuaJIT environment (or if the module path differs), the `require()` call throws an error. Since this is at module scope, it cascades: `require(\\\"src.telemetry\\\")` in `main.lua` also fails → the entire script fails to load → `script.windowMain` is never defined → CSP creates the window frame from the manifest but has nothing to draw → **blank window**.\\\n\\\n**To verify**: Check CSP log at `extension/logs/csp-lua.log` or the in-game CSP console (Ctrl+Shift+C) for require errors like `module 'socket.udp' not found`.\\\n\\\n**Fix options**:\\\n1. **Wrap LuaSocket in a pcall** — defer the require to first use, or catch the error gracefully\\\n2. **Check LuaSocket availability** — CSP bundles LuaSocket but the module path might be different (e.g., `require(\\\"socket\\\")` then `socket.udp()` instead of `require(\\\"socket.udp\\\")`)\\\n3. **Use CSP's built-in networking** — CSP has `web.request()` and other HTTP/websocket APIs that may be more reliable than raw LuaSocket\\\n\\\n#### `ac-tracer` — Missing `lib/` directory\\\n\\\nThe script requires 11 modules that do not exist on disk:\\\n```\\\nlib.core.state, lib.core.settings, lib.core.scoring,\\\nlib.windows.corner_analysis, lib.windows.lap_telemetry,\\\nlib.windows.lap_picker, lib.windows.delta_bar, lib.windows.main,\\\nlib.ui.utils, lib.ui.theme, lib.traffic\\\n```\\\n\\\nThe `ac-tracer` directory only contains `ac-tracer.lua`, `manifest.ini`, icons, and `tracks/*.csv`. The entire `lib/` source tree is missing — likely it was not copied from the git repository or the distribution was incomplete. Same failure mode: first `require('lib.core.state')` throws → entire script fails → all 5 window callbacks are undefined → **5 blank windows**.\\\n\\\n### CSP Lua App Window Patterns (Reference)\\\n\\\n| Pattern | How it works | Example |\\\n|---------|-------------|---------|\\\n| `[WINDOW_...]` manifest + `script.windowXxx(dt)` | CSP creates window frame, calls your function each frame | `ac-tracer`, `ac-telemetry-plugin` |\\\n| `ui.onExclusiveHUD(callback)` | Draw during specific modes (pause, etc.) | `ac-tracer` pause overlay |\\\n| `ui.toolWindow(id, pos, size, scrollbar, movable, callback)` | Custom positioned/movable window | `ac-tracer` pause windows |\\\n| `ui.beginTransparentWindow()` / `ui.endTransparentWindow()` | Overlay debug window | `drift-challenge/debug_display.lua` |\\\n| Direct `ui.drawRectFilled()`, `ui.dwriteDrawText()` | Draw directly on screen, no window | `drift-challenge/drift_hud.lua` |\\\n\\\n### Key UI Functions Available in CSP Lua\\\n\\\n**Text rendering:**\\\n- `ui.text(str)` — simple text\\\n- `ui.textColored(str, rgbm(r,g,b,a))` — colored text\\\n- `ui.textAligned(str, align, size)` — aligned text\\\n- `ui.dwriteDrawText(str, size, pos, color)` — DirectWrite text\\\n\\\n**Drawing primitives:**\\\n- `ui.drawRectFilled(pos1, pos2, color, rounding)` — filled rectangle\\\n- `ui.drawRect(pos1, pos2, color, rounding, thickness)` — rectangle outline\\\n- `ui.drawCircleFilled(center, radius, color, segments)` — filled circle\\\n- `ui.drawLine(from, to, color, width)` — line\\\n- `ui.pathArcTo()`, `ui.pathStroke()` — arcs and paths\\\n\\\n**Layout:**\\\n- `ui.sameLine()`, `ui.offsetCursorX/Y()` — cursor positioning\\\n- `ui.availableSpaceX()`, `ui.windowSize()` — size queries\\\n- `ui.pushFont()`, `ui.popFont()` — font switching\\\n- `ui.separator()` — horizontal line\\\n\\\n**Interactive:**\\\n- `ui.button(label, size)` — clickable button\\\n- `ui.slider(propertyName, value, min, max)` — slider control\\\n- `ui.checkbox(label, value)` — toggle checkbox\\\n\\\n### CSP Built-in Lua Scripts Reference\\\n\\\nCSP ships with 96 Lua scripts in `extension/lua/` organized by category:\\\n\\\n| Category | Path | Description | UI Pattern |\\\n|----------|------|-------------|------------|\\\n| Android Auto | `cars/android_auto/` | Full infotainment system with apps | `ui.drawImage()`, `ui.childWindow()`, touchscreen |\\\n| Drift Challenge | `new-modes/drift-challenge/` | Drift scoring mode with HUD | `ui.drawRectFilled()`, `ui.dwriteDrawText()` |\\\n| Traffic Tool | `tools/csp-traffic-tool/` | AI traffic scenario editor | `ui.header()`, `ui.slider()`, `ui.button()` |\\\n| Fireworks | `fireworks/holidays/` | Holiday themed fireworks | No UI, pure rendering |\\\n| PP Filters | `pp-filters/` | Post-processing effects | `ui.windowSize()` + shader uniforms |\\\n| Camera Systems | `chaser-camera/`, `cockpit-camera/` | Camera behavior scripts | No UI |\\\n| FFB Processing | `ffb-postprocess/` | Force feedback scripts | No UI |\\\n\\\n### LuaSocket in CSP — Notes\\\n\\\nCSP bundles LuaSocket but the module loading may differ from standalone Lua:\\\n- Try `require(\\\"socket\\\")` first, then use `socket.udp()` as a method\\\n- Or try `require(\\\"socket.core\\\")` which is the C core that LuaSocket wraps\\\n- CSP also provides `web.request()` for HTTP and may have WebSocket support\\\n- Check CSP documentation or `extension/lua-shared/` for available networking modules\\\n- Alternative: Use CSP's built-in `ac.sendChatMessage()` or file-based IPC as a last resort\\\n\\\n---\\\n\\\n\"],[0,\"*Last up\"]],\"start1\":17042,\"start2\":17042,\"length1\":16,\"length2\":5994},{\"diffs\":[[0,\"026-06-0\"],[-1,\"2\"],[1,\"3\"],[0,\"*\\\n*Sourc\"]],\"start1\":23044,\"start2\":23044,\"length1\":17,\"length2\":17},{\"diffs\":[[0,\"0543fd)*\"],[1,\"\\\n*Blank window debugging: 2026-06-03 — diagnosis and CSP Lua architecture documentation*\"]],\"start1\":23218,\"start2\":23218,\"length1\":8,\"length2\":96}]"
metadata_diff: {"new":{},"deleted":[]}
encryption_cipher_text: 
encryption_applied: 0
updated_time: 2026-06-03T06:17:52.011Z
created_time: 2026-06-03T06:17:52.011Z
type_: 13