fix crash, current rgba ffi design still ugly and dangerous

This commit is contained in:
open-trade 2020-11-18 18:12:43 +08:00
parent 33186e28d1
commit c469329d19
2 changed files with 17 additions and 11 deletions

View File

@ -80,13 +80,12 @@ class FFI {
setByName('connect', id);
}
static void _clearRgbaFrame() {
static void clearRgbaFrame() {
if (_lastRgbaFrame != null && _lastRgbaFrame != nullptr)
_freeRgba(_lastRgbaFrame);
}
static Uint8List getRgba() {
_clearRgbaFrame();
_lastRgbaFrame = _getRgba();
if (_lastRgbaFrame == null || _lastRgbaFrame == nullptr) return null;
final ref = _lastRgbaFrame.ref;
@ -115,7 +114,6 @@ class FFI {
}
static void close() {
_clearRgbaFrame();
setByName('close', '');
}

View File

@ -21,6 +21,7 @@ class _RemotePageState extends State<RemotePage> {
ui.Image _image;
PeerInfo _pi = PeerInfo();
Display _display = Display();
bool _decoding = false;
@override
void initState() {
@ -39,6 +40,7 @@ class _RemotePageState extends State<RemotePage> {
FFI.close();
_interval.cancel();
dismissLoading();
_decoding = null;
}
void interval() {
@ -53,15 +55,21 @@ class _RemotePageState extends State<RemotePage> {
handleSwitchDisplay(evt);
}
}
var rgba = FFI.getRgba();
if (rgba != null) {
ui.decodeImageFromPixels(
rgba, _display.width, _display.height, ui.PixelFormat.bgra8888,
(__image) {
setState(() {
_image = __image;
if (!_decoding) {
var rgba = FFI.getRgba();
if (rgba != null) {
_decoding = true;
ui.decodeImageFromPixels(
rgba, _display.width, _display.height, ui.PixelFormat.bgra8888,
(__image) {
FFI.clearRgbaFrame();
if (_decoding == null) return;
_decoding = false;
setState(() {
_image = __image;
});
});
});
}
}
}