opentui icon indicating copy to clipboard operation
opentui copied to clipboard

fix: Exception when selecting text on destroyed component

Open veracioux opened this issue 2 months ago • 3 comments

Fixes https://github.com/sst/opencode/issues/4099.

veracioux avatar Nov 09 '25 00:11 veracioux

The TextBufferView is a low level API that wraps the FFI bindings and I made the guard throw so it can be caught, instead of causing a segfault when accessing destroyed native structs.

Trying to return something in some methods but not others would be inconsistent and can lead to hard to debug issues, because it hides the actual error.

Renderables are built on top of these lower level apis, which have to deal with destroyed objects. In this case the Text renderable is destroyed, which also destroys the underlying TextBufferView.

IMO the selection logic in renderer.ts needs to make sure it deals with destroyed objects and does not trigger selection methods on destroyed Renderables, as there are and might be more Renderables that handle selection, but do not use a TextBufferView, like the ASCIIFontRenderable for example.

I would try to reproduce this in a test for the renderer selection logic in src/tests and then make sure the logic does not try to update the selection on destroyed Renderables.

kommander avatar Nov 09 '25 12:11 kommander

I see, I'll try to implement it that way.

veracioux avatar Nov 09 '25 14:11 veracioux

@kommander Implemented according to your suggestion.

  • Without the fixes, the test fails reproducibly
  • Tested in opencode too, so the downstream issue should be fixed by this as well

veracioux avatar Nov 17 '25 21:11 veracioux