Closed Bug 455698 Opened 16 years ago Closed 16 years ago

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

Categories

(Core :: Widget: Cocoa, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: bzbarsky, Assigned: jaas)

References

Details

Attachments

(2 files, 1 obsolete file)

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.
Attached patch fix v1.0 (obsolete) — Splinter Review
This will probably work but I haven't tested it.
Attachment #339816 - Flags: review?(smichaud)
Attached patch fix v1.1Splinter Review
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.
Attached patch Patch to applySplinter Review
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+
Attachment #339824 - Flags: superreview?(bzbarsky)
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.
Attachment #339824 - Flags: superreview?(bzbarsky) → superreview+
landed on trunk
Status: NEW → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: