Tobias Giesen napsal(a):

Hello,

I had problems with arithmetic exceptions in the following routine.
I was not able to find the root of the problem, so I added this
quick safety check. This makes my application work stable. Should I
submit this as a patch?
Hi,
I have encountered exactly the same problem, but I thought that it was caused by different error somewhere else in the code.

The problem is that ARect.origin.x sometimes is +Inf or other invalid
numbers.

function CGRectToRect(const ARect: CGRect): TRect;
begin
 if (ARect.origin.x<-1e10) or
    (ARect.origin.x>1e10) then begin
    WriteLn(StdErr,'CGRectToRect: ARect.origin.x is suspicious, returning a 
zero TRect.');
    Result.Left := 0;
    Result.Top := 0;
    Result.Right := 0;
    Result.Bottom := 0;
    Exit;
    end;
 Result.Left := Floor(ARect.origin.x);
 Result.Top := Floor(ARect.origin.y);
 Result.Right := Ceil(ARect.origin.x + ARect.size.width);
 Result.Bottom := Ceil(ARect.origin.y + ARect.size.height);
end;

Can you please test this code:

function CGRectToRect(const ARect: CGRect): TRect;
begin
 if CGRectIsNull(ARect) then
 begin
    WriteLn(StdErr,'CGRectToRect: ARect.origin.x is suspicious, returning a 
zero TRect.');
    Result.Left := 0;
    Result.Top := 0;
    Result.Right := 0;
    Result.Bottom := 0;
    Exit;
 end;
 Result.Left := Floor(ARect.origin.x);
 Result.Top := Floor(ARect.origin.y);
 Result.Right := Ceil(ARect.origin.x + ARect.size.width);
 Result.Bottom := Ceil(ARect.origin.y + ARect.size.height);
end;

I searched the apple docs through, but can't find anything others concerning 
this issue. If this won't work, we can use your solution.

Tom




_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to