Crash on GetException() on CefRefPtr<CefV8Value>

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Crash on GetException() on CefRefPtr<CefV8Value>

Postby Fallen » Tue Sep 30, 2014 7:14 am

Using the newest Dev release CEF 3.2168.1846. In this method in my code I have a crash on the line:
result->GetException()


If I comment it out, the app runs normally.

Code: Select all
void GCefV8Handler::sendToBrowserImpl(const std::string& message, const std::string & extraContent)
{   
   GalaxyAssert(CefCurrentlyOn(TID_RENDERER), "Not on renderer thread.");
   if (m_callbackContext == NULL)
      return;
   m_callbackContext->Enter();

   CefV8ValueList args;
   args.push_back(CefV8Value::CreateString(message));
   args.push_back(CefV8Value::CreateString(extraContent));

   CefRefPtr<CefV8Value> result = m_callbackFunc->ExecuteFunctionWithContext(m_callbackContext, m_object, args);
   
   CefRefPtr<CefV8Exception> exception = result->GetException();
   if (result == NULL)
   {
      if (m_callbackFunc->GetException() != NULL)
      {
         CefRefPtr<CefV8Exception> exception = m_callbackFunc->GetException();
         std::string error = exception->GetMessage();
         GalaxyClient::Logger::LogWarning("Send to browser failed with exception %s at line %d; message: %s", error.c_str(), exception->GetLineNumber(), message.c_str());
      }
      else
         GalaxyClient::Logger::LogWarning("Send to browser failed with NULL exception; message: %s", message.c_str());
   }
   else if (result->GetException() != NULL)
   {
      CefRefPtr<CefV8Exception> exception = result->GetException();
      std::string error = exception->GetMessage();
      GalaxyClient::Logger::LogWarning("Send to browser failed with exception %s at line %d; message: %s", error.c_str(), exception->GetLineNumber(), message.c_str());
   }
   m_callbackContext->Exit();
}


[0930/141109:FATAL:v8_impl.cc(1583)] Check failed: false. V8 handle is not valid
0 Chromium Embedded Framework 0x00000001021681cf base::debug::StackTrace::StackTrace() + 47
1 Chromium Embedded Framework 0x0000000102168223 base::debug::StackTrace::StackTrace() + 35
2 Chromium Embedded Framework 0x00000001021ea0e6 logging::LogMessage::~LogMessage() + 70
3 Chromium Embedded Framework 0x00000001021e9113 logging::LogMessage::~LogMessage() + 35
4 Chromium Embedded Framework 0x00000001020bbfe0 CefV8ValueImpl::GetException() + 592
5 Chromium Embedded Framework 0x0000000101edff5b v8value_get_exception(_cef_v8value_t*) + 283
6 GalaxyClient 0x0000000100d7d279 CefV8ValueCToCpp::GetException() + 153
7 GalaxyClient 0x0000000100103563 GalaxyClient::GCefV8Handler::sendToBrowserImpl(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 1731
Fallen
Techie
 
Posts: 39
Joined: Wed Jan 29, 2014 11:38 am

Re: Crash on GetException() on CefRefPtr<CefV8Value>

Postby Czarek » Tue Sep 30, 2014 7:41 am

I think you should call HasException() to ensure that there is an exception to get. Documentation for GetException() doesn't state that it can return NULL, so I wouldn't assume that. If there is a function like HasXxxx() you should always use it before calling GetXxxx(). I would also recommend to always call IsValid() and handle appropriate cases before operating on a V8 object - for eg. I recall having issues in OnContextCreated with CefV8Context handle passed sometimes being invalid (a timing issue I think). V8 code is tricky, so be careful with it.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Crash on GetException() on CefRefPtr<CefV8Value>

Postby Fallen » Tue Sep 30, 2014 7:47 am

Czarek wrote:I think you should call HasException() to ensure that there is an exception to get. Documentation for GetException() doesn't state that it can return NULL, so I wouldn't assume that. If there is a function like HasXxxx() you should always use it before calling GetXxxx(). I would also recommend to always call IsValid() and handle appropriate cases before operating on a V8 object - for eg. I recall having issues in OnContextCreated with CefV8Context handle passed sometimes being invalid (a timing issue I think). V8 code is tricky, so be careful with it.


Does the same thing, here's the stack:

Code: Select all
[0930/144653:FATAL:v8_impl.cc(1577)] Check failed: false. V8 handle is not valid
0   Chromium Embedded Framework         0x00000001021681cf base::debug::StackTrace::StackTrace() + 47
1   Chromium Embedded Framework         0x0000000102168223 base::debug::StackTrace::StackTrace() + 35
2   Chromium Embedded Framework         0x00000001021ea0e6 logging::LogMessage::~LogMessage() + 70
3   Chromium Embedded Framework         0x00000001021e9113 logging::LogMessage::~LogMessage() + 35
4   Chromium Embedded Framework         0x00000001020bbc8d CefV8ValueImpl::HasException() + 557
5   Chromium Embedded Framework         0x0000000101edfdd5 v8value_has_exception(_cef_v8value_t*) + 261
6   GalaxyClient                        0x0000000100d7d1de CefV8ValueCToCpp::HasException() + 126
Fallen
Techie
 
Posts: 39
Joined: Wed Jan 29, 2014 11:38 am

Re: Crash on GetException() on CefRefPtr<CefV8Value>

Postby Czarek » Tue Sep 30, 2014 7:56 am

Have you checked "result" returned from ExecuteFunctionWithContext() before operating on it? It may be NULL - see docs comments in .h file.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Crash on GetException() on CefRefPtr<CefV8Value>

Postby Fallen » Tue Sep 30, 2014 7:57 am

Czarek wrote:Have you checked "result" returned from ExecuteFunctionWithContext() before operating on it? It may be NULL - see docs comments in .h file.



The code looks like this:

Code: Select all
if (result == NULL)
{

}
else (result->HasEception())
{

}


It crashes on else, besides the message to the browser gets sent. I'll debug more to see if there's more to it.
Fallen
Techie
 
Posts: 39
Joined: Wed Jan 29, 2014 11:38 am

Re: Crash on GetException() on CefRefPtr<CefV8Value>

Postby Czarek » Tue Sep 30, 2014 8:05 am

Check for result->IsValid() as well.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Crash on GetException() on CefRefPtr<CefV8Value>

Postby tomst » Wed Oct 08, 2014 5:09 pm

I have a similar problem in CEF 3.2062.1856. handler->GetValue("...") (and also handler->GetException()) give me back that "V8 handle is not valid" even though I specifically check for handler->IsValid(), which is true. Looks like a CEF bug?

Code: Select all
[1008/145837:FATAL:v8_impl.cc(1665)] Check failed: false. V8 handle is not valid
0   Chromium Embedded Framework         0x000000010089218f base::debug::StackTrace::StackTrace() + 47
1   Chromium Embedded Framework         0x00000001008921e3 base::debug::StackTrace::StackTrace() + 35
2   Chromium Embedded Framework         0x000000010090ca46 logging::LogMessage::~LogMessage() + 70
3   Chromium Embedded Framework         0x000000010090ba63 logging::LogMessage::~LogMessage() + 35
4   Chromium Embedded Framework         0x00000001007dcf83 CefV8ValueImpl::GetValue(CefStringBase<CefStringTraitsUTF16> const&) + 611
5   Chromium Embedded Framework         0x00000001005fdb87 v8value_get_value_bykey(_cef_v8value_t*, _cef_string_utf16_t const*) + 343
6   Helper                              0x00000001000baf4c CefV8ValueCToCpp::GetValue(CefStringBase<CefStringTraitsUTF16> const&) + 188


Thomas
tomst
Techie
 
Posts: 43
Joined: Fri Aug 22, 2014 4:38 pm

Re: Crash on GetException() on CefRefPtr<CefV8Value>

Postby magreenblatt » Thu Oct 09, 2014 12:08 pm

What does your code
tomst wrote:I have a similar problem in CEF 3.2062.1856.

What does your code look like and where are you executing it from?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Crash on GetException() on CefRefPtr<CefV8Value>

Postby tomst » Thu Oct 09, 2014 7:11 pm

Here's the function and the full traceback:

Code: Select all
void ClientV8Handler::callback(CefRefPtr<CefBrowser> browser, CefRefPtr<CefListValue> msgArgs)
{
    CefRefPtr<CefV8Context> context = browser->GetMainFrame()->GetV8Context();
    CefRefPtr<CefV8Value> handler, handlerFunc;

    qDebug() << "CONTEXT VALID?" << context->IsValid(); // true
    qDebug() << "CONTEXT ENTER?" << context->Enter(); // true
    qDebug() << "CONTEXT VALID2?" << context->IsValid(); // true
    qDebug() << "CONTEXT GLOBAL VALID?" << context->GetGlobal()->IsValid(); // true
    handler = context->GetGlobal()->GetValue("PhoneHandler");
    qDebug() << "PHONE HANDLER VALID?" << handler->IsValid(); // true
    handlerFunc = handler->GetValue("onAccountState"); // FATAL
    context->Exit();
}


Output:

Code: Select all
CONTEXT VALID? true
CONTEXT ENTER? true
CONTEXT VALID2? true
CONTEXT GLOBAL VALID? true
PHONE HANDLER VALID? true
[1009/170722:FATAL:v8_impl.cc(1665)] Check failed: false. V8 handle is not valid
0   Chromium Embedded Framework         0x00000001008e39ff base::debug::StackTrace::StackTrace() + 47
1   Chromium Embedded Framework         0x00000001008e3a53 base::debug::StackTrace::StackTrace() + 35
2   Chromium Embedded Framework         0x0000000100965286 logging::LogMessage::~LogMessage() + 70
3   Chromium Embedded Framework         0x00000001009642b3 logging::LogMessage::~LogMessage() + 35
4   Chromium Embedded Framework         0x00000001007d7647 CefV8ValueImpl::GetValue(CefStringBase<CefStringTraitsUTF16> const&) + 599
5   Chromium Embedded Framework         0x00000001005ed18d v8value_get_value_bykey(_cef_v8value_t*, _cef_string_utf16_t const*) + 333
6   Helper                              0x00000001000b656c CefV8ValueCToCpp::GetValue(CefStringBase<CefStringTraitsUTF16> const&) + 188
7   Helper                              0x000000010001ab26 ClientV8Handler::callback(CefRefPtr<CefBrowser>, CefRefPtr<CefListValue>) + 1222
8   Helper                              0x0000000100014039 BrowserApp::OnProcessMessageReceived(CefRefPtr<CefBrowser>, cef_process_id_t, CefRefPtr<CefProcessMessage>) + 761
9   Helper                              0x00000001000145a2 non-virtual thunk to BrowserApp::OnProcessMessageReceived(CefRefPtr<CefBrowser>, cef_process_id_t, CefRefPtr<CefProcessMessage>) + 34
10  Helper                              0x000000010008d6b4 render_process_handler_on_process_message_received(_cef_render_process_handler_t*, _cef_browser_t*, cef_process_id_t, _cef_process_message_t*) + 756
11  Chromium Embedded Framework         0x00000001005c29ae CefRenderProcessHandlerCToCpp::OnProcessMessageReceived(CefRefPtr<CefBrowser>, cef_process_id_t, CefRefPtr<CefProcessMessage>) + 702
12  Chromium Embedded Framework         0x00000001007a026e CefBrowserImpl::OnRequest(Cef_Request_Params const&) + 750
13  Chromium Embedded Framework         0x00000001007a3f35 void DispatchToMethod<CefBrowserImpl, void (CefBrowserImpl::*)(Cef_Request_Params const&), Cef_Request_Params>(CefBrowserImpl*, void (CefBrowserImpl::*)(Cef_Request_Params const&), Tuple1<Cef_Request_Params> const&) + 165
14  Chromium Embedded Framework         0x00000001007a2f03 bool CefMsg_Request::Dispatch<CefBrowserImpl, CefBrowserImpl, void, void (CefBrowserImpl::*)(Cef_Request_Params const&)>(IPC::Message const*, CefBrowserImpl*, CefBrowserImpl*, void*, void (CefBrowserImpl::*)(Cef_Request_Params const&)) + 163
15  Chromium Embedded Framework         0x000000010079fcd1 CefBrowserImpl::OnMessageReceived(IPC::Message const&) + 385
16  Chromium Embedded Framework         0x00000001007a11a4 non-virtual thunk to CefBrowserImpl::OnMessageReceived(IPC::Message const&) + 52
17  Chromium Embedded Framework         0x0000000107cc0184 content::RenderViewImpl::OnMessageReceived(IPC::Message const&) + 436
18  Chromium Embedded Framework         0x0000000105cdc14e content::MessageRouter::RouteMessage(IPC::Message const&) + 110
19  Chromium Embedded Framework         0x0000000105cdc0ac content::MessageRouter::OnMessageReceived(IPC::Message const&) + 108
20  Chromium Embedded Framework         0x000000010805661f content::ChildThread::OnMessageReceived(IPC::Message const&) + 1999
21  Chromium Embedded Framework         0x000000010537e4f4 IPC::ChannelProxy::Context::OnDispatchMessage(IPC::Message const&) + 468
22  Chromium Embedded Framework         0x0000000105386926 base::internal::RunnableAdapter<void (IPC::ChannelProxy::Context::*)(IPC::Message const&)>::Run(IPC::ChannelProxy::Context*, IPC::Message const&) + 150
23  Chromium Embedded Framework         0x000000010538682f base::internal::InvokeHelper<false, void, base::internal::RunnableAdapter<void (IPC::ChannelProxy::Context::*)(IPC::Message const&)>, void (IPC::ChannelProxy::Context* const&, IPC::Message const&)>::MakeItSo(base::internal::RunnableAdapter<void (IPC::ChannelProxy::Context::*)(IPC::Message const&)>, IPC::ChannelProxy::Context* const&, IPC::Message const&) + 79
24  Chromium Embedded Framework         0x000000010538677c base::internal::Invoker<2, base::internal::BindState<base::internal::RunnableAdapter<void (IPC::ChannelProxy::Context::*)(IPC::Message const&)>, void (IPC::ChannelProxy::Context*, IPC::Message const&), void (IPC::ChannelProxy::Context*, IPC::Message)>, void (IPC::ChannelProxy::Context*, IPC::Message const&)>::Run(base::internal::BindStateBase*) + 140
25  Chromium Embedded Framework         0x0000000106de05ef base::Callback<void ()>::Run() const + 63
26  Chromium Embedded Framework         0x00000001008e5998 base::debug::TaskAnnotator::RunTask(char const*, char const*, base::PendingTask const&) + 968
27  Chromium Embedded Framework         0x000000010099d085 base::MessageLoop::RunTask(base::PendingTask const&) + 597
28  Chromium Embedded Framework         0x000000010099d219 base::MessageLoop::DeferOrRunPendingTask(base::PendingTask const&) + 89
29  Chromium Embedded Framework         0x000000010099d4e3 base::MessageLoop::DoWork() + 323
30  Chromium Embedded Framework         0x00000001008b22db base::MessagePumpCFRunLoopBase::RunWork() + 107
31  Chromium Embedded Framework         0x00000001008b177b base::MessagePumpCFRunLoopBase::RunWorkSource(void*) + 43
32  CoreFoundation                      0x00007fff903ca5b1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
33  CoreFoundation                      0x00007fff903bbc62 __CFRunLoopDoSources0 + 242
34  CoreFoundation                      0x00007fff903bb3ef __CFRunLoopRun + 831
35  CoreFoundation                      0x00007fff903bae75 CFRunLoopRunSpecific + 309
36  Foundation                          0x00007fff8c21416c -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 253
37  Chromium Embedded Framework         0x00000001008b2ec7 base::MessagePumpNSRunLoop::DoRun(base::MessagePump::Delegate*) + 151
38  Chromium Embedded Framework         0x00000001008b1f20 base::MessagePumpCFRunLoopBase::Run(base::MessagePump::Delegate*) + 128
39  Chromium Embedded Framework         0x000000010099cb89 base::MessageLoop::RunHandler() + 249
40  Chromium Embedded Framework         0x00000001009fb1ac base::RunLoop::Run() + 76
41  Chromium Embedded Framework         0x000000010099c0ff base::MessageLoop::Run() + 47
42  Chromium Embedded Framework         0x0000000107d192e3 content::RendererMain(content::MainFunctionParams const&) + 1507
43  Chromium Embedded Framework         0x00000001089fbb00 content::RunNamedProcessTypeMain(std::string const&, content::MainFunctionParams const&, content::ContentMainDelegate*) + 256
44  Chromium Embedded Framework         0x00000001089fcd4f content::ContentMainRunnerImpl::Run() + 543
45  Chromium Embedded Framework         0x00000001089fb593 content::ContentMain(content::ContentMainParams const&) + 147
46  Chromium Embedded Framework         0x000000010066b248 CefExecuteProcess(CefMainArgs const&, CefRefPtr<CefApp>, void*) + 424
47  Chromium Embedded Framework         0x0000000100539887 cef_execute_process + 327
48  Helper                              0x0000000100021e80 CefExecuteProcess(CefMainArgs const&, CefRefPtr<CefApp>, void*) + 336
49  Helper                              0x000000010000e042 main + 162
50  libdyld.dylib                       0x00007fff8e1945fd start + 1
51  ???                                 0x000000000000000d 0x0 + 13
tomst
Techie
 
Posts: 43
Joined: Fri Aug 22, 2014 4:38 pm

Re: Crash on GetException() on CefRefPtr<CefV8Value>

Postby Czarek » Fri Oct 10, 2014 12:28 am

@tomst Call HasValue() before GetValue().
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Next

Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 40 guests