All users were logged out of Bugzilla on October 13th, 2018

Assertion when creating a widget with null parent and null native data

RESOLVED FIXED

Status

()

RESOLVED FIXED
10 years ago
10 years ago

People

(Reporter: bzbarsky, Assigned: jaas)

Tracking

Trunk
x86
Mac OS X
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments, 1 obsolete attachment)

(Reporter)

Description

10 years ago
STEPS TO REPRODUCE:

Call nsIView::CreateWidget with a null parent widget and null native data.

ACTUAL RESULTS:  We end up in nsChildView::StandardCreate with a null aParent and a null aNativeParent.  Then we hit the following assertion:

  ###!!! ASSERTION: couldn't hook up new NSView in hierarchy: 'mParentView && mView', file /Users/bzbarsky/mozilla/svg-ext/mozilla/widget/src/cocoa/nsChildView.mm, line 513

because mParentView is null.

EXPECTED RESULTS: No assertion, or some way to do what I want to do that doesn't involve passing in all the nulls.

What I'm trying to do is to create an nsIWidget that's not hooked up to any existing nsIWidget, or to any existing native widgets.  It should just live in a little world of its own.

Need this for external reference documents.
(Assignee)

Comment 1

10 years ago
Created attachment 339816 [details] [diff] [review]
fix v1.0

This will probably work but I haven't tested it.
(Assignee)

Updated

10 years ago
Attachment #339816 - Flags: review?(smichaud)
(Assignee)

Comment 2

10 years ago
Created attachment 339824 [details] [diff] [review]
fix v1.1

oops, forgot to regenerate my patch after fixing this
Attachment #339816 - Attachment is obsolete: true
Attachment #339824 - Flags: review?(smichaud)
Attachment #339816 - Flags: review?(smichaud)
I strongly suspect this won't work, because (in Boris' example) we'd
be creating an NSView that doesn't belong to any NSWindow.

However, it might be possible to get this idea to work by also
changing the following code

  // Hook it up in the NSView hierarchy.
  if (mParentView) {
    NSWindow* window = [mParentView window];
    if (!window &&
        [mParentView respondsToSelector:@selector(nativeWindow)])
      window = [mParentView nativeWindow];

    [mView setNativeWindow:window];

    [mParentView addSubview:mView];
  }

to something like

  // Hook it up in the NSView hierarchy.
  if (mParentView) {
    NSWindow* window = [mParentView window];
    if (!window &&
        [mParentView respondsToSelector:@selector(nativeWindow)])
      window = [mParentView nativeWindow];

    [mView setNativeWindow:window];

    [mParentView addSubview:mView];
  } else {
    NSWindow *window = [NSApp keyWindow];
    if (!window)
      window = [NSApp mainWindow];
    if (!window)
      [Complain loudly and abort]

    [mView setNativeWindow:window];
    [[window contentView] addSubview:mView];
  }
Boris, could you create a testcase that shows what you're trying to do
(including, if possible, how you're using it to implement external
reference documents)?  This'll probably make it a lot easier for us to
figure out what you need.
(Reporter)

Comment 5

10 years ago
Created attachment 339833 [details] [diff] [review]
Patch to apply

Apply this patch (applies cleanly on top of rev dd9e757b2e96) and then recompile.  Then load <https://bugzilla.mozilla.org/attachment.cgi?id=335464>.  You will get the asserts described in this bug.

Note that as far as I can tell everything that I want to work actually works.  I just get these asserts.
Comment on attachment 339824 [details] [diff] [review]
fix v1.1

(In reply to comment #5)

> Note that as far as I can tell everything that I want to work
> actually works.  I just get these asserts.

That's puzzling.  I can't figure out why it would work ... but then
again I don't really know what you're trying to do.

(Following up comment #3)

Josh, I can't find any other problems with your patch than the one
I've already mentioned.  But it (as Boris seems to say) that's a
non-issue, then I'll r+ your patch.

However I suspect we may have problems with this down the line.

The core issue is that (as far as I know) you can't display the
contents of an NSView object without "attaching" it to an NSWindow
object (without making it a subview of (say) the NSWindow object's
contentView).

But maybe Boris isn't trying to display this particular NSView object
(the one corresponding to the "nsIWidget that's not hooked up to any
existing nsIWidget, or to any existing native widgets").
Attachment #339824 - Flags: review?(smichaud) → review+
(Assignee)

Updated

10 years ago
Attachment #339824 - Flags: superreview?(bzbarsky)
(Reporter)

Comment 7

10 years ago
Yeah, I don't need anything out of the widget here.  I just want to have the frame tree, which I paint into a totally different native surface.
(Reporter)

Updated

10 years ago
Attachment #339824 - Flags: superreview?(bzbarsky) → superreview+
(Assignee)

Comment 8

10 years ago
landed on trunk
Status: NEW → RESOLVED
Last Resolved: 10 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.