0

EXC-BAD-ACCESS タイプのエラーが発生し、既存の UIImage の値を割り当てて新しい UIImage インスタンスを作成し (以下のように)、問題の原因を突き止めようとしています。整理すべきコードの山があり、どこから始めればよいかわからないので、わざわざソースを投稿するつもりはありませんが、正確に何が起こっているのかを教えていただけると、私の調査に役立つかもしれません (記憶-賢い)別のUIImageから割り当てて新しいUIImageを作成するときは?

(in the .h)

UIImage* myExistsImage;

...

@property (retain) UIImage* myExistsImage;

...

-(UIImage*)rotateImage:(UIImage*)imageToRotate;



----------------------------------------------------


(in the .m)
@synthesize myExistsImage;

...

UIImage* myNewImage = [self rotateImage:myExistsImage];


...

-(UIImage*)rotateImage:(UIImage*)imageToRotate
{

UIImage* rotatedImage = imageToRotate;

//Rotate Image Here (details omitted)...

 return rotatedImage;
}
4

2 に答える 2

2

次のようなコードで:

UIImage* src;
UIImage* dst = src;

... ポインタをコピーするだけです。dstsrcが有効な を指し続けることを確認するには、 を2 回UIImage呼び出す必要があります。ポインターが不要になったら、- を呼び出す必要があります。すべてのポインターがなくなったら、最後の呼び出しで の割り当てが解除されます。あなたが見ているのは、あなたがまだそれを使いたいと思っている間に がリリースされているということです。その場合、それが起こらないようにする必要があります。retainUIImagesrcdstreleaseUIImagereleaseUIImageUIImageretain

于 2009-08-23T14:45:15.867 に答える
2
UIImage* rotatedImage = imageToRotate;

In that line, you're not creating a new UIImage object; you're simply creating a new pointer to the old one. If Rotate Image Here implies in-place modifications to rotatedImage, then you're actually modifying myExistsImage as well.

If you want to create a new UIImage object to hold the rotated object, you'll need to explicitly do so with the UIImage alloc and init methods.

于 2009-08-23T14:10:57.013 に答える