Skip to content

Commit

Permalink
Fix segfault when navigating in CEF.
Browse files Browse the repository at this point in the history
  • Loading branch information
bamidev committed Mar 6, 2024
1 parent fccdefb commit 11f169f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion c/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "browser-window-c"
version = "0.2.1"
version = "0.2.2"
description = "Browser framework functionality for BrowserWindow written in C/C++."
edition = "2018"
authors = ["Bamidev"]
Expand Down
6 changes: 3 additions & 3 deletions c/src/cef/bw_handle_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ namespace bw {

// Fetches a bw_BrowserWindow handle from a cef handle.
// Returns an optional bw_BrowserWindow pointer.
std::optional<BrowserInfo> fetch( CefRefPtr<CefBrowser> cef_handle ) {
std::optional<BrowserInfo*> fetch( CefRefPtr<CefBrowser> cef_handle ) {
this->mutex.lock();
auto it = this->map.find( cef_handle->GetIdentifier() );

// If not found return nothing
if ( it == this->map.end() )
return std::optional<BrowserInfo>();
return std::optional<BrowserInfo*>();

// If found:
std::optional<BrowserInfo> result( (*it).second );
std::optional<BrowserInfo*> result(&(*it).second);
this->mutex.unlock();

return result;
Expand Down
16 changes: 8 additions & 8 deletions c/src/cef/client_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class ClientHandler : public CefClient, public CefLifeSpanHandler, public CefLoa
}

void invokeCreationCallback(CefRefPtr<CefBrowser> browser) {
std::optional<bw::BrowserInfo> bw_info_opt = bw::bw_handle_map.fetch(browser);
std::optional<bw::BrowserInfo*> bw_info_opt = bw::bw_handle_map.fetch(browser);
if (bw_info_opt.has_value()) {
auto bw_info = bw_info_opt.value();
auto callback_opt = bw_info.callback;
if (callback_opt.has_value()) {
auto value = callback_opt.value();
callback_opt.reset();
value.callback(bw_info.handle, value.data);
auto callback_opt = &bw_info->callback;
if (callback_opt->has_value()) {printf("invokeCreationCallback callback_opt.has-value %i\n", browser->GetIdentifier());
auto value = callback_opt->value();
callback_opt->reset();
value.callback(bw_info->handle, value.data);printf("invokeCreationCallback callback_opt.has-value2 %i\n", callback_opt->has_value());
}
}
}
Expand Down Expand Up @@ -178,9 +178,9 @@ class ClientHandler : public CefClient, public CefLifeSpanHandler, public CefLoa
(void)(source_process);

// Obtain our browser window handle
std::optional<bw::BrowserInfo> bw_info = bw::bw_handle_map.fetch(browser);
std::optional<bw::BrowserInfo*> bw_info = bw::bw_handle_map.fetch(browser);
BW_ASSERT( bw_info.has_value(), "Link between CEF's browser handle and our handle does not exist!\n" );
bw_BrowserWindow* our_handle = bw_info.value().handle;
bw_BrowserWindow* our_handle = bw_info.value()->handle;

auto msg_args = msg->GetArgumentList();

Expand Down

0 comments on commit 11f169f

Please sign in to comment.