Drawing a subview loaded from a bundle
Hi,
I'm still trying to draw a ScreenSaverView. I now have an NSView subclass that is drawing properly, but I still can't get it to draw the ScreenSaverView as a subclass.
Here's my NSView subclass:
I am getting the following errors:
*** -[Preview alloc]: selector not recognized [self = 0x3d61b0]
*** NSRunLoop ignoring exception '*** -[Preview alloc]: selector not recognized [self = 0x3d61b0]' that raised during posting of delayed perform with target 34e8a0 and selector 'openPrefPaneWithParameters:'
I'm still trying to draw a ScreenSaverView. I now have an NSView subclass that is drawing properly, but I still can't get it to draw the ScreenSaverView as a subclass.
Here's my NSView subclass:
Code:
//
// Preview.m
// DesktopSaver
//
// Created by Joseph Duchesne on 12/02/06.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//
#import "Preview.h"
@implementation Preview
void timerCallBack(CFRunLoopTimerRef timer, void *info) {
Preview *self = (Preview *)info;
CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
[self display];
CFRunLoopTimerSetNextFireDate(timer, startTime + CFRunLoopTimerGetInterval(timer));
}
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
CFRunLoopTimerContext context = {0, self, NULL, NULL, NULL};
theTimer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent(), 1.0/60.0, 0, 0, timerCallBack, &context);
CFRunLoopAddTimer(CFRunLoopGetCurrent(), theTimer, kCFRunLoopCommonModes);
}
return self;
}
- (void)drawRect:(NSRect)aRect {
if(!hasLoaded)
{
hasLoaded=TRUE;
SSBundle = [NSBundle bundleWithPath:@"/System/Library/Screen Savers/Flurry.saver"];
Class SSBundleClass;
NSLog(@"Bundle Info\n%@",[ [ SSBundle infoDictionary ] description ] );
NSLog(@"Found and loaded principalClass");
theStupidView = [[SSBundleClass alloc] initWithFrame:NSMakeRect(0,0,320,240) isPreview:YES];
[theStupidView startAnimation];
[self addSubview:theStupidView];
}
[[NSColor blackColor] set];
NSRectFill(aRect);
[theStupidView lockFocus];
[theStupidView drawRect:aRect];
[theStupidView unlockFocus];
return;
}
@endI am getting the following errors:
*** -[Preview alloc]: selector not recognized [self = 0x3d61b0]
*** NSRunLoop ignoring exception '*** -[Preview alloc]: selector not recognized [self = 0x3d61b0]' that raised during posting of delayed perform with target 34e8a0 and selector 'openPrefPaneWithParameters:'
I'm pretty certain that you don't need to implement your own NSView subclass, it should be possible to just use an NSView and call addSubview: with your screen saver view you created. In your code, where do you actually assign SSBundleClass? I cannot find that part.
I changed Class SSBundleClass; to Class SSBundleClass=[ScreenSaverView class];
But it still isn't drawing anything.
I'm getting the following console errors:
2006-02-12 12:45:22.095 System Preferences[14992] *** Assertion failure in -[ScreenSaverView lockFocus], AppKit.subproj/NSView.m:3248
2006-02-12 12:45:22.096 System Preferences[14992] lockFocus sent to a view whose window is deferred and does not yet have a corresponding platform window
2006-02-12 12:45:22.259 System Preferences[14992] *** Assertion failure in -[ScreenSaverView lockFocus], AppKit.subproj/NSView.m:3248
2006-02-12 12:45:22.260 System Preferences[14992] lockFocus sent to a view whose window is deferred and does not yet have a corresponding platform window
2006-02-12 12:45:22.359 System Preferences[14992] *** Assertion failure in -[ScreenSaverView lockFocus], AppKit.subproj/NSView.m:3248
2006-02-12 12:45:22.359 System Preferences[14992] lockFocus sent to a view whose window is deferred and does not yet have a corresponding platform window
But it still isn't drawing anything.
I'm getting the following console errors:
2006-02-12 12:45:22.095 System Preferences[14992] *** Assertion failure in -[ScreenSaverView lockFocus], AppKit.subproj/NSView.m:3248
2006-02-12 12:45:22.096 System Preferences[14992] lockFocus sent to a view whose window is deferred and does not yet have a corresponding platform window
2006-02-12 12:45:22.259 System Preferences[14992] *** Assertion failure in -[ScreenSaverView lockFocus], AppKit.subproj/NSView.m:3248
2006-02-12 12:45:22.260 System Preferences[14992] lockFocus sent to a view whose window is deferred and does not yet have a corresponding platform window
2006-02-12 12:45:22.359 System Preferences[14992] *** Assertion failure in -[ScreenSaverView lockFocus], AppKit.subproj/NSView.m:3248
2006-02-12 12:45:22.359 System Preferences[14992] lockFocus sent to a view whose window is deferred and does not yet have a corresponding platform window
Ok, I just changed back to how it was before I made the view its own file.
here's the code:
The bundle is loading and init'ing properly, it's printing out the normal init stuff I made it print out but...
When it is drawn, I get a huge number of the following error:
Assertion failure in -[uDGS lockFocus], AppKit.subproj/NSView.m:3248
lockFocus sent to a view whose window is deferred and does not yet have a corresponding platform window
And that error just keeps repeating in the console until I quit.
Any idea what I'm doing wrong?
here's the code:
Code:
SSBundle = [NSBundle bundleWithPath:@"/Users/josephduchesne/Library/Screen Savers/uDG Screensaver.saver"];
Class SSBundleClass=[ SSBundle principalClass ];
newView = [[SSBundleClass alloc] initWithFrame:NSMakeRect(0,0,320,240) isPreview:YES];
[theStupidView addSubview:newView];
[newView startAnimation];When it is drawn, I get a huge number of the following error:
Assertion failure in -[uDGS lockFocus], AppKit.subproj/NSView.m:3248
lockFocus sent to a view whose window is deferred and does not yet have a corresponding platform window
And that error just keeps repeating in the console until I quit.
Any idea what I'm doing wrong?
From where I'm standing, it looks like you're not adding the view to a window? You're adding it to a view as a subview, but does the superview belong to a window? And is that window shown?
The view is part of the window in IB. The window is shown and this code is not run until after that point.
Joseph Duchesne Wrote:The view is part of the window in IB. The window is shown and this code is not run until after that point.
Uhh, if you're making a screen saver, you can just use the Screen Saver XCode template project... I believe these were introduced around XCode 2.1? (Someone correct me if I'm wrong.)
The template is really straightforward, and includes most of the hooks you need. (Additionally, you can forego the timer loop.) There are also a couple of excellent examples over at cocoadevcentral that get you through this step by step (for OpenGL and Quartz SSViews).
Ignore this comment if I completely missed the point or you're doing something else.
I'm not creating a screensaver, I'm displaying a screensaver, like the screensaver preferencePane in System Preferences.
If this isn't for a commercial product, take a look at SaverLab's source code:
http://www.dozingcatsoftware.com/
Actually, I think it is released under the MIT License, although it is not included in the source as far as I can tell (it is at the end of the online Readme)
Edit: Found it! The readme is inside the English.lproj folder 0.o
http://www.dozingcatsoftware.com/
Actually, I think it is released under the MIT License, although it is not included in the source as far as I can tell (it is at the end of the online Readme)
Edit: Found it! The readme is inside the English.lproj folder 0.o
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| grayscale loaded as gl_alpha: all texture is white | sefiroths | 2 | 4,737 |
Jan 18, 2011 12:34 AM Last Post: sefiroths |
|
| grayscale loaded as gl_alpha: the opaque image can be only white? | sefiroths | 2 | 5,092 |
Jan 14, 2011 08:06 AM Last Post: sefiroths |
|
| NSView loaded from bundle won't draw... | Joseph Duchesne | 1 | 3,129 |
Feb 12, 2006 03:33 AM Last Post: Cochrane |
|

