Skip to content

Add thread safety and lifecycle for native pointers#70

Merged
peerless2012 merged 2 commits into
peerless2012:masterfrom
edde746:fix/thread-safety
Jun 4, 2026
Merged

Add thread safety and lifecycle for native pointers#70
peerless2012 merged 2 commits into
peerless2012:masterfrom
edde746:fix/thread-safety

Conversation

@edde746
Copy link
Copy Markdown
Contributor

@edde746 edde746 commented Mar 20, 2026

Summary

  • Add null guards to all JNI functions that dereference native pointers (prevents crash when pointer is 0)
  • Add explicit release() methods to Ass, AssTrack, and AssRender (replaces GC-only finalize() cleanup)
  • Add ReentrantLock in AssRender to synchronize renderFrame, setTrack, and release
  • Synchronize AssHandler.readTrackDialogue() with the render lock to prevent concurrent ass_process_chunk / ass_render_frame on the same track
  • Add AssHandler.release() for explicit native resource cleanup

Context

Google Play Console reports native crashes in libass.so (ass_parse_tags, ass_render_frame) caused by concurrent thread access to ASS_Track* and null/freed native pointers.

@moi15moi
Copy link
Copy Markdown
Contributor

I believe to be properly thread safe, any call to libass should use the same mutex.

@peerless2012
Copy link
Copy Markdown
Owner

I think the lock in java/kotlin is easy to use and debug, I will merge this pr.

@peerless2012 peerless2012 merged commit 9c69339 into peerless2012:master Jun 4, 2026
2 checks passed
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.

3 participants