• 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
Re: Newbie (BAD_ACCESS)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie (BAD_ACCESS)


  • Subject: Re: Newbie (BAD_ACCESS)
  • From: Bernard Banks <email@hidden>
  • Date: Mon, 24 Mar 2003 08:18:06 -0800

>> I have a program that draws on NSView myView with drawRect. I am
>> trying to
>> include a toy subroutine to draw a line in myView by using a class
>> method
>> +(void)drawLine:(float)X:(float)Y defined in the subclass Line.h and
>> Line.m
>> of NSObj. In drawRect I make the call [Line drawLine:100.0:100.0]. In
>> compiling, I get two warnings, 1) invalid receiver type 'void (short
>> int,short int)', and 2) passing arg 1 of pointer to function from
>> incompatible pointer type.
>>
>> Under debug, the program chokes at [Line drawLine:100.0:100.0] and
>> gives me
>> the EXE_BAD_ACCESS error. If this line is left out the program runs
>> with no
>> problem.
>
> You're getting this error because the compiler is casting the numbers
> in your +drawLine call as integers and not floats. The BAD_ACCESS
> error you're getting is basically a segmentation fault, which
> indicates a memory problem.
>
>

Thomas Lachand-Robert suggested:

Not at all. The compiler would correctly convert an int to float in a
method call if an argument is declared so. Also 100.0 is actually a
double, not a short int. (Use 100.0f if you want to make sure that it's
a float).

Your error message says: "invalid RECEIVER"; this means that the object
receiving the message is not as expected. Try [[Line class]
drawLine:100.0:100.0], but I suspect there is something wrong in your
Line.h file: are you sure you define a class here?

I wrote to Thomas saying:

> Dear Thomas,
> Thanks for your suggestion. I am afraid that neither your suggestion or
> Nick's worked. I am missing something fundamental. I imported the
> class from
> IB, so IB structured Line.h and Line.m. Here are both files:
>
> /* Line */
>
> #import <Cocoa/Cocoa.h>
>
> @interface Line : NSObject
> {
> }
>
> +(void)drawLine:(float)X:(float)Y;
> @end
>
> And
>
> #import <Cocoa/Cocoa.h>
> #import "Line.h"
>
> @implementation Line
>
> +(void)drawLine:(float)X:(float)Y
> {
> NSPoint p1 = NSMakePoint(0,0);
> NSPoint p2 = NSMakePoint(X,Y);
> [NSBezierPath strokeLineFromPoint:p1 toPoint:p2];
>
>
> }
>
> @end
>
> Why the warning '(void)(short int, short int)' should appear when the
> call
> is +(void)drawLine:(float)X:(float)Y is beyond me.
>

Finally, the program exits with the signal 10 (sigbus), whatever that is?
Any further light would be greatly appreciated.

Bernard
_______________________________________________
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.

  • Prev by Date: Re: Where do I put the file?
  • Next by Date: Re: Where do I put the file?
  • Previous by thread: Re: Where do I put the file?
  • Next by thread: mount_webdav Wedging Finder
  • Index(es):
    • Date
    • Thread