Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Evasive Bug... Could Be Anything  (Read 8809 times)

0 Members and 1 Guest are viewing this topic.

Noegddgeon

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
    • Soundcloud
Evasive Bug... Could Be Anything
« on: December 15, 2010, 07:50:32 am »
Hello :] I went back to an old Pong game I had written several months ago the other day and finished it up.... well, almost. It was working fairly well, with the title screen, losing screen, winning screen, etc. functioning normally. However, it had no sound effects, so I added a sound effect for when the paddles hit the ball. It took me some trial and error in figuring out how to compile the program once I created a buffer and a Sound object (and I had forgotten to link the audio framework, but I took care of that to seal the compilation deal ;]). However, it's compiled now.... the only problem is, it just shows me the very familiar white screen of infinite loop death. I am compiling this under Xcode 3.1.4 on my MacBook, but I don't think that has anything to do with it. Rather, I think something had to have gotten messed up when I added in the sounds. Here, I'll post the source code... it's a bit lengthy, but I commented a bit. Note: I have learned how to code better than this and I know I should have built classes for it, but this was before I learned anything about OOP. I just wanted to clean this project up and finish it so I could be done with it forever :p Here goes:

Code: [Select]

/* This game is basically a simple remake of Pong. It will be for two players. */

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>

// Function prototypes
int distance(int, int, int, int);
void getInput(int&, int&, int&, int&, sf::Clock&, sf::Clock&);
void calculateBall(int&, int&, sf::Clock&, int&, int&, int&, double&, sf::Sound&);
void drawScore(sf::RenderWindow&, int&, int, int);
void screen(sf::RenderWindow&, sf::Sprite&, sf::View&);

// ENUMS
   enum BallDirection // Different directions/velocities
   {
      UpRight, DownRight, UpLeft, DownLeft
   };
   
   enum PaddleDirection // Different directions/velocities
   {
      Up, Down, Still
   };

// ************ //

// Paddle structure declaration
struct Paddle
{
   int x, y; // Paddle coordinates, upper left
   int botx, boty; // Paddle coordinates, bottom right
   int direction; // Paddle going up or down?
   sf::Clock PaddleTimer; // Movement timer
   
   Paddle(int xcoord, int ycoord, int bottomx, int bottomy, PaddleDirection direc) // Constructor
   {
      x = xcoord;
 y = ycoord;
 botx = bottomx;
 boty = bottomy;
 direction = direc;
   }
};

// Ball structure declaration
struct Ball
{
   int x, y; // Ball's position in the field
   int size; // Ball's size
   int direction; // Ball's current direction/velocity
   double speed; // Speed (less is more)
   sf::Clock BallTimer; // Movement timer
   
   Ball(int xcoord, int ycoord, int ballSize, double ballSpeed = 0.7)
   {
      x = xcoord;
 y = ycoord;
 size = ballSize;
   }
};

// Render window declaration
sf::RenderWindow App(sf::VideoMode(800, 600), "T4 Pong");

// View declaration -- Atari resolution
sf::View View(sf::FloatRect(0, 0, 192, 160));

// Event Receiver
sf::Event Event;

// Input Receiver
const sf::Input& Input = App.GetInput();

// Images for screens
sf::Image titleImage;
sf::Image winningImage;
sf::Image losingImage;

// Sprites for screens
sf::Sprite titleSprite;
sf::Sprite winningSprite;
sf::Sprite losingSprite;

// Audio variables
sf::SoundBuffer paddleBuffer;
sf::Sound paddleSound;

   // Player and ball declarations
   // **PLAYER 1**
   Paddle Player1(5, 60, 7, 70, Still);
   
   // **PLAYER 2**
   Paddle Player2(184, 60, 186, 70, Still);
   
   // **BALL**
   Ball Ball(80, 80, 2);

int main()
{
   // Game start variable
   bool gameStart = true;

   // Score variable
   
   int score1 = 0, score2 = 0;
   
   // Ball's speed
   double ballSpeed = 0.03;
   
   // Load buffer
   paddleBuffer.LoadFromFile("paddle_hit.wav");
   
   // Set sound
   paddleSound.SetBuffer(paddleBuffer);
   
   // Load images
   titleImage.LoadFromFile("pong_title.png");
   winningImage.LoadFromFile("you_win.png");
   losingImage.LoadFromFile("you_lose.png");
   
   // Set smoothness off
   titleImage.SetSmooth(false);
   winningImage.SetSmooth(false);
   losingImage.SetSmooth(false);

   // Initialize sprites
   titleSprite.SetImage(titleImage);
   winningSprite.SetImage(winningImage);
   losingSprite.SetImage(losingImage);
   titleSprite.SetPosition(0,0);
   winningSprite.SetPosition(0,0);
   losingSprite.SetPosition(0,0);
   
   // Start initialization / escape sequences (events)
   while (App.IsOpened())
   {
      while (App.GetEvent(Event))
 {
    if (Event.Type == sf::Event::Closed)
   App.Close();

if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
   App.Close();
 }
 
 // Opening screen
 if (gameStart)
 {
    screen(App, titleSprite, View);
gameStart = false;
 }
 
 // Game loop activities
 
 // Process input
 getInput(Player1.y, Player1.boty, Player2.y, Player2.boty, Player1.PaddleTimer, Player2.PaddleTimer);
 
 // Calculate ball
 calculateBall(Ball.x, Ball.y, Ball.BallTimer, Ball.direction, score1, score2, ballSpeed, paddleSound);
 
 // Clear previous screen
 App.Clear();
 
 // Draw the paddles and the ball
 App.Draw(sf::Shape::Rectangle(Player1.x, Player1.y, Player1.botx, Player1.boty, sf::Color::White));
 App.Draw(sf::Shape::Rectangle(Player2.x, Player2.y, Player2.botx, Player2.boty, sf::Color::White));
 App.Draw(sf::Shape::Circle(Ball.x, Ball.y, Ball.size, sf::Color::Blue));
 
 // Draw scores
 drawScore(App, score1, 30, 5);
 drawScore(App, score2, 160, 5);
 
 // Set the View
 App.SetView(View);
 
 // Lose or Win?
 if (score1 == 10)
 {
    screen(App, winningSprite, View);
score1 = 0;
score2 = 0;
 }
 
 if (score2 == 10)
 {
    screen(App, losingSprite, View);
score1 = 0;
score2 = 0;
 }
 
 // Display final image
 App.Display();
 
   } // End loop
   
   return EXIT_SUCCESS;
} // end main

// Functions and their declarations

// Distance formula
int distance(int x1, int y1, int x2, int y2)
{
   int temp = pow((x2 - x1), 2) + pow((y2 - y1), 2);
   return sqrt(temp);
}

// Process inputs and move players accordingly
void getInput(int &y1, int &boty1, int &y2, int &boty2, sf::Clock &Pad1, sf::Clock &Pad2)
{
   App.GetInput();
   
   if ((Input.IsKeyDown(sf::Key::Up)) && (Pad1.GetElapsedTime() >= 0.01))
   {
      if (y1 > 0)
      {
    y1--;
    boty1--;
 }
 Pad1.Reset();
   }
   else if ((Input.IsKeyDown(sf::Key::Down)) && (Pad1.GetElapsedTime() >= 0.01))
   {
      if (y1 < 150)
 {
         y1++;
    boty1++;
 }
 Pad1.Reset();
   }
   
   if ((Input.IsKeyDown(sf::Key::Q)) && (Pad2.GetElapsedTime() >= 0.01))
   {
      if (y2 > 0)
 {
         y2--;
    boty2--;
 }
 Pad2.Reset();
   }
   else if ((Input.IsKeyDown(sf::Key::A)) && (Pad2.GetElapsedTime() >= 0.01))
   {
      if (y2 < 150)
 {
         y2++;
    boty2++;
 }
 Pad2.Reset();
   }
}

// Calculate ball and its movement
void calculateBall(int &x, int &y, sf::Clock& ballTime, int &direc, int &score1, int &score2, double &ballSpeed, sf::Sound &paddle)
{
   if (ballTime.GetElapsedTime() >= ballSpeed)
   {
      if (direc == UpRight) // Ball traveling up and to the right?
 {
    if (x >= 192)
{
   score1++;
x = y = 80;
ballTime.Reset();
direc = UpLeft;
ballSpeed = 0.03;
}
else if (y <= 3)
{
   direc = DownRight;
ballTime.Reset();
}
else if ((x >= 184 && x <= 186) && (y >= Player2.y && y <= Player2.boty))
{
   direc = UpLeft;
ballTime.Reset();
ballSpeed -= 0.002;
paddle.Play();
}
else
{
   y--;
x++;
   ballTime.Reset();
}

return;
 }
 
 if (direc == DownRight) // Ball traveling down and to the right?
 {
    if (x >= 192)
{
       score1++;
   x = y = 80;
   ballTime.Reset();
   direc = UpLeft;
ballSpeed = 0.03;
}
    else if (y >= 158)
{
   direc = UpRight;
ballTime.Reset();
}
else if ((x >= 184 && x <= 186) && (y >= Player2.y && y <= Player2.boty))
{
   direc = DownLeft;
ballTime.Reset();
ballSpeed -= 0.002;
paddle.Play();
}
else
{
   y++;
x++;
ballTime.Reset();
}

return;
 }
 
 if (direc == UpLeft) // Ball traveling up and to the left?
 {
    if (x <= 0)
{
   score2++;
x = y = 80;
ballTime.Reset();
direc = UpRight;
ballSpeed = 0.03;
}
else if (y <= 3)
{
   direc = DownLeft;
ballTime.Reset();
}
else if ((x >= 5 && x <= 7) && (y >= Player1.y && y <= Player1.boty))
{
   direc = UpRight;
ballTime.Reset();
ballSpeed -= 0.002;
paddle.Play();
}
else
{
   x--;
y--;
ballTime.Reset();
}

return;
 }
 
 if (direc == DownLeft) // Ball traveling down and to the left?
 {
    if (x <= 0)
{
   score2++;
x = y = 80;
ballTime.Reset();
direc = UpRight;
ballSpeed = 0.03;
}
else if (y >= 158)
{
   direc = UpLeft;
ballTime.Reset();
}
else if ((x >= 5 && x <= 7) && (y >= Player1.y && y <= Player1.boty))
{
   direc = DownRight;
ballTime.Reset();
ballSpeed -= 0.002;
paddle.Play();
}
else
{
   y++;
x--;
ballTime.Reset();
}

return;
 }
 
 else
    return;
   }
}

// Draw the number of the score for either player
void drawScore(sf::RenderWindow &myApp, int &score, int x, int y)
{
   switch (score)
   {
      case 0:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
break;
 case 1:
    myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
break;
 case 2:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
break;
 case 3:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
break;
 case 4:
    myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
break;
 case 5:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y + 4, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
break;
 case 6:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y + 4, x + 5, y + 8, 1, sf::Color::White));
break;
 case 7:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
break;
 case 8:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
break;
 case 9:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
break;
}
}

// Function to display a static screen that waits for the user to press return (or enter)
void screen(sf::RenderWindow &myApp, sf::Sprite &screenshot, sf::View &myView)
{
   bool proceed = false;
   sf::Event myEvent;
   
   const sf::Input& myInput = App.GetInput();
   
   while (!proceed)
   {
      myApp.Clear();
      myApp.Draw(screenshot);
      myApp.SetView(myView);
      myApp.Display();
 myApp.GetEvent(myEvent);
 myApp.GetInput();
     
 if (myInput.IsKeyDown(sf::Key::Return))
 {
    proceed = true;
 }
   }
}


Perhaps one of you awesome people can figure out what I must have done wrong..... I've tried to avoid infinite loops as best I can (which usually causes this problem for me), but I may have missed something. All the images and the .wav file are in the right directory (where the program target is). All of the frameworks are linked properly, as well. As always, any help is greatly appreciated and will further my quest to game program and lead me to post more interesting game example questions than Pong in this forum to spice it up ;] Haha, thanks everybody.

Colton
Whether you think you can or you can't, you're right.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Evasive Bug... Could Be Anything
« Reply #1 on: December 15, 2010, 08:09:33 am »
What you could do first is to remove anything that is not relevant to the problem (I think you can get rid of 95% of this code) and provide a minimal and complete code that we can easily test and debug.
Laurent Gomila - SFML developer

Noegddgeon

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
    • Soundcloud
Evasive Bug... Could Be Anything
« Reply #2 on: December 15, 2010, 08:40:50 am »
The issue is that I just don't know where the problem might be... so I find it hard to simplify the code. Before I tried to add in sound, the program worked wonderfully, and it was hardly more complex than the example shown above. But once I put those objects and functions in there with Sound and SoundBuffer, it just won't run. It's showing white, so it's not getting past this part:

Code: [Select]

// Start initialization / escape sequences (events)
   while (App.IsOpened())
   {
      while (App.GetEvent(Event))
     {
        if (Event.Type == sf::Event::Closed)
          App.Close();
         
       if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
          App.Close();
     }
   
     // Opening screen
     if (gameStart)
     {
        screen(App, titleSprite, View);
       gameStart = false;
     }


...which means that it has to call this function:

Code: [Select]

// Function to display a static screen that waits for the user to press return (or enter)
void screen(sf::RenderWindow &myApp, sf::Sprite &screenshot, sf::View &myView)
{
   bool proceed = false;
   sf::Event myEvent;
   
   const sf::Input& myInput = App.GetInput();
   
   while (!proceed)
   {
      myApp.Clear();
      myApp.Draw(screenshot);
      myApp.SetView(myView);
      myApp.Display();
 myApp.GetEvent(myEvent);
 myApp.GetInput();
     
 if (myInput.IsKeyDown(sf::Key::Return))
 {
    proceed = true;
 }
   }
}


However, that function hasn't changed since before I put in the sound features, and before, it worked perfectly. So would that mean that maybe there's an issue with the initialization of any objects to the point where the program would crash upon its execution? To me, it's a difficult problem to pinpoint, and unfortunately I can't think of a way to truncate the code that would isolate the problem :/ I hope that helped in any sort of way to clarify things though.... I greatly appreciate your help :]

Colton[/code]
Whether you think you can or you can't, you're right.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Evasive Bug... Could Be Anything
« Reply #3 on: December 15, 2010, 08:57:32 am »
Quote
I can't think of a way to truncate the code that would isolate the problem

Remove a little piece of code, test, remove a little piece of code, test, remove a little piece of code, test, ... oops the problem disappeared! put back the last piece of code, and remove another one, test, remove another piece of code, test, remove... works pretty well ;)
Laurent Gomila - SFML developer

Noegddgeon

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
    • Soundcloud
Evasive Bug... Could Be Anything
« Reply #4 on: December 15, 2010, 09:30:35 am »
Well, if you take out the sound parts, it will work. I tried several piece-out, piece-out, piece-in approaches, but I still can't figure it out, which is why I must consult the powers above (you, Laurent ;]) to help me tackle this problem... and I found something interesting.

I plugged in the handy dandy Xcode debugger and set several breakpoints.... like I anticipated, it revolves around this bit:

Code: [Select]

// Opening screen
 if (gameStart)
 {
    screen(App, titleSprite, View);
gameStart = false;
 }


and that makes reference to the function posted in my last reply. What I found out is I'm getting what programmers supposedly dread: EXC_BAD_ACCESS. And that's all it tells anyone in C++ (there are ways to make it a little more evident with Objective-C). But it's on the line with the screen() function call, which may mean the problem exists either within the call or the definition.

From my research, it means that what I'm doing there is trying to access memory that has been released already. But I don't see where that might have happened... For all I know, it could be something related to how the library itself is programmed, because I know you incorporated automatic memory management into SFML.

I hope this shed a little more light on the situation. Thank you much for your help :]
Whether you think you can or you can't, you're right.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Evasive Bug... Could Be Anything
« Reply #5 on: December 15, 2010, 09:48:34 am »
Quote
Well, if you take out the sound parts, it will work.

So... what if you keep only the sound parts?

Quote
I plugged in the handy dandy Xcode debugger and set several breakpoints....

You should let it run and break at the exact position of the crash. Then look at the call stack and local variables.

Quote
I tried several piece-out, piece-out, piece-in approaches, but I still can't figure it out, which is why I must consult the powers above (you, Laurent ;]) to help me tackle this problem...

I'm pretty sure you can remove all the functions except main() and screen() ;)
Laurent Gomila - SFML developer

Noegddgeon

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
    • Soundcloud
Evasive Bug... Could Be Anything
« Reply #6 on: December 15, 2010, 10:18:32 am »
Quote

You should let it run and break at the exact position of the crash. Then look at the call stack and local variables.


I don't have a ton of experience debugging and I would love to learn, so I'm choosing this point to work off of. I did that, and it showed me that the function responsible for the problem is sf::RenderTarget::Clear. I do not know what this function is unfortunately, but I can surmise it's one that occurs behind the lines, so to speak. And it's during that function call, the screen() function.

A few other pieces of information I have access to that don't mean anything to me because I don't know what they stand for but which I'm assuming are heavily important are as follows:

0x0026b788  <+0040>  call     *0x14(%eax)

I'm going to assume this is assembly language. These bits of information are where the debugger is telling me the problem is occurring, with the EXC_BAD_ACCESS alert. I find this very interesting, and I wish I knew what it meant.

Thanks again for your help. I'm hoping we're getting closer to solving this problem. :][/quote]
Whether you think you can or you can't, you're right.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Evasive Bug... Could Be Anything
« Reply #7 on: December 15, 2010, 10:31:42 am »
By the way, which version of SFML do you use?
Laurent Gomila - SFML developer

Noegddgeon

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
    • Soundcloud
Evasive Bug... Could Be Anything
« Reply #8 on: December 15, 2010, 11:00:35 am »
Good sir, I am using SFML 1.6 :]
Whether you think you can or you can't, you're right.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Evasive Bug... Could Be Anything
« Reply #9 on: December 15, 2010, 11:25:30 am »
I'm afraid I won't be able to help you more without a minimal code. It's not that hard to do, really. Like I said, I'm sure you can already remove all the functions (and calls to them) except main() and screen(). We don't care if the application doesn't work properly anymore, we just want it to crash ;)
Laurent Gomila - SFML developer

Noegddgeon

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
    • Soundcloud
Evasive Bug... Could Be Anything
« Reply #10 on: December 15, 2010, 11:53:31 am »
Okie doke, sir. I have done my best. :] Hope this helps.

Code: [Select]

/* This game is basically a simple remake of Pong. It will be for two players. */

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>

void screen(sf::RenderWindow&, sf::Sprite&, sf::View&);

// Render window declaration
sf::RenderWindow App(sf::VideoMode(800, 600), "T4 Pong");

// View declaration -- Atari resolution
sf::View View(sf::FloatRect(0, 0, 192, 160));

// Event Receiver
sf::Event Event;

// Input Receiver
const sf::Input& Input = App.GetInput();

// Images for screens
sf::Image titleImage;
sf::Image winningImage;
sf::Image losingImage;

// Sprites for screens
sf::Sprite titleSprite;
sf::Sprite winningSprite;
sf::Sprite losingSprite;

int main()
{
   // Game start variable
   bool gameStart = true;
   
   titleImage.LoadFromFile("pong_title.png");
   
   // Set smoothness off
   titleImage.SetSmooth(false);

   // Initialize sprites
   titleSprite.SetImage(titleImage);
   titleSprite.SetPosition(0,0);
   
   // Start initialization / escape sequences (events)
   while (App.IsOpened())
   {
      while (App.GetEvent(Event))
 {
    if (Event.Type == sf::Event::Closed)
   App.Close();

if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
   App.Close();
 }
 
 App.Clear();
 
 // Opening screen
 if (gameStart)
 {
    screen(App, titleSprite, View);
gameStart = false;
 }
 
 // Display final image
 App.Display();
 
   } // End loop
   
   return EXIT_SUCCESS;
}

// Functions and their declarations

// Function to display a static screen that waits for the user to press return (or enter)
void screen(sf::RenderWindow &myApp, sf::Sprite &screenshot, sf::View &myView)
{
   bool proceed = false;
   sf::Event myEvent;
   
   const sf::Input& myInput = App.GetInput();
   
   while (!proceed)
   {
      myApp.Clear();
      myApp.Draw(screenshot);
      myApp.SetView(myView);
      myApp.Display();
 myApp.GetEvent(myEvent);
 myApp.GetInput();
     
 if (myInput.IsKeyDown(sf::Key::Return))
 {
    proceed = true;
 }
   }
}
Whether you think you can or you can't, you're right.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Evasive Bug... Could Be Anything
« Reply #11 on: December 15, 2010, 12:01:58 pm »
Still crashes? Where is the sound stuff??? :lol:
Laurent Gomila - SFML developer

Noegddgeon

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
    • Soundcloud
Evasive Bug... Could Be Anything
« Reply #12 on: December 15, 2010, 12:15:53 pm »
:shock:

This is weird stuff, man.  :cry:  I don't recall ever having changed something, but I'll assume I did without recognizing it. The program did run before I added the sound features though, I can promise that. And when I added the sound features, I don't recall tweaking much in the program other than what I needed just to get the sound to work :p Perhaps my mind and fingers strayed on the keyboard while contemplating how wonderful my Pong remake would be with sound? ;]

Now that it's been narrowed down, it's all within the screen() function still. I would love to know what is causing this problem, as I feel it's one of those incidences that prove to be great learning moments.

Thank you for all your help Laurent. By the way, is it pronounced "LORE-int" or "Lore-ONNN"?
Whether you think you can or you can't, you're right.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Evasive Bug... Could Be Anything
« Reply #13 on: December 15, 2010, 12:51:37 pm »
You can probably remove additionnal stuff. For example, the view, some sprites, etc.

Quote
Thank you for all your help Laurent. By the way, is it pronounced "LORE-int" or "Lore-ONNN"?

It's more "lor-ant", like in "croissant" (same "r" and same "ant"). This is for the french way of saying it. But I'm fine with "low-rent" for english-speaking people, it's easier to prenounce ;)
Laurent Gomila - SFML developer

Noegddgeon

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
    • Soundcloud
Evasive Bug... Could Be Anything
« Reply #14 on: December 16, 2010, 01:13:50 am »
Lah-RAUN! (with emphasis ;]) :D

haha, I tried to shrink it down even further, still with the same results and still saying there's something causing an issue with sf::RenderTarget::Clear. I know I'm calling the App.Clear() function in there, but I tried removing all the instances of them and recompiling but it still showed the same error :p

Code: [Select]

/* This game is basically a simple remake of Pong. It will be for two players. */

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>

void screen(sf::RenderWindow&, sf::Sprite&);

// Render window declaration
sf::RenderWindow App(sf::VideoMode(800, 600), "T4 Pong");

// Event Receiver
sf::Event Event;

// Input Receiver
const sf::Input& Input = App.GetInput();

// Images for screens
sf::Image titleImage;

// Sprites for screens
sf::Sprite titleSprite;

int main()
{
   // Game start variable
   bool gameStart = true;
   
   titleImage.LoadFromFile("pong_title.png");
   
   // Set smoothness off
   titleImage.SetSmooth(false);

   // Initialize sprites
   titleSprite.SetImage(titleImage);
   titleSprite.SetPosition(0,0);
   
   // Start initialization / escape sequences (events)
   while (App.IsOpened())
   {
      while (App.GetEvent(Event))
 {
    if (Event.Type == sf::Event::Closed)
   App.Close();

if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
   App.Close();
 }
 
 // Opening screen
 if (gameStart)
 {
    App.Clear();
    screen(App, titleSprite);
gameStart = false;
 }
 
 // Display final image
 App.Display();
 
   } // End loop
   
   return EXIT_SUCCESS;
}

// Functions and their declarations

// Function to display a static screen that waits for the user to press return (or enter)
void screen(sf::RenderWindow &myApp, sf::Sprite &screenshot)
{
   bool proceed = false;
   sf::Event myEvent;
   
   const sf::Input& myInput = App.GetInput();
   
   while (!proceed)
   {
      myApp.Clear();
      myApp.Draw(screenshot);
      myApp.Display();
 myApp.GetEvent(myEvent);
 myApp.GetInput();
     
 if (myInput.IsKeyDown(sf::Key::Return))
 {
    proceed = true;
 }
   }
}


Thank you much as always, Mr. Laurent! Hope this is skimpy enough! :p
Whether you think you can or you can't, you're right.

 

anything