Skip to content

Conversation

@TwhomeGH
Copy link

@TwhomeGH TwhomeGH commented Jan 1, 2026

概述

修正 audio 模組中 AudioQueue 緩衝區管理、callback race condition 以及記憶體釋放問題,並改善 Xcode genic/ios 打包可編譯性。

問題

  1. audio_destroy() 先 Dispose queue 後釋放 buffers,可能造成 callback 存取已釋放 buffer crash。
  2. AudioQueueBuffer 的 mUserData 可能發生非法記憶體讀取造成crash
  3. callback 在 audio 銷毀期間沒有防護,存在 race condition。
  4. legacy loc/mem offset 實作不再使用。
  5. audio_clear() 未檢查 null,可能 crash。

修正

  1. 新增 struct audio.isStopping,callback 在 destroy 期間會跳過。
  2. 將 mUserData 由指向可變動記憶體的指標改為穩定的 buffer index,避免音訊非同步 callback 中可能發生的非法記憶體存取與 crash。
  3. audio_destroy() 釋放順序:
    • Stop queue
    • Free AudioQueue buffers
    • Free silence buffer
    • Dispose queue
    • Free ctx->rcm.rc
    • Free ctx
  4. 清理 loc/mem 陣列,RecycleChain 改用 array 索引。
  5. audio_clear() 增加 null 檢查。
  6. audio_queue_callback() 增加 isStopping 檢查。
  7. 調整 Xcode genic/ios 打包問題。

影響

  • 非破壞性修正,不改變 API。
  • 增加播放穩定性,避免 crash。
  • 減少 legacy code,維護性更高。

測試

  • Xcode 編譯和打包測試成功 (genic/ios)。
  • 安裝後應用啟動與基本使用正常。
  • 尚未進行多次 start/stop 或實際音訊播放壓力測試。

添加了isStopping标志来管理音频队列停止。更新了音频缓冲器的内存管理,并改进了回调处理。

此區段原始可能存在內存異常讀取
可能會導致應用崩潰問題
  "vmRegionInfo" : "0 is not in any region.  Bytes before following region: 4366663680\n      REGION TYPE                 START - END      [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      UNUSED SPACE AT START\n--->  \n      __TEXT                   104460000-1044cc000 [  432K] r-x\/r-x SM=COW  \/var\/containers\/Bundle\/Application\/3A882EEF-290C-419B-9D72-85B1D7EB9598\/OpenParsec.app\/OpenParsec",
  "exception" : {"codes":"0x0000000000000001, 0x0000000000000000","rawCodes":[1,0],"type":"EXC_BAD_ACCESS","signal":"SIGSEGV","subtype":"KERN_INVALID_ADDRESS at 0x0000000000000000"},
  "termination" : {"flags":0,"code":11,"namespace":"SIGNAL","indicator":"Segmentation fault: 11","byProc":"exc handler","byPid":41615},
  "vmregioninfo" : "0 is not in any region.  Bytes before following region: 4366663680\n      REGION TYPE                 START - END      [ VSIZE] PRT\/MAX SHRMOD  REG

⚠️待實際調試檢查
工作流測試
手動調試測試生產ipa吧
工作流測試 不使用真機打包
修正用存在的模擬器
Updated variable type for lastbuf and improved comments for clarity.
Modify audio_clear function to return early if queue is not initialized and adjust in_use calculation.
Changed 'release__nightly' input to be optional with a default value of true. Updated condition for 'release__nightly' job to include 'patch-1' branch.
Added FPS setting with selectable options for frame rates.
Added fpsPerFrame variable and loading logic from UserDefaults.
Replaced hardcoded FPS with dynamic setting and added updateFPS method.
Refactor metricInfo construction for better readability and include GLK FPS parameter.
TwhomeGH and others added 29 commits January 2, 2026 04:29
Updated the build timestamp format to include date and time in a more detailed manner.
Added methods to calculate actual and delta FPS.
Removed average FPS logging and updated delta FPS formatting.
Removed commented-out SwiftUI and GLKit code for ParsecGLKViewController.
@hugeBlack
Copy link
Owner

hugeBlack commented Jan 10, 2026

看你把Metal相关的注释去掉了,你是解决了Metal渲染吗?

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