• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSBitmapImageRep problem (I think)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSBitmapImageRep problem (I think)


  • Subject: NSBitmapImageRep problem (I think)
  • From: Brian Williams <email@hidden>
  • Date: Fri, 19 Apr 2002 04:08:48 -0700 (PDT)

Hi everyone,

I took the advice of the kind folks here and decided to use an ImageRep to hold
my data for a screen saver. The screen saver is an implemintation of Langsont's
Ant. It's very simple the "ant" (like the turtle in logo) moves forward turns
right if on a colored square or left if not and then flips the square color.

Problem is that it keeps crashing. It runns for awhile and then poof, but not
in a predictable fashion. It's driving me nuts. I get :

Exception: EXC_BAD_ACCESS (0x0001)

and

2002-04-19 13:49:39.260 System Preferences[3176] init with frame
*** malloc[3176]: error for object 0x1d98440: Incorrect check sum for freed
object - object was probably modified after beeing freed; break at szone_error
*** malloc[3176]: error for object 0x1d9ad30: Incorrect check sum for freed
object - object was probably modified after beeing freed; break at szone_error


I have included my source code if any cares to have a look.
Thanks for any help!

#import <ScreenSaver/ScreenSaver.h>

@interface antView : ScreenSaverView
{
NSPoint position; //position on the board
int direction; //direction the ant is heading
NSBitmapImageRep* board; //the board to hold the square values
unsigned char * boardData;
}
@end

@implementation antView

- (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
{
NSLog(@"init with frame");
self = [super initWithFrame:frame isPreview:isPreview];
if (self) {
int i;
[self setAnimationTimeInterval:1/30.0];
position = NSMakePoint(frame.size.width/2,frame.size.height/2);
direction = 0;

//set up a one bit bitmap of the same size as the screen
board = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL

pixelsWide:frame.size.width

pixelsHigh:frame.size.height
bitsPerSample:1
samplesPerPixel:1
hasAlpha:NO
isPlanar:NO

colorSpaceName:NSDeviceWhiteColorSpace
bytesPerRow:0
bitsPerPixel:0];
boardData = [board bitmapData];

//be sure the bit map is clear
for(i=0; i<frame.size.width*frame.size.height; i++)
boardData[i]=0;
}
return self;
}

- (void)dealloc
{
NSLog(@"dealloc");
[board release];
}

- (void)animateOneFrame
{
int i;
//go 100 squares every tick to speed things up a little
for(i=0;i<100;i++)
{
int pos = position.x+position.y*[board pixelsWide]; //offset for our
position

if(0==boardData[pos])//turn and flip the square
{
boardData[pos] = 1;
direction++;
[[NSColor whiteColor]set];
}else{
boardData[pos] = 0;
[[NSColor blackColor] set];
direction--;
}

NSRectFill(NSMakeRect(position.x,position.y,1,1)); //fill in our square

if(direction<0) //fix the direction
direction +=4;
direction = direction%4;

switch(direction){ //move the ant
case 0:
position.y++;
break;
case 1:
position.x++;
break;
case 2:
position.y--;
break;
case 3:
position.x--;
break;
}
if(position.x>=[board pixelsWide]) position.x=0; //wrap around the
screen
if(position.y>=[board pixelsHigh]) position.y=0;
if(position.x<0)position.x=[board pixelsWide]-1;
if(position.y<0)position.y=[board pixelsHigh]-1;
}
}

- (void)startAnimation
{
[super startAnimation];
}

- (void)stopAnimation
{
[super stopAnimation];
}

- (void)drawRect:(NSRect)rect
{
[super drawRect:rect];
}

- (BOOL)hasConfigureSheet
{
return NO;
}

- (NSWindow*)configureSheet
{
return nil;
}

@end

=====
Brian Williams
homepage == <http://chromaticgray.com>
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSBitmapImageRep problem (I think)
      • From: Marcel Weiher <email@hidden>
    • Re: NSBitmapImageRep problem (I think)
      • From: email@hidden
    • Re: NSBitmapImageRep problem (I think)
      • From: Lance Bland <email@hidden>
  • Prev by Date: Re: Setting environment variables for Project Builder
  • Next by Date: Re: A suggestion for alias and symbolic links, and a request
  • Previous by thread: Re: Scripting implementation - accepting/returning ae records?
  • Next by thread: Re: NSBitmapImageRep problem (I think)
  • Index(es):
    • Date
    • Thread