clay
clay copied to clipboard
[Renderers/Raylib] TYPE_NONE not handled in the raylib renderer
I just got "Unhandled command type." for raylib renderer for command "CLAY__ELEMENT_CONFIG_TYPE_NONE".
My layout is just a rectangle:
Clay_RenderCommandArray CreateLayout() {
Clay_BeginLayout();
CLAY_RECTANGLE({ .color = {255,255,255,0} });
Clay_RenderCommandArray renderCommands = Clay_EndLayout();
return renderCommands;
}
full code
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// Must be defined in one file, _before_ #include "clay.h"
#define CLAY_IMPLEMENTATION
#include "clay/clay.h"
#include "clay/renderers/raylib/clay_renderer_raylib.c"
const uint32_t FONT_ID_BODY_24 = 0;
const uint32_t FONT_ID_BODY_16 = 1;
#define COLOR_ORANGE (Clay_Color) {225, 138, 50, 255}
#define COLOR_BLUE (Clay_Color) {111, 173, 162, 255}
bool reinitializeClay = false;
void HandleClayErrors(Clay_ErrorData errorData) {
printf("%s", errorData.errorText.chars);
if (errorData.errorType == CLAY_ERROR_TYPE_ELEMENTS_CAPACITY_EXCEEDED) {
reinitializeClay = true;
Clay_SetMaxElementCount(Clay_GetMaxElementCount() * 2);
} else if (errorData.errorType == CLAY_ERROR_TYPE_TEXT_MEASUREMENT_CAPACITY_EXCEEDED) {
reinitializeClay = true;
Clay_SetMaxMeasureTextCacheWordCount(Clay_GetMaxMeasureTextCacheWordCount() * 2);
}
}
Clay_RenderCommandArray CreateLayout() {
Clay_BeginLayout();
CLAY_RECTANGLE({ .color = {255,255,255,0} });
Clay_RenderCommandArray renderCommands = Clay_EndLayout();
return renderCommands;
}
int main(void) {
uint64_t totalMemorySize = Clay_MinMemorySize();
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
Clay_SetMeasureTextFunction(Raylib_MeasureText);
Clay_Initialize(clayMemory, (Clay_Dimensions) { (float)GetScreenWidth(), (float)GetScreenHeight() }, (Clay_ErrorHandler) { HandleClayErrors });
Clay_Raylib_Initialize(1024, 768, "Clay - Raylib Renderer Example", FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI | FLAG_MSAA_4X_HINT);
Raylib_fonts[FONT_ID_BODY_24] = (Raylib_Font) {
.font = LoadFontEx("resources/Roboto-Regular.ttf", 48, 0, 400),
.fontId = FONT_ID_BODY_24,
};
SetTextureFilter(Raylib_fonts[FONT_ID_BODY_24].font.texture, TEXTURE_FILTER_BILINEAR);
Raylib_fonts[FONT_ID_BODY_16] = (Raylib_Font) {
.font = LoadFontEx("resources/Roboto-Regular.ttf", 32, 0, 400),
.fontId = FONT_ID_BODY_16,
};
SetTextureFilter(Raylib_fonts[FONT_ID_BODY_16].font.texture, TEXTURE_FILTER_BILINEAR);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
if (reinitializeClay) {
Clay_SetMaxElementCount(8192);
totalMemorySize = Clay_MinMemorySize();
clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
Clay_Initialize(clayMemory, (Clay_Dimensions) { (float)GetScreenWidth(), (float)GetScreenHeight() }, (Clay_ErrorHandler) { HandleClayErrors });
reinitializeClay = false;
}
double currentTime = GetTime();
Clay_RenderCommandArray renderCommands = CreateLayout();
printf("layout time: %f microseconds\n", (GetTime() - currentTime) * 1000 * 1000);
BeginDrawing();
ClearBackground(BLACK);
Clay_Raylib_Render(renderCommands);
EndDrawing();
}
return 0;
}
It's exactly what it sounds like — nothing. In the renderer's big switch statement (the one that determines which command is drawn), add:
case CLAY_RENDER_COMMAND_TYPE_NONE:
break;
Though, you did say you were using the built-in RayLib renderer. I'm surprised it doesn't handle that already.
Anyway, Clay probably gave a CLAY_RENDER_COMMAND_TYPE_NONE because you passed it a rectangle with zero opacity.
Actually, reading over that again, it probably gave a CLAY_RENDER_COMMAND_TYPE_NONE because you didn't give it anything. Rectangles are defined within element parameters, e.g.:
CLAY(
CLAY_LAYOUT(
{.sizing = {CLAY_SIZING_GROW, CLAY_SIZING_GROW}}
),
CLAY_RECTANGLE({.color = accent_color, .cornerRadius = {8, 8, 8, 8}})
);
It is admittedly a little confusing, but I'm not the Clay maintainer. I think Barker is planning on updating the syntax for those things in the future, though.
I'll reopen this to handle the case in the renderer.
Actually, reading over that again, it probably gave a
CLAY_RENDER_COMMAND_TYPE_NONEbecause you didn't give it anything. Rectangles are defined within element parameters, e.g.:CLAY( CLAY_LAYOUT( {.sizing = {CLAY_SIZING_GROW, CLAY_SIZING_GROW}} ), CLAY_RECTANGLE({.color = accent_color, .cornerRadius = {8, 8, 8, 8}}) ); It is admittedly a little confusing, but I'm not the Clay maintainer. I think Barker is planning on updating the syntax for those things in the future, though.
True @EmmanuelMess this is your fault not a real bug, you need to add things inside the CLAY macro, on your code you don't call the CLAY macro
True
@EmmanuelMess this is your fault not a real bug, you need to add things inside the CLAY macro, on your code you don't call the CLAY macro
The issue is present in the case where nothing is drawn and an empty window is a valid window, so the raylib renderer should handle the empty case. That's why this issue is still open.