Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5929563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:26:17+00:00 2026-05-22T14:26:17+00:00

My friend and I have made a tetris-like game in Java and it works

  • 0

My friend and I have made a tetris-like game in Java and it works fine for a while and then suddenly bugs out at around the same number of total pieces every time. For example, it might bug out at 42 pieces one time, 46 the next, and 44 the time after that.

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][2][2][ ][ ][ ][ ][ ][ ][7]
[ ][2][2][2][3][3][ ][4][ ][7]
[2][2][1][3][3][1][ ][4][ ][7]

The above is an example of what it looks like right before the bug happens. Don’t try to read into the above sample too much as the bug is not dependent on piece positions, etc.

Here is what the grid looks like right after the bug occurs…

[ ][ ][ ][2][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][2][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][2][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][2][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][2][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][2][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][2][ ][ ][ ][ ][ ][ ]
[ ][2][2][ ][ ][ ][ ][ ][ ][7]
[ ][2][2][2][3][3][ ][4][ ][7]
[2][2][1][3][3][1][ ][4][ ][7]

Notice the twos going all the way up to the top of the grid? That is what is happening.

Here’s where things get interesting. We have limited it down to a specific function and a specific line of code.

grid[x+legend[piece.type].fetch(i, 0, piece.rotate)]
    [y+legend[piece.type].fetch(i, 1, piece.rotate)]
    .type = piece.type+1;

The above line of code is the exact line of code believed to be causing the problem. The problem is that there is nothing wrong with that line of code. I’ve been debugging the whole program for about a week and I have it log the grid after every single change.

The difference between the two grids above was one call to that line. It should not be possible for it to have assigned all the other cells in the grid. The debug log said the variables were:

i: 0
legend[piece.type].block.length: 4
legend[piece.type].fetch(i, 0, piece.rotate): 0
legend[piece.type].fetch(i, 1, piece.rotate): 0
piece.type: 1
piece.rotate: 3
x: 3
y: 6

Those were the variables that influenced the second grid above. The buggy line of code would have read:

grid[3+0][6+0].type = 1+1;

Is it possible that we uncovered a bug in Java itself? I’ve spent hours debugging this code and I’ve never had a bug I couldn’t find (I usually code in python, though… Java is fairly new to me)

Also, it seems that the bug is influenced by the size of the grid. If I set the height of the grid to a lower number, it takes less pieces to cause the bug. On the same token, it requires more pieces if I make a taller grid.

Hopefully the Java experts out there can help shed some light on the situation.

p.s. I’m programming in Eclipse on a Mac using JRE JVM 1.6. I also tried JRE JVM 1.4 and the same thing happens.

Additional info:

private Grid grid[][] = new Grid[dimx][dimy];

the above code is when the grid is created. Grid is a class:

public class Grid {
    int type;

    public Grid(int type) {
    }
}

Here is part of the extensive debug log code… This is the function that prints the text-based grid.

public void printGrid(int line) {
    System.out.print("\n\n\n"+line+":\n");
    for (int y = 0;y < grid[0].length;y++) {
        for (int x = 0;x < grid.length;x++) {
            if (grid[x][y].type == 0) {
                System.out.print("[ ]");
            } else {
                System.out.print("["+grid[x][y].type+"]");
            }

        }
        System.out.println();
    }
    System.out.println("\n\n");
}

The variable ‘line’ is not important and merely tells us what line number the function printGrid() was called from.

Let me know if you guys need any more information.

More Additional Info:

Here are all the files for this program.

  • Legend.java:
    http://pastebin.com/mWL7wACW
  • Listener.java:
    http://pastebin.com/8A2BgicD
  • TetrisFrame.java:
    http://pastebin.com/1HKgc1uS (90% of the code is here)
  • Grid.java:
    http://pastebin.com/6HgKZsaF
  • Tetris.java:
    http://pastebin.com/kHdnvHyT
  • Piece.java:
    http://pastebin.com/k5PZpCzd

Oh, and here is an excerpt from a debug log to give you more info.

http://pastebin.com/9VKhF8CR

It includes placing a piece successfully (the last piece placed before the bug) and then it shows the bug happening. All the variables for the function are printed and none appear out of place. The bug happens to any piece being placed at any spot on the grid. The grid was printed after each call to the line I talked about above. Let me know if you guys need any more info. I want this bug squashed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:26:17+00:00Added an answer on May 22, 2026 at 2:26 pm

    From the description of your problem, it appears as though grid[0], grid[1] through grid[6] are all references to the same row array (but grid[7] and beyond are references to different arrays). This would cause the symptom you describe, where changing a single element causes it to appear to change in all those rows.

    Try:

    System.err.println(grid[0] == grid[1]);
    

    and see whether you get true or false. You’ll probably get true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a java chat server & client, that works fine. I made a
I have a Java Swing project which works fine on both Windows and Ubuntu.
So I have made a simple site for a friend using codeigniter and grocery
hi I have a scenario like this I made a chat program where a
My friend said he thinks i may have made a mistake in my programme
I have made a database structure where users can make friend connection between them
I have made a small java swing application that I want to share with
I have made an app for iPad and I would like to send this
In C++, I have often made a unit test class a friend of the
I'm writing a web application (PHP) for my friend and have decided to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.