Skip to content

Commit

Permalink
fix: fix event not responding when multiple flutter engine created.
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Aug 9, 2023
1 parent f752311 commit a673dd1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions bridge/core/executing_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ ExecutingContext::ExecutingContext(DartIsolateContext* dart_isolate_context,
// #endif

// @FIXME: maybe contextId will larger than MAX_JS_CONTEXT
assert_m(valid_contexts[contextId] != true, "Conflict context found!");
valid_contexts[contextId] = true;
if (contextId > running_context_list)
running_context_list = contextId;
Expand Down
4 changes: 4 additions & 0 deletions bridge/include/webf_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ WEBF_EXPORT_C
void* initDartIsolateContext(uint64_t* dart_methods, int32_t dart_methods_len);
WEBF_EXPORT_C
void* allocateNewPage(void* dart_isolate_context, int32_t targetContextId);

WEBF_EXPORT_C
int64_t newPageId();

WEBF_EXPORT_C
void disposePage(void* dart_isolate_context, void* page);
WEBF_EXPORT_C
Expand Down
6 changes: 6 additions & 0 deletions bridge/webf_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#define SYSTEM_NAME "unknown"
#endif

static std::atomic<int64_t> unique_page_id{0};

void* initDartIsolateContext(uint64_t* dart_methods, int32_t dart_methods_len) {
void* ptr = new webf::DartIsolateContext(dart_methods, dart_methods_len);
return ptr;
Expand All @@ -51,6 +53,10 @@ void* allocateNewPage(void* dart_isolate_context, int32_t targetContextId) {
return ptr;
}

int64_t newPageId() {
return unique_page_id++;
}

void disposePage(void* dart_isolate_context, void* page_) {
auto* page = reinterpret_cast<webf::WebFPage*>(page_);
assert(std::this_thread::get_id() == page->currentThread());
Expand Down
8 changes: 1 addition & 7 deletions webf/lib/src/bridge/bridge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import 'binding.dart';
import 'from_native.dart';
import 'to_native.dart';

int _contextId = 0;

int newContextId() {
return ++_contextId;
}

class DartContext {
DartContext() : pointer = initDartIsolateContext(makeDartMethodsData()) {
initDartDynamicLinking();
Expand All @@ -31,7 +25,7 @@ int initBridge(WebFViewController view) {
// Setup binding bridge.
BindingBridge.setup();

int pageId = newContextId();
int pageId = newPageId();
allocateNewPage(pageId);

return pageId;
Expand Down
9 changes: 9 additions & 0 deletions webf/lib/src/bridge/to_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ void disposePage(int contextId) {
_allocatedPages.remove(contextId);
}

typedef NativeNewPageId = Int64 Function();
typedef DartNewPageId = int Function();

final DartNewPageId _newPageId = WebFDynamicLibrary.ref.lookup<NativeFunction<NativeNewPageId>>('newPageId').asFunction();

int newPageId() {
return _newPageId();
}

typedef NativeAllocateNewPage = Pointer<Void> Function(Pointer<Void>, Int32);
typedef DartAllocateNewPage = Pointer<Void> Function(Pointer<Void>, int);

Expand Down

0 comments on commit a673dd1

Please sign in to comment.