ataranto / CefSharp

.Net binding for the Chromium Embedded Framework
Other
62 stars 34 forks source link

NullReferenceException in ExecuteScript #24

Closed oconnor663 closed 12 years ago

oconnor663 commented 12 years ago
>   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 commented 12 years ago

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:

https://github.com/ataranto/CefSharp/issues/24

ataranto commented 12 years ago

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 commented 12 years ago

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

https://github.com/oconnor663/CefSharp/commit/e595b4ff1dccc73d90ad24cdf96b291fb7e13d9c

ataranto commented 12 years ago

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 commented 12 years ago

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

ataranto commented 12 years ago

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.