19 votes

Is something wrong with getType(object)?

The function detectCollision() returns NULL if there's no collision happened. You have to check whether your object is equal to NULL before you pass it to getType().
user avatar
  • 17.4k
12 votes
Accepted

getType() causing a seg fault when called on object as returned by detectcollision?

Pay close attention to what detectCollision() returns. What happens when there is no collision? (which will be most of the time). Are you handling that? It appears you are not, hence your segfault....
user avatar
  • 18.4k
11 votes
Accepted

Why does the ball glide along the paddle whenever it touches its sides?

What really causes this problem is that the ball hits one of the paddle's sides (or corners) and the bottom of the ball actually passes the top of the paddle. let's call the distance between the ...
user avatar
  • 17.4k
8 votes
Accepted

Collision of ball with other objects

The Idea Behind Collision: There's a function namely detectCollision() that's already written for you and ready to use. This function, when it's called, checks whether any of the sides of the ball ...
user avatar
  • 17.4k
8 votes
Accepted

Segmentation fault when trying to detect collisions in breakout

You may also have to make sure it's not null before you try to pass it into getType(). detectCollision will return null when there are no collisions.
user avatar
6 votes

Bricks are not available to the detectCollision function

Your first assumption was not wrong. The bricks are not returned to the main function, so you need to find another way to refer to them while the game is running. The bricks do definitely exist as ...
user avatar
  • 2,625
6 votes
Accepted

Segmentation Fault in Pset4 when detecting is brick is hit

You have to check whether object is equal to NULL before passing it to getType(). detectCollision() might return NULL in case there's no collision happened.
user avatar
  • 17.4k
6 votes
Accepted

Bricks aren't disappearing when hit with the ball

The function removeGWindow() receives a GWindow and a GObject not a GWindow and a string. You should be removing object when it's a GRect other than the paddle!
user avatar
  • 17.4k
6 votes

Why breakout does not restart after placing a new ball and clicking?

Instead of removing the ball and paddle from the window with removeGWindow, why not use another command (hint, hint) to change their positions back to where they began? Then you can allow normal play ...
user avatar
5 votes
Accepted

Why Do I Get a Segmentation Fault When Trying to Move the Paddle?

You get a segmentation fault when you touch locations in memory that you shouldn't! Make sure your initPaddle() function doesn't return NULL and returns the paddle you created within it instead!
user avatar
  • 17.4k
5 votes
Accepted

Why is this code unable to bounce the ball

Converting the code to pseudo code might help to reveal the problem: loop while lives > 0 and bricks > 0 set velocity to -0.5 move the ball in the y axis by the velocity if the ...
user avatar
  • 2,625
5 votes
Accepted

Coloring the bricks in breakout

Yes. Usually there's a better approach to do something specially when you find yourself repeating code or checking every possible case manually to do something different in each situation. I prefer ...
user avatar
  • 17.4k
4 votes

in pset4 only 1 row of bricks appear even with nested loop

This is a great question because it illustrates a very common mistake. Here is an excerpt from your code: for (int i = 0; i < ROWS; i++) { x = 2; for (int j = 0; i < COLS; i++) { ...
user avatar
  • 2,625
4 votes

Segmentation fault (core dumped) in the updateScoreboard function of pset4

Thankfully I found where I have done a mistake! It's in the initScoreboard . I didn't add return scoreboard to be used in updateScoreboard because in the beginning of main there's GLabel label=...
user avatar
4 votes
Accepted

How to use strcmp correctly in PSET4? (Using it cause my whole program to stop)

You need to add if(object != NULL) before your if (object == paddle) Your program stops because of "Segmentation Fault". The Detect-Collision function returns a NULL if no object is detected. You ...
user avatar
  • 428
4 votes
Accepted

why doesn't getColor work?

It returns an int that represents a color. See http://www.programmingsimplified.com/c/graphics.h/colors for more info. Also google getColor for more explanation. You could use the actual color ...
user avatar
  • 64.2k
3 votes

Running breakout on Mac OS X

As such, the Stanford Portable Library is under a GNU license, which makes it legal for us (or in fact, me) to redistribute it to you, or anyone else, as stated by the license: /**********************...
user avatar
  • 1,146
3 votes
Accepted

How to Update the Scoreboard in Breakout?

there is an updateScoreboard() function already implemented. You just need to call it with the parameters specified.
user avatar
3 votes

Collision of ball with other objects

Here is a bit of psuedocode to help you define detectCollision: If object is not equal to NULL then check if: object == paddle, if it is, flip the y-velocity accordingly else if, object == GRect (...
user avatar
  • 483
3 votes

Breakout slows down just before finishing the game

Just for the record, I had the same problem of breakout getting "laggy" after running (in the appliance) for a few seconds. Staff's implementation would run properly, so it wasn't strictly a hardware (...
user avatar
  • 1,140
3 votes
Accepted

What is the correct `wget` URL for breakout (pset 3) for spring 2015?

The zip file you linked contains folders for breakout and find, as specified in the problem set. There does not appear to be any fifteen content. Note that find was moved to accompany breakout, as ...
user avatar
3 votes
Accepted

Breakout - bounce off brick- why do I need to check for object == NULL?

If you're following the distribution code, you're likely to have a variable named paddle that stores an instance of your paddle. If the ball collides with the paddle, detectCollision returns an ...
user avatar
  • 17.4k
3 votes
Accepted

Segmentation fault testing for detectCollision returning NULL

I was having a similar problem when I moved from: if (object == paddle) to: if (strcmp(getType(object), "GRect") == 0) After reading your question, I realized I was probably not handling NULL ...
user avatar
  • 166
3 votes
Accepted

In Breakout the ball latches itself to paddle and bricks occasionally

It sounds like you've hit a known issue with this program. Is this what's happening? The ball hits the side of the paddle or a brick and it starts bouncing inside the paddle or brick until it emerges ...
user avatar
  • 64.2k
3 votes

Breakout: paddle no longer moves after ball movement inserted

look at your 2nd while loop that moves the ball, think about when your code will exit that and move on to the part of the code that moves the paddle
user avatar
  • 1,415
3 votes

Pset3 - Multiple nested if statements

Not sure what you mean by "many" if statements, but most people will use two nested for loops to create the bricks - an inner for loop to create each row and an outer for loop to do multiple rows. ...
user avatar
  • 64.2k
3 votes
Accepted

Breakout ScoreBoard

My guess is that the score is being displayed slightly low and slightly right of center. This is because setLocation() will place the object based on the upper left corner of the object, not the ...
user avatar
  • 64.2k
3 votes
Accepted

Breakout program freezes when i make it wait for click to start.

the problem is obviously that you're not updating event. that is, you're getting the next event only once. if it doesn't happen to be a mouse click, the value of event never changes and your program ...
user avatar
  • 17.4k
2 votes

Collision of ball with other objects

On the main routine, you have a call to a function that detect collisions. The ball is the only moving object. What you need to do is checking if the ball "touches" an object or the walls. ...
user avatar
  • 1,156
2 votes

initBricks as a 2d array of labelled bricks

You don't really need to have an array to store bricks. Once you create and add a brick to the window, it stays there until you remove it using the function named removeGWindow() from the SPL library ...
user avatar
  • 17.4k

Only top scored, non community-wiki answers of a minimum length are eligible