Skip to content

FIX: Guard m_side_window against null/stale pointer in ObjectGridTable (fixes Flatpak crash on 'View all object settings')#10303

Open
tinezivic wants to merge 2 commits intobambulab:masterfrom
tinezivic:fix/object-table-side-window-null-guard
Open

FIX: Guard m_side_window against null/stale pointer in ObjectGridTable (fixes Flatpak crash on 'View all object settings')#10303
tinezivic wants to merge 2 commits intobambulab:masterfrom
tinezivic:fix/object-table-side-window-null-guard

Conversation

@tinezivic
Copy link
Copy Markdown

@tinezivic tinezivic commented Apr 20, 2026

Summary

Fixes a crash when clicking View all object settings on Linux Flatpak (GNOME Platform 48). Reported in #9423, #10015, #10178.

Crash location

Valgrind output from issue #9423 (credit: @hadess):

Invalid read of size 4 at wxWindowBase::Freeze()
called from ObjectGridTable::OnSelectCell()
Address 0x1cc is not stack'd, malloc'd or recently free'd

OnSelectCell(), OnCellValueChanged(), and OnCellLeftClick() all call m_panel->m_side_window->Freeze() without verifying that m_side_window is still valid, which is the crash path identified in the Valgrind trace.

Root cause

The crash is a use-after-free during teardown caused by a race between ObjectTablePanel destruction and pending wxGrid events.

The original destructor:

ObjectTablePanel::~ObjectTablePanel()
{
    if (m_top_sizer)
        m_top_sizer->Clear(true);   // (1) deletes m_side_window (it is a child widget in the sizer)
    m_side_window = nullptr;        // (2) nulled too late — pending events can fire between (1) and (2)
    ...
}

m_side_window is a child widget owned by m_top_sizer. Clear(true) deletes it. wxWidgets can process pending events (e.g. EVT_GRID_SELECT_CELL) during widget destruction — at that point m_side_window is already deleted but the pointer has not been nulled yet, so the null-guard in OnSelectCell() does not help. The result is an invalid read at 0x1cc (m_freezeCount in wxWindowBase), exactly as seen in the Valgrind trace.

The fix is to null the pointer before Clear(true):

ObjectTablePanel::~ObjectTablePanel()
{
    m_side_window = nullptr;        // (1) null first — pending events now hit the guard safely
    if (m_top_sizer)
        m_top_sizer->Clear(true);   // (2) deletes the widget; no live pointer remains
    ...
}

Changes

  • ~ObjectTablePanel(): null m_side_window before m_top_sizer->Clear(true) to close the race window
  • OnSelectCell(): early return if m_side_window is null
  • OnCellLeftClick(): wrap Freeze/ValueChanged/Thaw in null check
  • OnCellValueChanged(): wrap Freeze/ValueChanged/Thaw in null check

The null-guards in the event handlers are still necessary as a defence in depth — the destructor fix closes the primary race, but the guards protect against any other path where m_side_window might be null or stale.

Testing

Not runtime-tested by the contributor (no Flatpak build environment available). The fix is based on static code analysis of the destructor and the crash path from the Valgrind trace. The crash has been reproduced locally on BambuStudio 2.5.0.66 Flatpak + GNOME Platform 48 (see comments below). If a maintainer or contributor can confirm the fix resolves the crash, that would be very helpful.


AI Disclosure: This fix was developed with the assistance of GitHub Copilot (Claude Sonnet 4.6). The diagnosis, code analysis, and validation were performed by the contributor. The AI assisted with code generation and diff review.

Crash reproducible on Linux Flatpak (GNOME Platform 48) when clicking
'View all object settings'. Reported in issues bambulab#9423, bambulab#10015, bambulab#10178.

Root cause: ObjectGridTable::OnSelectCell(), OnCellValueChanged(), and
OnCellLeftClick() all call m_panel->m_side_window->Freeze() without
verifying that m_side_window is still valid. On Flatpak with GNOME
Platform 48, the newer wxWidgets ABI triggers an invalid read at address
0x1cc (Freeze() dereferencing a stale vtable pointer), causing a SIGSEGV.
Valgrind output from issue bambulab#9423:
  Invalid read of size 4 in wxWindowBase::Freeze()
  called from ObjectGridTable::OnSelectCell()

Changes:
1. OnSelectCell(): early return if m_side_window is null
2. OnCellLeftClick(): wrap Freeze/ValueChanged/Thaw in null check
3. OnCellValueChanged(): wrap Freeze/ValueChanged/Thaw in null check
4. ~ObjectTablePanel(): set m_side_window = nullptr after Clear(true)
   so that any pending wxGrid events fired during teardown hit the
   guard rather than a freed pointer

Note: this addresses the symptom (crash) safely. The root cause is an
ABI mismatch between the wxWidgets version bundled in the AppImage and
the one provided by org.gnome.Platform/48 in the Flatpak runtime.

Co-authored-by: GitHub Copilot <copilot@github.com>
AI-generated: This fix was developed with the assistance of GitHub
Copilot (Claude Sonnet 4.6). The logic and diagnosis were reviewed and
validated by the contributor.
@hadess
Copy link
Copy Markdown
Contributor

hadess commented Apr 20, 2026

On Flatpak with org.gnome.Platform/x86_64/48, the runtime provides a newer wxWidgets ABI than the version bundled in the AppImage

ABI shouldn't factor into it at all, because we're recompiling from source.

So either there's a warning during the build which we're ignoring and we shouldn't, or it's a bug that just happens not to crash on the AppImage version because, for example, FORTIFY_SOURCE isn't set during its build.

If the problem is an ABI/API problem, then we should be able to find the exact upstream commit that started causing crashes.

@tinezivic
Copy link
Copy Markdown
Author

Thanks @hadess — that makes sense. I've updated the PR description to remove the ABI mismatch explanation and mark the root cause as unconfirmed.

The intent of this PR is narrower: add a defensive null-guard around m_side_window in the exact crash path shown by Valgrind (ObjectGridTable::OnSelectCellwxWindowBase::Freeze()). Even if the underlying cause turns out to be a suppressed build warning or a FORTIFY_SOURCE difference, the guard should still prevent the crash by blocking access to an invalid pointer.

I don't have a Flatpak build environment, so I can't reproduce or further diagnose from my side. If you have a direction you'd like me to investigate (build warnings, compiler flags, a specific wxWidgets upstream commit), I'm happy to look into it.

@tinezivic
Copy link
Copy Markdown
Author

tinezivic commented Apr 22, 2026

Crash reproduced locally

Environment:

  • BambuStudio 2.5.0.66 (Flatpak, com.bambulab.BambuStudio)
  • GNOME Platform 48 (Flatpak runtime)
  • Ubuntu 24.04, x86_64

Steps to reproduce:

  1. Open BambuStudio Flatpak
  2. Load any 3MF project with objects
  3. Right-click an object → "View all object settings"
  4. BambuStudio crashes immediately

Kernel crash log (journalctl -k):

bambustu_main[2033063]: segfault at 1cc ip 000059d05153e574 sp 00007fff25cad018 error 4 in bambu-studio[52b1574,59d04c905000+4f17000]
bambustu_main[2027576]: segfault at 1cc ip 000059b8feafa574 sp 00007fffe6282fb8 error 4 in bambu-studio[52b1574,59b8f9ec1000+4f17000]

The crash address 0x1cc matches exactly the Valgrind output from issue #9423:

Invalid read of size 4 at wxWindowBase::Freeze()
Address 0x1cc is not stack'd, malloc'd or recently free'd

The offset 0x1cc corresponds to the m_freezeCount field inside wxWindowBase — the read fails because m_side_window points to an already-destroyed window object (use-after-free during teardown), not an ABI mismatch. This is consistent with @hadess's assessment that the issue is likely a pre-existing use-after-free that other build configurations happen to survive.

…e window

Previously m_side_window was nulled after m_top_sizer->Clear(true), which
deletes the widget. Pending wxGrid events (e.g. EVT_GRID_SELECT_CELL) could
fire between the delete and the null assignment, bypassing the null-guards
in OnSelectCell/OnCellLeftClick/OnCellValueChanged and causing use-after-free.

Move the null assignment before Clear(true) so any pending event hits the
guard before the widget is destroyed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants