clay icon indicating copy to clipboard operation
clay copied to clipboard

[Core] Crash when introducing a scroll area mid frame

Open emoon opened this issue 9 months ago • 4 comments

Here

Clay_ScrollContainerData Clay_GetScrollContainerData(Clay_ElementId id) {
  ...
  .config = *Clay__FindElementConfigWithType(scrollContainerData->layoutElement, CLAY__ELEMENT_CONFIG_TYPE_SCROLL).scrollElementConfig,

This call above can be NULL which causes a crash due to the de-ref. I have change so I do this locally, but I'm unsure if it's correct or not (but it seems to work)

      Clay_ScrollElementConfig* scrollConfig = Clay__FindElementConfigWithType(scrollContainerData->layoutElement, CLAY__ELEMENT_CONFIG_TYPE_SCROLL).scrollElementConfig;
            if (!scrollConfig) {
                return CLAY__INIT(Clay_ScrollContainerData) CLAY__DEFAULT_STRUCT;
            }

            return CLAY__INIT(Clay_ScrollContainerData) {
                .scrollPosition = &scrollContainerData->scrollPosition,
                .scrollContainerDimensions = { scrollContainerData->boundingBox.width, scrollContainerData->boundingBox.height },
                .contentDimensions = scrollContainerData->contentSize,
                .config = *scrollConfig,
                .found = true
            };

emoon avatar Mar 06 '25 13:03 emoon

Any update on this? I still have to keep a fork because of this crash.

emoon avatar Apr 11 '25 13:04 emoon

My apologies, this one slipped through the cracks. I'll take a look at it now 🙂

nicbarker avatar Apr 11 '25 23:04 nicbarker

Your fix looks like totally the right way to do it! I've comitted it here: https://github.com/nicbarker/clay/commit/06167b4f4b5e52a29e17cfc7e61b41aa2e982ba3

nicbarker avatar Apr 11 '25 23:04 nicbarker

Thanks! :)

emoon avatar Apr 13 '25 11:04 emoon