赤いボックスを描画するシンプルな hello world のようなプラグインを作成しました。
xulrunner アプリケーションに埋め込んだ後、プラグインはほぼ問題なく動作します。Xulrunner アプリケーションは、アプリケーション ウィンドウのサイズ変更時にボックスを正常に再描画します。
しかし、左クリックなどのマウスイベントの後、アプリケーションが「スタックオーバーフロー」でクラッシュします。デバッガーは、その理由は forwardMethod の 2 回の呼び出しとそれに続く JSD_GetValueForObject の 1 回の呼び出しの無限サイクルであると述べています
クラッシュ スタックの内容の次は次のとおりです。
-[NSApplication _indexOfWindow:]
-[NSEvent window]
JSD_GetValueForObject
JSD_GetValueForObject
JSD_GetValueForObject
forwardMethod
forwardMethod
JSD_GetValueForObject
forwardMethod
forwardMethod
JSD_GetValueForObject
forwardMethod
forwardMethod
JSD_GetValueForObject
forwardMethod
forwardMethod
JSD_GetValueForObject
forwardMethod
forwardMethod
JSD_GetValueForObject
forwardMethod
forwardMethod
- .....等
私のコードは次のとおりです。
int16_t NPP_HandleEvent(NPP instance, void* event)
{
EventRecord* carbonEvent = (EventRecord*)event;
if (carbonEvent && (carbonEvent->what == updateEvt))
{
PluginInstance* currentInstance = (PluginInstance*)(instance->pdata);
CGContextRef cgContext = ((NP_CGContext*)(currentInstance->window.window))->context;
float windowWidth = currentInstance->window.width;
float windowHeight = currentInstance->window.height;
static int x = 0;
if (x++)
return;
NPRect clipRect = currentInstance->window.clipRect;
NP_CGContext* npContext = currentInstance->window.window;
NSWindow* browserWindow = [[[NSWindow alloc] initWithWindowRef:npContext->window] autorelease];
int y = [browserWindow frame].size.height - (clipRect.bottom - clipRect.top) - currentInstance->window.y;
//[plugin attachToWindow:browserWindow at:NSMakePoint(window->x, y)];
NSPoint point = NSMakePoint(currentInstance->window.x, y);
// find the NSView at the point
NSView* hitView = [[browserWindow contentView] hitTest:NSMakePoint(point.x+1, point.y+1)];
if (hitView == nil || ![[hitView className] isEqualToString:@"ChildView"])
{
x = 0;
return;
}
NSView* parentView = hitView;
NSBox *box = [[NSBox alloc] initWithFrame:NSMakeRect(0.0, 0.0, 100, 100)];
[box setBoxType:NSBoxCustom];
[box setBorderType:NSLineBorder];
[box setTitlePosition:NSNoTitle];
[box setFillColor:[NSColor redColor]];
[parentView addSubview:box];
//DrawPlugin(cgContext, windowWidth, windowHeight);
}
return 0;
}