NullReferenceException in ExecuteScript #24

Closed
oconnor663 opened this Issue May 11, 2012 · 6 comments

Projects

None yet

2 participants

@oconnor663
>   CefSharp.dll!CefSharp::ScriptCore::UIT_Execute(CefRefPtr<CefBrowser>* browser, CefStringBase<CefStringTraitsUTF16>* script) Line 10 C++
    [External Code] 
    CefSharp.dll!DispatchToMethod<CefSharp::ScriptCore,void (__thiscall CefSharp::ScriptCore::*)(CefRefPtr<CefBrowser>,CefStringBase<CefStringTraitsUTF16>),CefRefPtr<CefBrowser>,CefStringBase<CefStringTraitsUTF16> >(CefSharp::ScriptCore* obj, void* method, Tuple2<CefRefPtr<CefBrowser>,CefStringBase<CefStringTraitsUTF16> >& arg) Line 592  C++
    CefSharp.dll!CefRunnableMethod<CefSharp::ScriptCore,void (__thiscall CefSharp::ScriptCore::*)(CefRefPtr<CefBrowser>,CefStringBase<CefStringTraitsUTF16>),Tuple2<CefRefPtr<CefBrowser>,CefStringBase<CefStringTraitsUTF16> > >::Execute(cef_thread_id_t threadId) Line 151   C++
    [External Code] 

This occurs when an ExecuteScript call is made right before the app exits, so presumably the WinForms browser is getting disposed out from under us. Is there a good way to protect ourselves from this error? Alternatively, should we do something like check for null here in UIT_Execute?

Exception

@ataranto
Owner

Yeah, good find. We should probably block JS execution once Dispose begins.

On , Jack O'Connor
reply@reply.github.com
wrote:


> CefSharp.dll!CefSharp::ScriptCore::UIT_Execute(CefRefPtr* browser,  
CefStringBase* script) Line 10 C++

[External Code]

CefSharp.dll!DispatchToMethod,CefStringBase),CefRefPtr,CefStringBase  
>(CefSharp::ScriptCore* obj, void* method, Tuple2,CefStringBase >& arg)  
Line 592 C++

CefSharp.dll!CefRunnableMethod,CefStringBase),Tuple2,CefStringBase >  
>::Execute(cef_thread_id_t threadId) Line 151 C++

[External Code]

This occurs when an ExecuteScript call is made right before the app
exits, so presumably the WinForms browser is getting disposed out from
under us. Is there a good way to protect ourselves from this error?
Alternatively, should we do something like check for null here in
UIT_Execute?

Exception


Reply to this email directly or view it on GitHub:

#24

@ataranto
Owner

On second though, we probably need something more similar to the TryGetCefBrowser() pattern used within the WebView classes:

https://github.com/ataranto/CefSharp/blob/master/CefSharp.Wpf/WebView.cpp#L42

@oconnor663

Working from your suggestion, this looks like it solves the problem. How does it look to you?

oconnor663/CefSharp@e595b4f

@ataranto
Owner

Yeah, looks great. I may try to make a general TryGet* internal api. Also, I might make Evaluate throw an exception, which right now is how consumers are notified that "your script didn't run successfully" .

@oconnor663

Do you want to merge the diff as it is now, or make changes first?

@ataranto
Owner

I will probably merge it as is for now. I want to make some time this weekend to merge in a bunch of contributions and make a release, there are lots of great changes/fixes that are only on other people's branches right now, so i want to get them merged before there's more fragmentation.

@ataranto ataranto closed this May 17, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment