2010-12-07 6 views
1

Xcodeで私のプログラムが一時停止する原因は何ですか?ブレークポイントは設定されていません。コードを実行すると、gdbプロンプトがコマンドラインに表示されます。誰にもこれについての迅速なアドバイスがありますか? プログラム自体はクラッシュせず、適切な値を返します。それだけでは実行を停止しません。GDBはブレークポイントが設定されていなくてもXCodeでプログラムを一時停止します

私が取り組んでいることの少しを教えてください。私は、Objective-C 2.0のStephen Kochanプログラミングからのいくつかの演習を行っています。これが起こった運動は8.6です。このエクササイズでは、2つの他の矩形間に交差するデータを持つ矩形オブジェクトを作成する簡単なメソッドを作成するように求められます。

私の主な次のようになります。

#import "Rectangle.h" 
#import "XYPoint.h" 
#import <stdio.h> 

int main (int argc, const char * argv[]) { 
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 

    Rectangle *myRectangle = [[Rectangle alloc] init]; 
    XYPoint *myPoint = [[XYPoint alloc] init]; 
    Rectangle *secondRectangle = [[Rectangle alloc] init]; 
    XYPoint *secondPoint = [[XYPoint alloc] init]; 
    Rectangle *intersectRectangle; 

    [myRectangle setWidth:100 andHeight:180]; 
    [myPoint setX:400 andY:300]; 
    [myRectangle setOrigin:myPoint]; 

    [secondRectangle setWidth:250 andHeight:75]; 
    [secondPoint setX:200 andY:420]; 
    [secondRectangle setOrigin:secondPoint]; 

    intersectRectangle = [myRectangle intersect:secondRectangle]; 

    NSLog(@"Width: %i, Height: %i", intersectRectangle.width, intersectRectangle.height); 
    NSLog(@"With translated origin (%i, %i)", intersectRectangle.origin.x, intersectRectangle.origin.y); 

    [myRectangle release]; 
    [myPoint release]; 
    [secondRectangle release]; 
    [secondPoint release]; 
    [intersectRectangle release]; 
    [pool drain]; 
    return 0; 
} 

そして、次のようなクラスのメソッド:

-(Rectangle *)intersect:(Rectangle *)rect{ 
    if (intersectingRect) { 
     [intersectingRect release]; 
    } 
    intersectingRect = [[Rectangle alloc] init]; 
    XYPoint *intersectPt = [[XYPoint alloc] init]; 
    int intersectWidth = 0; 
    int intersectHeight = 0; 
    int intersectX = 0; 
    int intersectY = 0; 

    if(origin.x < rect.origin.x) { 
     if ((origin.x + width) > rect.origin.x) { 
      if ((origin.x + width) > (rect.origin.x+rect.height)) { 
       if (origin.y < rect.origin.y) { 
        if ((origin.y+height) > rect.origin.y) { 
         if ((origin.y + height) > (rect.origin.y + rect.height)) { 
          intersectWidth = rect.width; 
          intersectHeight = rect.height; 
          intersectX = rect.origin.x; 
          intersectY = rect.origin.y; 
         } else { 
          intersectWidth = rect.width; 
          intersectHeight = origin.y + height - rect.origin.y; 
          intersectX = rect.origin.x; 
          intersectY = rect.origin.y; 
         } 
        } else { 
         intersectWidth = 0; 
         intersectHeight = 0; 
         intersectX = 0; 
         intersectY = 0; 
        } 
       } else if ((rect.origin.y + rect.height) > origin.y) { 
        if ((rect.origin.y + rect.height) > (origin.y + height)) { 
         intersectWidth = rect.width; 
         intersectHeight = height; 
         intersectX = rect.origin.x; 
         intersectY = origin.y; 
        } else { 
         intersectWidth = rect.width; 
         intersectHeight = rect.origin.y + rect.height - origin.y; 
         intersectX = rect.origin.x; 
         intersectY = origin.y; 
        } 
       } else { 
        intersectWidth = 0; 
        intersectHeight = 0; 
        intersectX = 0; 
        intersectY = 0; 
       } 
      } else if (origin.y < rect.origin.y) { 
       if ((origin.y + height) > rect.origin.y) { 
        if ((origin.y + height) > (rect.origin.y + rect.height)) { 
         intersectWidth = origin.x + width - rect.origin.x; 
         intersectHeight = rect.height; 
         intersectX = rect.origin.x; 
         intersectY = rect.origin.y; 
        } else { 
         intersectWidth = origin.x + width - rect.origin.x; 
         intersectHeight = origin.y + height - rect.origin.y; 
         intersectX = rect.origin.x; 
         intersectY = rect.origin.y; 
        } 
       } else { 
        intersectWidth = 0; 
        intersectHeight = 0; 
        intersectX = 0; 
        intersectY = 0; 
       } 
      } else if ((rect.origin.y + rect.height) > origin.y) { 
       if ((rect.origin.y + rect.height) < (origin.y + height)) { 
        intersectWidth = origin.x + width - rect.origin.x; 
        intersectHeight = rect.origin.y + rect.height - origin.y; 
        intersectX = rect.origin.x; 
        intersectY = origin.y; 
       } else { 
        intersectWidth = origin.x + width - rect.origin.x; 
        intersectHeight = height; 
        intersectX = rect.origin.x; 
        intersectY = origin.y; 
       } 
      } else { 
       intersectWidth = 0; 
       intersectHeight = 0; 
       intersectX = 0; 
       intersectY = 0; 
      } 
     } else { 
      intersectWidth = 0; 
      intersectHeight =0; 
      intersectX = 0; 
      intersectY = 0; 
     } 
    } else if (origin.x < (rect.origin.x + rect.width)) { 
     if ((origin.x + width) > (rect.origin.x + rect.width)) { 
      if (origin.y < rect.origin.y) { 
       if ((origin.y+height) > rect.origin.y) { 
        if ((origin.y + height) > (rect.origin.y + rect.height)) { 
         intersectWidth = rect.origin.x + rect.width - origin.x; 
         intersectHeight = rect.height; 
         intersectX = origin.x; 
         intersectY = rect.origin.y; 
        } else { 
         intersectWidth = rect.origin.x + rect.width - origin.x; 
         intersectHeight = origin.y + height - rect.origin.y; 
         intersectX = origin.x; 
         intersectY = rect.origin.y; 
        } 
       } else { 
        intersectWidth = 0; 
        intersectHeight = 0; 
        intersectX = 0; 
        intersectY = 0; 
       } 
      } else if (origin.y < (rect.origin.y + rect.height)) { 
       if ((origin.y + height) > (rect.origin.y + rect.height)) { 
        intersectWidth = rect.origin.x + rect.width - origin.x; 
        intersectHeight = rect.origin.y + rect.height - origin.y; 
        intersectX = origin.x; 
        intersectY = origin.y; 
       } else { 
        intersectWidth = rect.origin.x + rect.width - origin.x; 
        intersectHeight = height; 
        intersectX = origin.x; 
        intersectY = origin.y; 
       } 
      } else { 
       intersectWidth = 0; 
       intersectHeight = 0; 
       intersectX = 0; 
       intersectY = 0; 
      } 
     } else if (origin.y < rect.origin.y) { 
      if ((origin.y + height) > rect.origin.y) { 
       if ((origin.y + height) > (rect.origin.y + rect.height)) { 
        intersectWidth = width; 
        intersectHeight = rect.height; 
        intersectX = origin.x; 
        intersectY = rect.origin.y; 
       } else { 
        intersectWidth = width; 
        intersectHeight = origin.y + height - rect.origin.y; 
        intersectX = origin.x; 
        intersectY = rect.origin.y; 
       } 
      } else { 
       intersectWidth = 0; 
       intersectHeight = 0; 
       intersectX = 0; 
       intersectY = 0; 
      } 
     } else if (origin.y < (rect.origin.y + rect.height)) { 
      if ((origin.y + height) > (rect.origin.y + rect.height)) { 
       intersectWidth = width; 
       intersectHeight = rect.origin.y + rect.height - origin.y; 
       intersectX = origin.x; 
       intersectY = origin.y; 
      } else { 
       intersectWidth = width; 
       intersectHeight = height; 
       intersectX = origin.x; 
       intersectY = origin.y; 
      } 
     } else { 
      intersectWidth = 0; 
      intersectHeight = 0; 
      intersectX = 0; 
      intersectY = 0; 
     } 
    } else { 
     intersectWidth = 0; 
     intersectHeight = 0; 
     intersectX = 0; 
     intersectY = 0; 
    } 
    [intersectingRect setWidth:intersectWidth andHeight:intersectHeight]; 
    [intersectPt setX:intersectX andY:intersectY]; 
    [intersectingRect setOrigin:intersectPt]; 
    return intersectingRect; 
} 

事は、私は完全にブレークポイントを無効にしたくないということです。なぜ私はブレークポイントを設定していないので、このケースで実行が一時停止しているのか分かりません。私は最終的にそれらを使用したいので、ブレークポイントを無効にしたくありません。予期せず一時停止しているのはこの特定のケースです。

+0

シンプルリスタートを試しましたか?多くの場合、XCodeはこれで混乱することがあります(これまで同様のことが起こっていました)。これは実際にあなたの質問に対する回答ではありませんが(例えば原因は何か)、解決する可能性もあります。 – makdad

+0

@phooze私はそれを試しましたが、それでも実行を停止しません。私は他のクラスを走らせることができ、彼らは一時停止しません。 –

+0

これらの手順についてはどうすればいいですか:http://stackoverflow.com/questions/1067689/how-to-disable-all-breakpoints-in-xcode – makdad

答えて

2

プログラムは何らかの理由で、すでにリリースされたオブジェクトにメッセージを送信しようとしました。 deallocメソッドのオーバーロードを修正すると、一時停止の問題が解決されました。交差メソッド内で作成されていたオブジェクトは、オーバーロードされたdeallocメソッドによって解放されました。したがって、メインがそれをリリースするためにメッセージを送信しようとしたとき、それはすでに消えていました。

+1

補足として、これをデバッグするにはNSZombiesEnabledをYESに設定してみてください。 –

+0

ありがとう、私はします。特別なアドバイスを受けるのは常に良いことです。特に、新しいものへの移行をしているときは特にそうです。 –

0

:私が答えたときにあなたの質問にコードはありませんでしたので、これは問題ではないようです。誰かが私が持っていた同じ一時停止の問題を抱えている場合に備えて、ここに残しておきます。


実際には、[続行]ボタンが使用可能で、緑色で表示されていますか?

実行が停止しているように見える場合 - コードdosntが実行されているように見えますが、実際には一時停止していない場合 - アプリケーションが実行ループに座って入力を待っている可能性があります実際にはその準備が整っており、掛けられているようです。

そのような場合、それは私がデリゲートプロトコルを持っていたが、私はプログラムの流れが予想されるデリゲートメソッドに返されることはありませんので、デリゲートとして自己を設定することを怠っ何かを呼ばれたときに私に起こっているものと類似していてもよいです。

どうもありがとうございます。

+0

はい、ビルドボタンは緑色で、停止実行ボタンは使用可能で赤色です。 –

+0

ビルドボタンが緑色で、実行の停止ボタンが赤色の場合、プログラムは一時停止されずに実行されます。 「続行」ボタンはなく、「一時停止」ボタンだけです。あなたは一時停止していません。 –

+0

そうですね、プログラムは実行されていましたが、gdbプロンプトが表示されたときには、単にあなたと対話するのを待っています。私はそれが実行上の一種の休止だと思った。 –

関連する問題