Skip to main content
replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

eBuisiness's answereBuisiness's answer is correct. But you're setting the HasBeenHandled flag after trying to update all the neighbors which then causes a stack overflow. You should instead set the flag before doing anything else.

EDIT: You've also made typos in the if statements.

  if (Bottom.btn != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left.btn != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right.btn != null)
      set_text_of_button(Bottom_Right.btn);

should be

  if (Bottom != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right != null)
      set_text_of_button(Bottom_Right.btn);

Also, you'll need to stop this habit of initializing variables by allocating dummy objects. It is better to assign null than create a new object you're not going to use. For example, your find_by_coordinates function would be better written as

  protected Block find_by_coordinates(int x,int y)
  {
      Block return_value = null;
      foreach (Block blk in arr_buttons)
      {
          if (blk.x == x && blk.y == y)
          {
              return_value = blk;
              break;
          }
      }
      return return_value;
  }

Now, when the coordinate has no button a null value is returned instead of a dummy Block object which was leading to NullReferenceExceptions because the program was trying to work with these dummy objects.

eBuisiness's answer is correct. But you're setting the HasBeenHandled flag after trying to update all the neighbors which then causes a stack overflow. You should instead set the flag before doing anything else.

EDIT: You've also made typos in the if statements.

  if (Bottom.btn != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left.btn != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right.btn != null)
      set_text_of_button(Bottom_Right.btn);

should be

  if (Bottom != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right != null)
      set_text_of_button(Bottom_Right.btn);

Also, you'll need to stop this habit of initializing variables by allocating dummy objects. It is better to assign null than create a new object you're not going to use. For example, your find_by_coordinates function would be better written as

  protected Block find_by_coordinates(int x,int y)
  {
      Block return_value = null;
      foreach (Block blk in arr_buttons)
      {
          if (blk.x == x && blk.y == y)
          {
              return_value = blk;
              break;
          }
      }
      return return_value;
  }

Now, when the coordinate has no button a null value is returned instead of a dummy Block object which was leading to NullReferenceExceptions because the program was trying to work with these dummy objects.

eBuisiness's answer is correct. But you're setting the HasBeenHandled flag after trying to update all the neighbors which then causes a stack overflow. You should instead set the flag before doing anything else.

EDIT: You've also made typos in the if statements.

  if (Bottom.btn != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left.btn != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right.btn != null)
      set_text_of_button(Bottom_Right.btn);

should be

  if (Bottom != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right != null)
      set_text_of_button(Bottom_Right.btn);

Also, you'll need to stop this habit of initializing variables by allocating dummy objects. It is better to assign null than create a new object you're not going to use. For example, your find_by_coordinates function would be better written as

  protected Block find_by_coordinates(int x,int y)
  {
      Block return_value = null;
      foreach (Block blk in arr_buttons)
      {
          if (blk.x == x && blk.y == y)
          {
              return_value = blk;
              break;
          }
      }
      return return_value;
  }

Now, when the coordinate has no button a null value is returned instead of a dummy Block object which was leading to NullReferenceExceptions because the program was trying to work with these dummy objects.

eBuisiness' answereBuisiness's answer is correct. But you're setting the HasNeenHandledHasBeenHandled flag after trying to update all the neighboursneighbors which then causes a stack overflow. You should instead set the flag before doing anything else.

EDIT: You've also made typos in the ifif statements.

  if (Bottom.btn != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left.btn != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right.btn != null)
      set_text_of_button(Bottom_Right.btn);

should be

  if (Bottom != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right != null)
      set_text_of_button(Bottom_Right.btn);

Also, you'll need to stop this habbithabit of initializing valiablesvariables by allocating dummy objects. It is better to assign null than create a new object you're not supposedgoing to use. For example, your find_by_coordinates function would be better written as

  protected Block find_by_coordinates(int x,int y)
  {
      Block return_value = null;
      foreach (Block blk in arr_buttons)
      {
          if (blk.x == x && blk.y == y)
          {
              return_value = blk;
              break;
          }
      }
      return return_value;
  }

Now, when the coordinate has no button a null value is returned instead of a dummy Block object which was leading to NullReferenceExceptions because the program was trying to work with these dummy objects.

eBuisiness' answer is correct. But you're setting the HasNeenHandled flag after trying to update all the neighbours which then causes a stack overflow. You should instead set the flag before doing anything else.

EDIT: You've also made typos in the if statements.

  if (Bottom.btn != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left.btn != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right.btn != null)
      set_text_of_button(Bottom_Right.btn);

should be

  if (Bottom != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right != null)
      set_text_of_button(Bottom_Right.btn);

Also, you'll need to stop this habbit of initializing valiables by allocating dummy objects. It is better to assign null than create a new object you're not supposed to use. For example your find_by_coordinates function would be better written as

  protected Block find_by_coordinates(int x,int y)
  {
      Block return_value = null;
      foreach (Block blk in arr_buttons)
      {
          if (blk.x == x && blk.y == y)
          {
              return_value = blk;
              break;
          }
      }
      return return_value;
  }

Now, when the coordinate has no button a null value is returned instead of a dummy Block object which was leading to NullReferenceExceptions because the program was trying to work with these dummy objects.

eBuisiness's answer is correct. But you're setting the HasBeenHandled flag after trying to update all the neighbors which then causes a stack overflow. You should instead set the flag before doing anything else.

EDIT: You've also made typos in the if statements.

  if (Bottom.btn != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left.btn != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right.btn != null)
      set_text_of_button(Bottom_Right.btn);

should be

  if (Bottom != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right != null)
      set_text_of_button(Bottom_Right.btn);

Also, you'll need to stop this habit of initializing variables by allocating dummy objects. It is better to assign null than create a new object you're not going to use. For example, your find_by_coordinates function would be better written as

  protected Block find_by_coordinates(int x,int y)
  {
      Block return_value = null;
      foreach (Block blk in arr_buttons)
      {
          if (blk.x == x && blk.y == y)
          {
              return_value = blk;
              break;
          }
      }
      return return_value;
  }

Now, when the coordinate has no button a null value is returned instead of a dummy Block object which was leading to NullReferenceExceptions because the program was trying to work with these dummy objects.

added 1370 characters in body
Source Link
Anton
  • 434
  • 4
  • 9

eBuisiness' answer is correct. But you're setting the HasNeenHandled flag after trying to update all the neighbours which then causes a stack overflow. You should instead set the flag before doing anything else.

EDIT: You've also made typos in the if statements.

  if (Bottom.btn != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left.btn != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right.btn != null)
      set_text_of_button(Bottom_Right.btn);

should be

  if (Bottom != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right != null)
      set_text_of_button(Bottom_Right.btn);

Also, you'll need to stop this habbit of initializing valiables by allocating dummy objects. It is better to assign null than create a new object you're not supposed to use. For example your find_by_coordinates function would be better written as

  protected Block find_by_coordinates(int x,int y)
  {
      Block return_value = null;
      foreach (Block blk in arr_buttons)
      {
          if (blk.x == x && blk.y == y)
          {
              return_value = blk;
              break;
          }
      }
      return return_value;
  }

Now, when the coordinate has no button a null value is returned instead of a dummy Block object which was leading to NullReferenceExceptions because the program was trying to work with these dummy objects.

eBuisiness' answer is correct. But you're setting the HasNeenHandled flag after trying to update all the neighbours which then causes a stack overflow. You should instead set the flag before doing anything else.

eBuisiness' answer is correct. But you're setting the HasNeenHandled flag after trying to update all the neighbours which then causes a stack overflow. You should instead set the flag before doing anything else.

EDIT: You've also made typos in the if statements.

  if (Bottom.btn != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left.btn != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right.btn != null)
      set_text_of_button(Bottom_Right.btn);

should be

  if (Bottom != null)
      set_text_of_button(Bottom.btn);
  if (Bottom_Left != null)
      set_text_of_button(Bottom_Left.btn);
  if (Bottom_Right != null)
      set_text_of_button(Bottom_Right.btn);

Also, you'll need to stop this habbit of initializing valiables by allocating dummy objects. It is better to assign null than create a new object you're not supposed to use. For example your find_by_coordinates function would be better written as

  protected Block find_by_coordinates(int x,int y)
  {
      Block return_value = null;
      foreach (Block blk in arr_buttons)
      {
          if (blk.x == x && blk.y == y)
          {
              return_value = blk;
              break;
          }
      }
      return return_value;
  }

Now, when the coordinate has no button a null value is returned instead of a dummy Block object which was leading to NullReferenceExceptions because the program was trying to work with these dummy objects.

Source Link
Anton
  • 434
  • 4
  • 9
Loading