Coder Social home page Coder Social logo

tetris's Issues

Premature gameover on line clear

I'm going to try out issues for bug resolution just to get the hang of it.

So far, this seems to happen most with I_PIECE, but idk if that's a necessary part of it.

game.log from a game where this happened:

Global piece locations are: {[24, 7] [25, 7] [26, 7] [27, 7] }
Gravity tick activated systime=200069, last tick=16: piece moved down
display_board()
display_board()
display_board()
display_board()
display_board()
display_board()
display_board()
display_board()
Global piece locations are: {[25, 7] [26, 7] [27, 7] [28, 7] }
Gravity tick activated systime=400097, last tick=200069: piece moved down
display_board()
display_board()
display_board()
display_board()
display_board()
display_board()
display_board()
display_board()
Global piece locations are: {[26, 7] [27, 7] [28, 7] [29, 7] }
Gravity tick activated: move down failed
Piece stopped falling at loc row=26, col=7
check_and_clear: checking row 26
check_and_clear: checking row 27
check_and_clear: checking row 28
check_and_clear: checking row 29
smallest value in array {26, 28, 29, } is 26!
clearing 3 rows with top_row=26
Score updated for 3 lines cleared. Score = 4300, Level = 3     Lines cleared since last level=2
Global piece locations are: {[1, 9] [2, 8] [2, 9] [3, 8] }

Gravity tick activated: move down failed

Piece stopped falling at loc row=1, col=8
check_and_clear: checking row 1
check_and_clear: checking row 2
check_and_clear: checking row 2
check_and_clear: checking row 3
smallest value in array {2, 2, } is 2!
clearing 2 rows with top_row=2
Score updated for 2 lines cleared. Score = 5200, Level = 3     Lines cleared since last level=4
game over detected, returning false from tg_tick
Deallocating tetris game

The first sign of a problem is that "Gravity tick activated" line - for some reason it thinks it can't move the piece down when it's at the top of the board, and that causes the crash.

That print statement is in check_do_piece_gravity(), but the source of the problem has to be at/near check_valid_move(tg, T_DOWN).

Minor memory leak in tetris.c

I'm testing out using issues to track bugs as I fix them. This is another one of those

Running test_tetris through valgrind, the result is:

$ valgrind --track-origins=yes ./build/test_tetris
==341505== Memcheck, a memory error detector                                                                                                                
==341505== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.                                                                                  
==341505== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info                                                                               
==341505== Command: ./build/test_tetris                                                                                                                     
==341505==                                                                                                                                                  
==== RUNNING UNIT TESTS ON TETRIS =====                             
[path]/tetrisgame/test/suite_1.c:476:test_checkValidMove:PASS                                                     
[path]/tetrisgame/test/suite_1.c:477:test_T_testPieceRotate:PASS                                                  
[path]/tetrisgame/test/suite_1.c:478:test_clearRows:PASS                                                          
[path]/tetrisgame/test/suite_1.c:479:test_checkSpawnNewPiece:PASS                                                 
[path]/tetrisgame/test/suite_1.c:482:test_arr_helpers:PASS                                                        
Config loaded from ./test/files/gamestate-full-row-not-detected.ini!
==341505== Conditional jump or move depends on uninitialised value(s)
==341505==    at 0x10DEA2: val_in_arr (tetris.c:646)          
==341505==    by 0x10DBDF: check_and_clear_rows (tetris.c:527)                
==341505==    by 0x10A9E6: test_clearRowsDumpedGame_1 (suite_1.c:269)                                                                                       
==341505==    by 0x110F71: UnityDefaultTestRun (unity.c:2202)      
==341505==    by 0x10B5E2: main (suite_1.c:483)                                                                                                             
==341505==  Uninitialised value was created by a stack allocation
==341505==    at 0x10DB2F: check_and_clear_rows (tetris.c:502)
==341505==                                                                                                                                                  
[path]/tetrisgame/test/suite_1.c:483:test_clearRowsDumpedGame_1:PASS                                              
Config loaded from ./test/files/gamestate-J-lined-up-dbl-clear.ini!
==341505== Conditional jump or move depends on uninitialised value(s)
==341505==    at 0x10DEA2: val_in_arr (tetris.c:646)             
==341505==    by 0x10DBDF: check_and_clear_rows (tetris.c:527)
==341505==    by 0x10DDFC: check_and_spawn_new_piece (tetris.c:609)           
==341505==    by 0x10AD27: test_clearRowsDumpedGame_2 (suite_1.c:325)                                                                                       
==341505==    by 0x110F71: UnityDefaultTestRun (unity.c:2202)                 
==341505==    by 0x10B600: main (suite_1.c:484)                               
==341505==  Uninitialised value was created by a stack allocation             
==341505==    at 0x10DB2F: check_and_clear_rows (tetris.c:502)                
==341505==                                                                    
[path]/tetrisgame/test/suite_1.c:484:test_clearRowsDumpedGame_2:PASS                                              
                                                                              
-----------------------                                                                                                                                     
7 Tests 0 Failures 0 Ignored                                                  
OK                                   
==341505==                                                                    
==341505== HEAP SUMMARY:                                                                                                                                    
==341505==     in use at exit: 36 bytes in 2 blocks
==341505==   total heap usage: 14 allocs, 12 frees, 17,756 bytes allocated
==341505==                                                                    
==341505== LEAK SUMMARY:                                                      
==341505==    definitely lost: 36 bytes in 2 blocks                           
==341505==    indirectly lost: 0 bytes in 0 blocks                    
==341505==      possibly lost: 0 bytes in 0 blocks                       
==341505==    still reachable: 0 bytes in 0 blocks                                                                                                          
==341505==         suppressed: 0 bytes in 0 blocks
==341505== Rerun with --leak-check=full to see details of leaked memory       
==341505==                                                                                                                                                  
==341505== For lists of detected and suppressed errors, rerun with: -s
==341505== ERROR SUMMARY: 3 errors from 2 contexts (suppressed: 0 from 0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.