Closed michael closed 11 years ago
A classical seggie... (~ null pointer exception) I will have a look...
Resolved.
On web page reloads the browser destroys the javascript context. It could happen, that during the reload there was still (native) code running which accessed the (old) context. An access on an already deleted javascript context leaded to a segmentation fault.
The Substance app increases the refcount of the javascript context when initialising Javascript extensions. This has the effect that when the context is released by the browser there remains a reference owned by Substance. The context is not deleted at the moment of reload, instead at the time when Substance releases its reference.
On a webpage reload Substance triggers a delayed reference release after a certain time (e.g. 2s). This time interval must be large enough so that all ongoing native functions can finish safely.
The solution's code:
@implementation WebViewWithExtensions
...
- (void) updateJSEngine
{
if (m_context != nil) {
[self performSelector:@selector(disposeContext:) withObject: m_context afterDelay:2.0];
}
JSGlobalContextRef context = [[m_webView mainFrame] globalContext];
m_context = [[ContextContainer new] initWithJSGlobalContext: context];
...
}
- (void) disposeContext: (id) context {
[context release];
}
...
@end
@implementation ContextContainer
- (id) initWithJSGlobalContext : (JSGlobalContextRef) context {
m_context = JSGlobalContextRetain(context);
return self;
}
- (void) dealloc {
JSGlobalContextRelease(m_context);
[super dealloc];
}
@end