contour-terminal / contour

Modern C++ Terminal Emulator
http://contour-terminal.org/
Apache License 2.0
2.3k stars 100 forks source link

`Assertion failed: (_buffer->begin() <= _region.data() && (_region.data() + _region.size()) <= _buffer->end()), function BufferFragment` #1511

Closed herrhotzenplotz closed 1 week ago

herrhotzenplotz commented 1 month ago

I am getting assertion failures again when dumping a lot of output (e.g. running find /)

Possibly another case of the solution to #1444

$ build/src/contour/contour
QML debugging is enabled. Only use this in a safe environment.
amdgpu: os_same_file_description couldn't determine if two DRM fds reference the same file description.
If they do, bad things may happen!
Warning: Invalid audio device ((null):0, (null))
Warning: Failed to create a gst element for the audio device, using a default audio sink ((null):0, (null))
[error] freetype: Failed to set LCD filter. unimplemented feature
Assertion failed: (_buffer->begin() <= _region.data() && (_region.data() + _region.size()) <= _buffer->end()), function BufferFragment, file /usr/home/nico/src/contour/src/crispy/BufferObject.h, line 320.
Abort trap (core dumped)
$ 

Debugger backtrace:

$ lldb -c contour.core build/src/contour/contour                                                                                                                                                                                                
(lldb) target create "build/src/contour/contour" --core "contour.core"                                                                                                                                                                          
Core file '/usr/home/nico/src/contour/contour.core' (x86_64) was loaded.
warning: This version of LLDB has no plugin for the language "assembler". Inspection of frame variables will be limited. 
(lldb) bt
* thread #1, name = 'contour', stop reason = signal SIGABRT
  * frame #0: 0x000000083330f86a libc.so.7`__sys_thr_kill at thr_kill.S:4
    frame #1: 0x0000000833287f54 libc.so.7`__raise(s=6) at raise.c:50:10
    frame #2: 0x0000000833338fc9 libc.so.7`abort at abort.c:65:8
    frame #3: 0x000000083326b2e1 libc.so.7`__assert(func=<unavailable>, file=<unavailable>, line=320, failedexpr=<unavailable>) at assert.c:49:2
    frame #4: 0x000000000062ab8d contour`vtbackend::Screen<vtbackend::SimpleCell>::emplaceCharsIntoCurrentLine(std::__1::basic_string_view<char, std::__1::char_traits<char>>, unsigned long) [inlined] crispy::BufferFragment<char>::BufferFrag
ment(this=<unavailable>, buffer=nullptr, region=crispy::BufferFragment<char>::span_type @ 0x00000a52fd469d20) at BufferObject.h:320:5
    frame #5: 0x000000000062ab74 contour`vtbackend::Screen<vtbackend::SimpleCell>::emplaceCharsIntoCurrentLine(this=0x00000064856c0c60, chars=" ", cellCount=1) at Screen.cpp:436:44
    frame #6: 0x000000000061b28e contour`vtbackend::Screen<vtbackend::SimpleCell>::tryEmplaceChars(this=0x00000064856c0c60, chars=" ", cellCount=1) at Screen.cpp:394:48
    frame #7: 0x000000000061af67 contour`vtbackend::Screen<vtbackend::SimpleCell>::writeText(this=0x00000064856c0c60, text=" ", cellCount=<unavailable>) at Screen.cpp:485:12
    frame #8: 0x000000000065fb60 contour`vtparser::Parser<vtbackend::SequenceBuilder<vtbackend::LocalSequenceHandler>, false>::parseBulkText(char const*, char const*) [inlined] vtbackend::LocalSequenceHandler::writeText(this=0x0000000893111
7f0, chars=<unavailable>, cellCount=<unavailable>) at Terminal.cpp:1267:22
    frame #9: 0x000000000065fb53 contour`vtparser::Parser<vtbackend::SequenceBuilder<vtbackend::LocalSequenceHandler>, false>::parseBulkText(char const*, char const*) [inlined] vtbackend::SequenceBuilder<vtbackend::LocalSequenceHandler>::pr
int(this=<unavailable>, chars=<unavailable>, cellCount=<unavailable>) at Terminal.cpp:1098:21
    frame #10: 0x000000000065fb4c contour`vtparser::Parser<vtbackend::SequenceBuilder<vtbackend::LocalSequenceHandler>, false>::parseBulkText(this=0x0000000893111728, begin=" \U0000001b[#}\U0000001b[#{\U0000001b[38:2:255:255:0m\U0000001b[1m
INSERT\U0000001b[#}", end="") at Parser-impl.h:399:28
    frame #11: 0x00000000006531c3 contour`vtbackend::Terminal::writeToScreenInternal(vtbackend::Screen<vtbackend::SimpleCell>&, std::__1::basic_string_view<char, std::__1::char_traits<char>>) at Parser-impl.h:329:56
    frame #12: 0x00000000006531a1 contour`vtbackend::Terminal::writeToScreenInternal(this=0x00000064856bfd20, screen=0x00000064856c0c60, vtStream=<unavailable>) at Terminal.cpp:1289:12
    frame #13: 0x0000000000652e9f contour`vtbackend::Terminal::updateIndicatorStatusLine(this=0x00000064856bfd20) at Terminal.cpp:565:9
    frame #14: 0x0000000000652bb8 contour`vtbackend::Terminal::fillRenderBufferStatusLine(this=0x00000064856bfd20, output=0x00000064856c0f88, includeSelection=true, base=(value = 24)) at Terminal.cpp:506:13
    frame #15: 0x00000000006525b7 contour`vtbackend::Terminal::fillRenderBufferInternal(this=0x00000064856bfd20, output=0x00000064856c0f88, includeSelection=<unavailable>) at Terminal.cpp:493:9
    frame #16: 0x0000000000651ff6 contour`vtbackend::Terminal::ensureFreshRenderBuffer(bool) [inlined] vtbackend::Terminal::fillRenderBuffer(this=0x00000064856bfd20, output=0x00000064856c0f88, includeSelection=true) at Terminal.cpp:430:5
    frame #17: 0x0000000000651fd7 contour`vtbackend::Terminal::ensureFreshRenderBuffer(this=0x00000064856bfd20, locked=<unavailable>) at Terminal.cpp:341:17
    frame #18: 0x0000000000651ee9 contour`vtbackend::Terminal::refreshRenderBuffer(this=<unavailable>, locked=<unavailable>) at Terminal.cpp:315:5
    frame #19: 0x0000000000686335 contour`vtrasterizer::Renderer::render(this=0x0000006482d31400, terminal=0x00000064856bfd20, pressure=false) at Renderer.cpp:291:14
    frame #20: 0x00000000005d2558 contour`contour::display::TerminalDisplay::paint(this=0x0000006481d29180) at TerminalDisplay.cpp:689:20
    frame #21: 0x00000000005d2313 contour`contour::display::TerminalDisplay::onAfterRendering(this=<unavailable>) at TerminalDisplay.cpp:716:5
    frame #22: 0x000000082f36c630 libQt6Core.so.6`___lldb_unnamed_symbol12211 + 1312
    frame #23: 0x000000082a9d069a libQt6Quick.so.6`QQuickWindowPrivate::renderSceneGraph() + 1002
    frame #24: 0x000000082ab7a267 libQt6Quick.so.6`___lldb_unnamed_symbol24594 + 1639
    frame #25: 0x000000082ab7b381 libQt6Quick.so.6`___lldb_unnamed_symbol24599 + 273
    frame #26: 0x000000082f49e1d0 libQt6Core.so.6`___lldb_unnamed_symbol13848 + 288
    frame #27: 0x000000082dd7ba75 libthr.so.3`thread_start(curthread=0x000000648542ec00) at thr_create.c:290:16
(lldb) f 4
frame #4: 0x000000000062ab8d contour`vtbackend::Screen<vtbackend::SimpleCell>::emplaceCharsIntoCurrentLine(std::__1::basic_string_view<char, std::__1::char_traits<char>>, unsigned long) [inlined] crispy::BufferFragment<char>::BufferFragment(this=<unavailable>, buffer=nullptr, region=crispy::BufferFragment<char>::span_type @ 0x00000a52fd4a5940) at BufferObject.h:320:5
   317  BufferFragment<T>::BufferFragment(buffer_object_ptr<T> buffer, gsl::span<T const> region) noexcept:
   318      _buffer { std::move(buffer) }, _region { region }
   319  {
-> 320      assert(_buffer->begin() <= _region.data() && (_region.data() + _region.size()) <= _buffer->end());
   321  }
   322 
   323  template <typename T>
(lldb) up
frame #5: 0x000000000062ab74 contour`vtbackend::Screen<vtbackend::SimpleCell>::emplaceCharsIntoCurrentLine(this=0x00000064856c0c60, chars=" ", cellCount=1) at Screen.cpp:436:44
   433                                             line.trivialBuffer().fillAttributes,
   434                                             _cursor.hyperlink,
   435                                             ColumnCount::cast_from(cellCount),
-> 436                                             crispy::BufferFragment { _terminal->currentPtyBuffer(), chars } });
   437          advanceCursorAfterWrite(ColumnCount::cast_from(cellCount));
   438      }
   439      else
(lldb) q
$ 
Yaraslaut commented 1 month ago

Hi @herrhotzenplotz, thanks for the report, i also noticed it a while ago, this bug will be closed by https://github.com/contour-terminal/contour/pull/1497 once it is merged

christianparpart commented 1 week ago

@herrhotzenplotz the linked PR sadly cannot be merged too soon, because it's actually removing some optimization path. But until it is fixed for real, we are working on a temporary workaround.

One question: Do you actively use the statusline feature? Was it enabled during the time you have been hitting the crash?

EDIT: p.s.: looking at your backtrace, looks like the statusline was enabled. You can avoid it by making sure it is disabled (when pumping out a lot of output) - until it's fixed. :)

EDIT/2: we've both looked into the source code again, looks like we can actually use this PR. Sorry for the confusion. :)

herrhotzenplotz commented 1 week ago

One question: Do you actively use the statusline feature? Was it enabled during the time you have been hitting the crash?

No I don't - in fact I find it kinda irritating (prolly because I am not used to it). And yes, it was enabled during the crash.

EDIT/2: we've both looked into the source code again, looks like we can actually use this PR. Sorry for the confusion. :)

Great stuff!