andlabs / andlabs/libui

darwin/cocoa: adding uiTab to uiGrid causes a stack overflow

Abierto
#444 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
C
Estrellas
10.9k
Forks
612
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

I'm experimenting with libui for the first time using [libui-rs](https://github.com/LeoTindall/libui-rs) and have hit upon an interesting bug which, as far as I can tell from some cursory debugging, is an issue in the underlying C/ObjC libraries.

Adding `uiTab` to `uiGrid` causes a stack overflow inside the call to `uiGridAppend`, as illustrated in the following backtrace from lldb (with a few thousand duplicate entries removed for brevity):

```
frame #7822: 0x00000001001d1fb8 libui.A.dylib`-[gridView establishOurConstraints] + 7960
frame #7823: 0x00000001001d1fb8 libui.A.dylib`-[gridView establishOurConstraints] + 7960
frame #7824: 0x00000001001d1fb8 libui.A.dylib`-[gridView establishOurConstraints] + 7960
frame #7825: 0x00000001001d219f libui.A.dylib`-[gridView append:] + 127
frame #7826: 0x0000000100001c6f tm155-tool`iui::controls::layout::LayoutGrid::append::hea401a736b5872b2(self=&0x7ffeefbfef40, _ctx=&0x7ffeefbff230, control=TabGroup {
uiTab: &0x10043c190
}, left=0, height=1, xspan=1, yspan=1, expand=Neither, halign=Fill, valign=Fill) at layout.rs:361
frame #7827: 0x0000000100002538 tm155-tool`tm155_tool::MouseWindow::new::h476612a68b1c9009(ui=&0x7ffeefbff230) at main.rs:62
frame #7828: 0x000000010000295a tm155-tool`tm155_tool::main::h3acaee3fc6f51bd5 at main.rs:83
```

I think I've found what the cause is, but I'm not familiar enough with libui to know how to fix it properly. Here is what I believe is happening:

- `-[gridView append:]` is called, which adds the `gridChild` instance (containing a `uiTab`) to `children` and then calls `-[gridView establishOurConstraints]`
- This calls `uiDarwinControlSetHuggingPriority` for all of its children
- For the `uiTab` child, this goes to `uiTabSetHuggingPriority`, which sets its priority and then calls `uiDarwinNotifyEdgeHuggingChanged` on itself
- This calls `uiDarwinControlChildEdgeHuggingChanged` on its parent, the `uiGrid`, which goes to `uiGridChildEdgeHuggingChanged`
- This function calls `-[gridView establishOurConstraints]`
- ... Rinse and repeat

My first guess for a fix would be to store a flag inside the `gridView` struct so that `establishOurConstraints` can't be recursively called, but I don't know if this would maintain correct behaviour.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.