Skip to content

Allocate the client and server on the heap - #3987

Open
ann0see wants to merge 1 commit into
jamulussoftware:mainfrom
ann0see:ios/heap-allocate-client-server
Open

ann0see wants to merge 1 commit into
jamulussoftware:mainfrom
ann0see:ios/heap-allocate-client-server

Conversation

@ann0see

@ann0see ann0see commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Short description of changes

Allocate CClient and CServer with std::unique_ptr in main() instead of keeping them on the stack.

main()'s frame is sized for the larger of the two mutually exclusive branches, so it reserves roughly 341 KB of stack (aarch64 and x86-64 alike), of which CServer is ~336 KB and CClient ~9 KB. iOS gives the main thread a 1 MB stack, and the deep UIKit startup stack can overflow that. Stack corruption of that kind can hit anything that lives nearby, including Qt's own state.

Lifetime and destruction order are unchanged: the objects are still created and destroyed in the same scope, and call sites keep taking raw pointers via .get().

CClientSettings, CServerSettings, CClientDlg and CServerDlg are left on the stack — they are small (hundreds of bytes) and not the reason for the frame size. CClientRpc/CServerRpc are also left alone: they are already parented to pRpcServer, so a unique_ptr would double-free.

CHANGELOG: SKIP

Context: Fixes an issue?

Refs #3808 (upstream). It does not claim to close it: with the two Qt/iOS startup issues fixed separately — ann0see#341 (a fork-only PR, not yet submitted upstream) and the UIScene setup — I could not reproduce the original crash with or without this change.

Does this change need documentation? What needs to be documented and how?

No.

Status of this Pull Request

Working implementation, verified locally.

What is missing until this pull request can be merged?

  • It has only been built and run on an iOS simulator and needs a normal-platform check (Windows/Linux/macOS) to make sure nothing regressed in the client and server paths.
  • Whether the smaller dialog/settings objects should be converted too is left as a follow-up decision.

Checklist

  • I've verified that this Pull Request follows the general code principles
  • I tested my code and it does what I want
  • My code follows the style guide
  • I waited some time after this Pull Request was opened and all GitHub checks completed without errors.
  • I've filled all the content above

AUTOBUILD: Please build all targets

🤖 Used AI: DeepSeek V4.1 Flash, OpenCode

main() keeps CClient and CServer on the stack. On x86-64 and aarch64 that
reserves roughly 341 KB of stack for main(), almost all of it CServer
(~336 KB); CClient adds ~9 KB. iOS gives the main thread a 1 MB stack, and the
deep UIKit startup stack can overflow that, corrupting Qt state.

Allocate both objects with std::unique_ptr instead. Lifetime and destruction
order are unchanged, and the call sites keep using raw pointers via .get().

Refs jamulussoftware#3808
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

main now manages the client and server instances with std::unique_ptr. Settings, RPC adapters, dialogs, and startup operations use the managed pointers. Existing conditions for RPC setup, settings initialization, and startup connections remain in place.

Changes: Managed instance ownership

Layer / File(s) Summary
Client ownership and startup wiring
src/main.cpp
The client is now managed by std::unique_ptr. Settings, the RPC adapter, the dialog, and startup connections use its pointer.
Server ownership and startup wiring
src/main.cpp
The server is now managed by std::unique_ptr. The RPC adapter, settings, dialog, and headless directory configuration use its pointer.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested labels: bug, AI

Suggested reviewers: pljones, softins

Merge Risk: Minimal · up to aab0a

No actionable issue is established for this ownership change. Complete the usual platform checks before merging.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly summarizes the main change: allocating the client and server on the heap.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description covers the change, changelog decision, issue context, documentation, implementation status, remaining platform testing, and checklist. It clearly states that the change does not claim …
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files.

Full details: Description check

Explanation

The description covers the change, changelog decision, issue context, documentation, implementation status, remaining platform testing, and checklist. It clearly states that the change does not claim to fix issue #3808.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: f06040bc-ce1b-4c18-bcbd-147ebee27353
Commits

Reviewing files that changed from the base of the PR and between 19c50e5 and aab0ae8.

Files selected for processing: 1

  • src/main.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Comment thread src/main.cpp
Comment on lines +985 to +987
// Allocate the client on the heap: it is too large for the main
// thread stack on iOS (1 MB), where the deep UIKit startup stack
// can otherwise overflow and corrupt Qt's state.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May want to shorten this...

@ann0see

ann0see commented Nov 9, 2026 •

Copy link
Copy Markdown
Member Author

Part of the Qt 6 iOS set with #3988 and #3989.

This is not what blocked iOS from starting: the launch abort was the UIScene lifecycle issue addressed in #3988, and with that change alone the release tag launches and renders. This one removes a ~341 KB stack frame against iOS's 1 MB main thread stack, which is where the startup crash in #3808 was suspected.

Together with #3988 and #3989, the set is what allows an iOS release on Qt 6 (3.12.6 or 3.12.7, maintainers' call).

🤖 Used AI: DeepSeek V4.1 Flash, OpenCode

@ann0see

ann0see commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

Built and ran with this change on an iPhone 15 Pro (iOS 27.0.1) and in the iPhone 17, iPad Pro and Apple Vision Pro simulators. It is not what blocked the iOS launch - that was the UIScene lifecycle issue addressed in #3988 - so this is not required for a 3.12.6/3.12.7 iOS build.

🤖 Used AI: DeepSeek V4.1 Flash, OpenCode

@ann0see ann0see added this to Tracking Nov 9, 2026
@github-project-automation github-project-automation Bot moved this to Triage in Tracking Nov 9, 2026
@ann0see

ann0see commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

Low priority.

@ann0see ann0see added the AI AI generated or potentially AI generated label Nov 9, 2026
@ann0see ann0see moved this from Triage to Backlog in Tracking Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI AI generated or potentially AI generated

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant