Skip to content

Troubleshooting

rizuki edited this page Nov 30, 2026 · 8 revisions

Troubleshooting

Find a build error or runtime symptom below and apply the listed fix.

Compile errors

undefined reference to CC__MousePressedThisFrame

Link your target to ccompose or ccompose_headless so it includes the implementation. Including ccompose.h alone does not define the functions.

raylib.h: No such file or directory in a headless build

Headless builds (-DCCOMPOSE_BACKEND_RAYLIB=OFF) exclude raylib.h from the include path. Remove raylib includes and calls from headless source files, or guard that code with #ifndef CCOMPOSE_NO_BACKEND.

Runtime / Clay errors

ccompose prints Clay errors to stderr unless you set a handler with CC_SetErrorHandler. These errors identify common layout problems:

CLAY_ERROR_TYPE_UNBALANCED_OPEN_CLOSE

Clay has more open elements than close calls. Check the control flow inside container blocks:

break inside a container block.

Column("X") {
    if (fail) break;              // Incorrect: skips CC_CloseScope
    Text("ok", ...);
}

Use continue instead (it runs the for-loop's step clause, closing the element cleanly):

Column("X") {
    if (fail) continue;           // Runs the close step
    Text("ok", ...);
}

return also skips the loop's close step, even inside a helper function:

static void build_maybe(bool fail) {
    Column("X") {
        if (fail) return;         // Incorrect: skips CC_CloseScope
        Text("ok", ...);
    }
}

Let the container block finish before returning from the helper.

A goto that leaves the block also skips its close step.

Container macro used as the unbraced body of an if.

if (show_sidebar) Column("Sidebar") { ... }   // Incorrect: scoping weirdness

Wrap in braces:

if (show_sidebar) {
    Column("Sidebar") { ... }
}

An element with this ID was already previously declared during this layout

You reused the same id (ids hash by content, so this also happens with snprintf'd strings that produce the same bytes) for two different elements in the same frame. Clay requires ids to be globally unique per layout.

// Both boxes use the same id in one frame.
Row("Toolbar") {
    Box("Spacer", .layout = { .sizing = { Grow(), Fit() } });
}
Column("PrayerCard") {
    Box("Spacer", .layout = { .sizing = { Fit(), Grow() } });
}

Use an anonymous leaf for layout filler:

Row("Toolbar")      { HSpacer(); }
Column("PrayerCard") { VSpacer(); }

See Spacer and divider. For repeated named elements, format a unique id with snprintf:

for (int i = 0; i < count; ++i) {
    char id[24];
    snprintf(id, sizeof id, "row-%d", i);
    Row(id, .layout = { ... }) { /* ... */ }
}

Or use CC_IDI("row", i) + raw CLAY({ ... }) blocks if you want index-offset hashing without the format string.

CLAY_ERROR_TYPE_ELEMENTS_CAPACITY_EXCEEDED

Clay's element pool is full. Raise the cap after CC_Init():

CC_Init();
Clay_SetMaxElementCount(16384);     // default is ~8192

The new limit takes effect on the next CC_Begin.

CLAY_ERROR_TYPE_TEXT_MEASUREMENT_CAPACITY_EXCEEDED

Clay's text-measure cache is full. Raise that cap similarly:

CC_Init();
Clay_SetMaxMeasureTextCacheWordCount(32768);

CLAY_ERROR_TYPE_FLOATING_CONTAINER_PARENT_NOT_FOUND

A floating element set .floating.attachTo = CC_ATTACH_TO_ELEMENT_WITH_ID with a .parentId that doesn't match any element in the current frame. Make sure:

  • The anchor element with that id is declared earlier in the layout.
  • You're passing CLAY_ID("name").id (the hashed uint32_t), not the raw string "name".

Visual / interaction problems

Hover / click lags by one frame

Clay tests the pointer against the previous frame's layout. On the first frame an element appears, CC_Hovered and CC_Clicked return false. For detection in the frame when you move an element, test pointer coordinates against its rectangle yourself.

CC_Clicked always returns false in tests

CC__MousePressedThisFrame() always returns false in headless mode. See Pointer input in tests for simulated pointer and press handling.

A child paints outside its parent

Clay doesn't clip by default. Set .clip = { .horizontal = true, .vertical = true } on the parent if you want overflow hidden. See Scroll and clip.

Text doesn't wrap

Two possible causes:

  1. The parent has Fit() sizing on the wrap axis. Fit() shrink-wraps around children: there's no bound for text to wrap against. Switch the parent to Grow() or Fixed(px).
  2. .wrapMode = CC_TEXT_WRAP_NONE was explicitly set. Default is CC_TEXT_WRAP_WORDS.

Custom font loaded but not shown

  • Call CC_LoadFont() after CC_Init() so raylib has a GL context.

  • Check the returned id. A value of -1 means loading failed. Fall back to slot 0 if needed:

    int FONT_UI = CC_LoadFont("resources/Inter.ttf", 16);
    if (FONT_UI < 0) FONT_UI = 0;
  • Pass the returned id as .fontId, or select it with CC_InitFont. A .fontId of 0 uses the global font.

Sidebar Buttons visually overlap or don't stack

Set the parent Column's .layout.childGap, and give each Button .sizing = { Grow(), Fit() }. The width fills the sidebar, and the height fits the padding and content.

Build system quirks

raylib fetched from source fails on Linux

Install the X11 and GL development headers listed under Building: Linux, or install a raylib package so CMake can skip FetchContent.

find_package(raylib) picks up the wrong version

Override explicitly:

cmake -S . -B build \
  -DCCOMPOSE_RAYLIB_VERSION=5.5 \
  -Draylib_ROOT=/path/to/raylib/install

Or delete build/ and rebuild with -DCCOMPOSE_BACKEND_RAYLIB=OFF -DCCOMPOSE_BACKEND_RAYLIB=ON to force a clean FetchContent.

CMake complains about C_STANDARD

You asked for a standard your compiler doesn't support:

cmake -S . -B build -DCCOMPOSE_C_STANDARD=11   # safest
cmake -S . -B build -DCCOMPOSE_C_STANDARD=17
cmake -S . -B build -DCCOMPOSE_C_STANDARD=23   # needs a modern compiler

MSVC and older GCC versions may not accept 23 even with a recent ccompose.

Still stuck?

  • Read the API comments in include/ccompose.h.
  • Use tests/smoke_test.c as a minimal headless program.
  • Use examples/demo.c as an interactive raylib example.
  • File an issue in the ccompose repository with a minimal reproducer.

Clone this wiki locally