Is -[CPAlert runModalWithDidEndBlock:] Borked?

113 views
Skip to first unread message

Keary Suska

unread,
Mar 9, 2016, 8:01:12 PM3/9/16
to objec...@googlegroups.com
I get this:

[Error] TypeError: null is not an object (evaluating '((___r1 = self._platformWindow), ___r1 == null ? null : ___r1.isa.objj_msgSend0(___r1, "contentBounds")).size')
- [CPWindow center]
objj_msgSendFast0
- [CPAlert layout]
objj_msgSendFast0
- [CPAlert runModal]
objj_msgSendFast0
- [CPAlert runModalWithDidEndBlock:]
objj_msgSendFast1
- [AppController checkSession:]
objj_msgSend
- [CPInvocation invoke]
objj_msgSendFast0
- [CPTimer fire]
objj_msgSendFast0
- [CPRunLoop limitDateForMode:]
objj_msgSendFast1
(anonymous function)

From this:

_sessionAlert = [CPAlert alertWithMessageText:"Your session will expire in less than 60 seconds" defaultButton:"Extend" alternateButton:"Cancel" otherButton:nil informativeTextWithFormat:"Login sessions time out after a period of inactivity. Click 'Extend' to extend your session."];
[_sessionAlert runModalWithDidEndBlock:function (alert, returnCode) { /* code */ }];

As you can see it is called from a method invoked by a timer, but I wouldn’t think that would matter. I would probably otherwise use a sheet but then I get into complicated checks for existing sheets...

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

Martin Carlberg

unread,
Mar 10, 2016, 10:00:43 AM3/10/16
to objec...@googlegroups.com
Hi!

If I guess a little the contentBounds of the CPWindow is null when evaluating the size attribute in the line where you get the error.

Why this attribute is null is a good question. Maybe you have removed the window from the screen or its content before the timer trigger. It can be some kind of bug too…

Try to set a break point in [CPWindow center] and check what is happening.


Happy coding,

- Martin
> --
> You received this message because you are subscribed to the Google Groups "Cappuccino & Objective-J" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to objectivej+...@googlegroups.com.
> To post to this group, send email to objec...@googlegroups.com.
> Visit this group at https://groups.google.com/group/objectivej.
> For more options, visit https://groups.google.com/d/optout.

Keary Suska

unread,
Mar 10, 2016, 1:53:19 PM3/10/16
to objec...@googlegroups.com

> On Mar 10, 2016, at 8:00 AM, Martin Carlberg <mar...@oops.se> wrote:
>
> Hi!
>
> If I guess a little the contentBounds of the CPWindow is null when evaluating the size attribute in the line where you get the error.
>
> Why this attribute is null is a good question. Maybe you have removed the window from the screen or its content before the timer trigger. It can be some kind of bug too…
>
> Try to set a break point in [CPWindow center] and check what is happening.

Oddly, I can get it to work sometimes with no code changes. In any case, how would I set such a breakpoint, since the method is buried somewhere deep inside (I assume) AppKit.sj?

Martin Carlberg

unread,
Mar 10, 2016, 2:12:47 PM3/10/16
to objec...@googlegroups.com
I use Chrome to debug Cappuccino code. Open the dev tools in Chrome and navigate to the CPWindow.j file with the cmd/ctrl- o command from the source tab. After you have found the CPWindow.j file find the ’center’ method with crtl/cmd-shift-o.

Check this for more info on navigate source files in Chrome dev tools: http://stackoverflow.com/questions/14608075/how-to-go-to-a-specific-file-in-chrome-developer-tools

To set break points just google after it if you need help on that.

- Martin

Keary Suska

unread,
Mar 10, 2016, 5:57:01 PM3/10/16
to objec...@googlegroups.com
Wow, the Chrome debugger is much better than Safari. Anyway, I found the following.

The code in question is this, reformatted for clarity:

containerSize = CPPlatform.isa.objj_msgSend0(CPPlatform, "isBrowser") ?

This method call returns a true value, so the next is executed:

((___r1 = self._platformWindow),

Chrome says that the _platformWindow property of self (a CPPanel) is null. Therefore the following:

___r1 == null ? null : ___r1.isa.objj_msgSend0(___r1, "contentBounds")).size

is trying to get the “size” property of “null”, rather explicitly. This must be a compiler side-effect to allow for method calls on null objects but fails when using objects in place of Foundation structs. The original code comes from this:

containerSize = [CPPlatform isBrowser] ? [_platformWindow contentBounds].size : [[self screen] visibleFrame].size;

So the question now is, why is _platformWindow sometimes null? What I have figured so far (at least in Chrome) is that if the browser window isn’t frontmost then [CPApp keyWindow] returns null, which CPAlert uses to determine the platform window. I would prefer to still be able to pop up the message when the browser is in the background, in case it would be seen by the user.

So I added this:

if (![CPApp keyWindow])
{
[_sessionAlert _createWindowWithStyle:_CPModalWindowMask];
[[_sessionAlert window] setPlatformWindow:[theWindow platformWindow]];
}

Which works, but is it unwise?

>
> On Mar 10, 2016, at 12:12 PM, Martin Carlberg <mar...@oops.se> wrote:
>
> I use Chrome to debug Cappuccino code. Open the dev tools in Chrome and navigate to the CPWindow.j file with the cmd/ctrl- o command from the source tab. After you have found the CPWindow.j file find the ’center’ method with crtl/cmd-shift-o.

Martin Carlberg

unread,
Mar 11, 2016, 8:03:38 AM3/11/16
to objec...@googlegroups.com
I’m not very familiar with platform window and when it should be set or not. Maybe someone else can answer if it is wise or unwise to do that?

- Martin

Philippe Fuentes

unread,
Apr 28, 2016, 9:36:11 AM4/28/16
to Cappuccino & Objective-J
Hi
Running into the exact same problem, did you find out why your _platformWindow is null ?

- Philippe

Dogild

unread,
May 9, 2016, 8:42:46 PM5/9/16
to Cappuccino & Objective-J
Hi guys, 

Can we have a reduction (the whole project) ? Any chance to open the issue here : https://github.com/cappuccino/cappuccino/issues

Thanks, 

Keary Suska

unread,
May 9, 2016, 10:09:31 PM5/9/16
to objec...@googlegroups.com
I have a list that I either intend to bug report or fix, and this is one of them. I have been busy trying to finish my project first, but since my launch was delayed 6 months I will probably get to it sooner.
Reply all
Reply to author
Forward
0 new messages