KlarkKentThe3rd wrote: ↑2020-03-16, 20:10
I hope this mess will help you understand, since I sure don't.
Javascript isn't really my area of expertise, but I'll take a look at it a bit later...
Right now I am kind of focused on the problem that I can reproduce, and I wanted to give a slight update on that progress.
So the problem seems to be stemming from during drawRect: in nsChildView.mm.
CGContextRef cgContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
This returns a nil (0x0) CoreGraphics context sometimes. I am not sure why this is happening. But different buttons seem to take different code paths to draw. When this happens the currentContext is also nil.
Often times the trigger for the drawRect() is nsCocoaWindow::Show() in nsCocoaWindow.mm.
So there is a way to create a graphics context from the window, so in there I check if the context is nil and if so I create a new context using the popup window, and set the current context to the newly created context. This fixes about half of the buttons, however the other half do not seem to follow the same path and I don't see any browser code in the path, if I can find a place to check for a nil context and create a new one for those other buttons I can make a workaround to this problem.
However, this fix is kind of a hacky solution, I really need to figure out why the context is nil during drawRect: to begin with, and so far I still have not determined a cause.
When I test on 10.11 currentContext and graphicsPort always return valid values and do not ever return nil, which is what I expect to be happening. Not sure why on 10.14 and 10.15 they occasionally return nil. And once it returns nil, it seems to keep returning nil.