<div dir="ltr"><div><span style="font-family:monospace">Hi everyone,<br><br>  Following up on our Week 11 report, this update focuses on the primary goal for<br>  the past two weeks: investigating and fixing the "Ghost Parent" UI crash.<br><br>  After a deep and complex investigation, we may have found the root cause and<br>  have implemented a solution which needs feedback and testing. The bug seems to<br>  a multi-layered problem involving a UI deadlock, a memory-safety<br>  issue, and a loss of application context post fixing it(I will tell below).<br><br>  <b>Asynchronously launch IDE:</b>  <a href="https://gerrit.libreoffice.org/c/core/+/189922" target="_blank">https://gerrit.libreoffice.org/c/core/+/189922</a><br><br>  Just now the CI is passing which I anticipated. But, I need feedback and testing<br>  from community members and also is this approach even better or not? As of now<br>  to me it seems to be solving the situation and we also noticed a past patch<br>  trying to fix a similar UI situation with "Choose Macros UI" by hiding it -<br>  <br>  <b>m_xDialog->hide(); // tdf#126828 dismiss dialog before opening new window</b><br><br>  To my understanding there were historically some problems with how IDE was launched.<br><br>  And what I have also understood is that the BASIC IDE can  have only one single<br>  instance throughout the entire application's lifetime which means it is a Singleton.<br>  Which means that the BASIC IDE is not like a normal document. We can open many<br>  Writer documents at once, but we can only have one BASIC IDE window open at a time.<br><br>    <b>in file basctl/source/basicide/iderdll.cxx - `Shell* GetShell ()`</b><br><br>---------------------------------------------------------------------------<br><br><br><b>  Chapter 1: The Initial Symptom - The "Ghost Window"</b><br><br>  The journey began with a UI freeze. When clicking the "Edit" button in the<br>  "Tools > Macros > Edit" dialog without a document open. The IDE was launching<br>  but the parent "BASIC Macros" dialog would remain on screen as a<br>  non-functional "ghost". Clicking this ghost window would crash the application.<br><br>  Our initial finding was that this was caused by a synchronous deadlock.<br>  The code("Choose Macro") was telling the UI thread to "launch the IDE<br>  and wait", which blocked the thread from doing its other job: closing this window.<br><br>  Flowchart 1: The Synchronous Deadlock<br><br>      [UI Thread]<br>          |<br>          v<br>      [User clicks "Edit" -> Synchronous "Launch IDE" command]<br>          |<br>          +------> [This call BLOCKS the entire UI thread...]<br>          |<br>      [Thread is FROZEN, cannot process "close dialog" event]<br>          |<br>          v<br>      +------------------------+<br>      | GHOST WINDOW ON SCREEN |<br>      +------------------------+<br><br><br><br><br> <b> Chapter 2: The Mystery of the "New" Button</b><br><br>  A key clue was that clicking the "New" button worked fine, even though its<br>  code also used a synchronous launch. We investigated and found that the<br>  "New" button first calls a function, CreateMacro().<br><br>  This function does a lot of background work, like loading libraries and<br>  modifying the document model. This work accidentally? processed the pending<br>  UI events, preventing the deadlock? This is what I was able to understand<br>  from the code as with "Edit" the IDE was launching immediately but with this<br>  delaying of operations with "New Button" gave it enough time to process the UI?<br><br>  So, I am looking for feedback specially how this is going to impact as I not only<br>  have made changes for Fixing the "Edit Button" but also for the "New Button"<br>  since both of the codes were similar in how the IDE should be launched.<br>  The code related to these are in file basctl/source/basicide/macrodlg.cxx -<br>   <b>IMPL_LINK</b>(MacroChooser, ButtonHdl, weld::Button&, rButton, void)<br>    inside this clause -<br>     <b>else if (&rButton == m_xEditButton.get() || &rButton == m_xDelButton.get() || &rButton == m_xNewButton.get())<br></b><br><br><br><br>  <b>Chapter 3: The First Fix & A Deeper Bug - Memory Corruption</b><br><br>  The obvious fix for this situation was to make the launch <b>asynchronous</b><br>  ("do it later"). This solved the UI freeze, but the CI build started<br>  failing with crashes in other parts of the application which was in `sw`<br>  <i>`cppunit test CppunitTest_sw_a11y failed`</i><br><br>  This seems like a classic sign of a `use-after-free memory` bug. The new async<br>  handler was a member of the dialog object. The dialog would schedule the<br>  handler to run later and then immediately close itself. By the time the<br>  handler ran, the dialog object was destroyed, and its <span class="gmail_default">`</span>this<span class="gmail_default">`</span><span class="gmail_default"></span> pointer was<br>  invalid, causing memory corruption in the CI? Again how I understand these events.<br><br><br><br><br> <b> Chapter 4: The Second Fix & The Final Bug - The Broken UI</b><br><br>  To fix the memory corruption, we made the handler `static` as suggested<br>  by the CI error "this member function can be declared static [loplugin:staticmethods]"<br>  A static function is independent and doesn't have a `this` pointer, so it can run<br>  safely after the dialog is destroyed. This fixed the CI crashes.<br><br>  However, this introduced the final problem: the IDE would launch with a<br>  broken/default? UI with text written in the IDE "Copyright 2012-2017 Jean-Pierre LEDURE"<br>  The UI didn't know which macro to open.<br>  The static handler, while safe, had lost the UI "context".<br><br>    Which again brings us back to our WEEK 4 mail main highlight "CONTEXT"<br>    > UNO Services and Memes - Why Context Comes First<br><br><br>  Flowchart 2: The Flawed Asynchronous Fix<br><br>      [Dialog]                                  [Event Queue]<br>         |<br>         +---- "Launch IDE" message ---->           (Message is queued)<br>         |      (with no context)<br>         |<br>      [Dialog is destroyed]<br>                                                       |<br>                                                       v<br>                                            (Later...) [Static handler runs]<br>                                                       |<br>                                                       v<br>                                            [Launches a generic IDE]<br>                                                       |<br>                                                       v<br>                                            +--------------------+<br>                                            | BROKEN/DEFAULT? UI |<br>                                            +--------------------+<br><br><br><br><br><br>  <b>Chapter 5: The Definitive Solution - Finding the Context</b><br><br>  The final challenge was to launch asynchronously and safely, without losing<br>  the context. The solution was a two-step process within the static handler,<br>  especially for the "no document" case:<br><br>   1. Launch: First, tell the main application to launch the IDE. This<br>      creates the IDE window and its core object, the `basctl::Shell`.<br><br>   2. Find & Command: After the IDE appears, we use a global function we<br>      discovered, `basctl::GetShell()`, to get a pointer to the newly<br>      created IDE's shell. Now that we have the IDE's specific context, we<br>      can send it the final command telling it which macro to edit.<br><br>  Flowchart 3: The Correct? Asynchronous Solution<br><br>      [Dialog]                                  [Event Queue]<br>         |<br>         +---- "Launch IDE" message ---->           (Message is queued)<br>         |      (with macro info)<br>         |<br>      [Dialog is destroyed]<br>                                                       |<br>                                                       v<br>                                            (Later...) [Static handler runs]<br>                                                       |<br>                                                       v<br>                                            1. [Launches a generic IDE]<br>                                                       |<br>                                                       v<br>                                            2. [Finds new IDE via GetShell()]<br>                                                       |<br>                                                       v<br>                                            3. [Sends it the macro info]<br>                                                       |<br>                                                       v<br>                                            +---------------------+<br>                                            | IDE LOADS CORRECTLY |<br>                                            +---------------------+<br><br><br>  Now regarding the Object Browser I am able to split the code logically but<br>  it is all still in the same one patch for search and navigation buttons.<br><br>  Based on my mentors feedback the search UI as been improved as of now I am<br>  now we are having grouped search results with a 350ms search delay and now <br>  trying to fix the grouped search expansion bug and there are still some<br>  refinements needs to be done for the navigation buttons the vision I had for<br>  the Navigation Buttons is like how git works making an image of time instance<br>  so they would work exactly like what user selected in the UI and being able to<br>  go backward and forward what they did.<br><br>  I also made a mistake this week while trying to having a discussion over the<br>  async IDE launch patch I unecessarly sent a really long reply which I made<span class="gmail_default"> </span>overly<span class="gmail_default" style="font-family:comic sans ms,sans-serif"></span></span><span style="font-family:monospace"><br>  detailed & refined with an LLM and which isn't how professional 2 way communication<br>  works. Which is not going to happen again :)<br><br>  Now given the timelines my mentors specially Jonathan suggested for this project's<br>  extension and here is what years of experience make a difference while I was<br>  maybe in over<span class="gmail_default">confidence? estimated</span> that I would be able to resolve all these<br>  situations of bugs and be able to break this patch in multiple chronological patches.<br><br>  Which I am still far away <span class="gmail_default">since</span> this August from the mid I kept dealing<br>  with this libreoffice post mouseEvent crash which wasn't caused by the Object Browser<br>  rather this new time consuming process exposed this pre-existing problem?<br><br>  So, while solving and investigating this puzzle was interesting, on the other hand I<br>  kinda lost the time which was crucial for at least getting the Object Browser complete.<br>  Hence, his vision and experience has now made things possible to achieve and we have<br>  extended this project.<br><br>  A major chunk of this project which is Auto Code Suggestion is still remaining and<br>  can be thought as the remaining 35% of this project which has to be done quickly.<br></span><div><br></div><div><span class="gmail_default" style="font-family:arial,sans-serif">         </span><span style="font-family:arial,sans-serif"><a href="https://gerrit.libreoffice.org/c/core/+/186822" target="_blank">https://gerrit.libreoffice.org/c/core/+/186822</a></span></div><span style="font-family:monospace"><br>    I have also attached the Images related to this week's work and a text file.<br></span></div><div><br><span style="font-family:monospace"></span></div><div><span style="font-family:monospace"><br></span></div><div><div class="gmail_default"><span style="font-family:monospace">Images: </span></div><div class="gmail_default"><span style="font-family:monospace"><br></span></div><div class="gmail_default"><span style="font-family:monospace"><a href="https://bugs.documentfoundation.org/attachment.cgi?id=202573" title="View the content of the attachment"><b>BASIC IDE launch without STATIC ASYNC handler</b></a> - <a href="https://bug-attachments.documentfoundation.org/attachment.cgi?id=202573">https://bug-attachments.documentfoundation.org/attachment.cgi?id=202573</a></span></div><div class="gmail_default"><span style="font-family:monospace"><br></span></div><div class="gmail_default"><span style="font-family:monospace"><a href="https://bugs.documentfoundation.org/attachment.cgi?id=202574" title="View the content of the attachment"><b>BASIC IDE launch with STATIC ASYNC handler</b></a> - <a href="https://bug-attachments.documentfoundation.org/attachment.cgi?id=202574">https://bug-attachments.documentfoundation.org/attachment.cgi?id=202574</a></span></div><div class="gmail_default"><span style="font-family:monospace"><br></span></div><div class="gmail_default"><b style="font-family:monospace">post patch 32 grouped search</b></div><div class="gmail_default"><span style="font-family:monospace"><a href="https://bug-attachments.documentfoundation.org/attachment.cgi?id=202575">https://bug-attachments.documentfoundation.org/attachment.cgi?id=202575</a></span></div><div class="gmail_default"><span style="font-family:monospace"><a href="https://bug-attachments.documentfoundation.org/attachment.cgi?id=202576">https://bug-attachments.documentfoundation.org/attachment.cgi?id=202576</a></span></div><br><span style="font-family:monospace"></span></div><div><span style="font-family:monospace"><b><br></b></span></div><div><span style="font-family:monospace"><b><br></b></span></div><div><span style="font-family:monospace"><b>Previous Updates:</b><br><br>Week 1: <a href="https://lists.freedesktop.org/archives/libreoffice/2025-May/093264.html" target="_blank">https://lists.freedesktop.org/archives/libreoffice/2025-May/093264.html</a><br><br>Weeks 2-3: <a href="https://lists.freedesktop.org/archives/libreoffice/2025-June/093362.html" target="_blank">https://lists.freedesktop.org/archives/libreoffice/2025-June/093362.html</a><br><br>Week 4: <a href="https://lists.freedesktop.org/archives/libreoffice/2025-June/093392.html" target="_blank">https://lists.freedesktop.org/archives/libreoffice/2025-June/093392.html</a><br><br>Week 5: <a href="https://lists.freedesktop.org/archives/libreoffice/2025-June/093443.html" target="_blank">https://lists.freedesktop.org/archives/libreoffice/2025-June/093443.html</a><br><br>Week 6: <a href="https://lists.freedesktop.org/archives/libreoffice/2025-July/093493.html" target="_blank">https://lists.freedesktop.org/archives/libreoffice/2025-July/093493.html</a><br><br>Week 7: <a href="https://lists.freedesktop.org/archives/libreoffice/2025-July/093527.html" target="_blank">https://lists.freedesktop.org/archives/libreoffice/2025-July/093527.html</a><br><br>Week 8: <a href="https://lists.freedesktop.org/archives/libreoffice/2025-July/093572.html" target="_blank">https://lists.freedesktop.org/archives/libreoffice/2025-July/093572.html</a><br><br>Week 9-10: <a href="https://lists.freedesktop.org/archives/libreoffice/2025-August/093662.html" target="_blank">https://lists.freedesktop.org/archives/libreoffice/2025-August/093662.html</a><br><br>Week 11: <a href="https://lists.freedesktop.org/archives/libreoffice/2025-August/093694.html" target="_blank">https://lists.freedesktop.org/archives/libreoffice/2025-August/093694.html</a><br><br><br>If there is any mistake or something I missed in my understanding do let me know :)</span><font color="#888888"><br></font><br clear="all"></div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><span style="font-family:monospace"><b>Regards,</b></span></div><div><span style="font-family:monospace;color:rgb(153,0,255)"><b>Devansh</b></span><br></div></div></div></div>