Skip to content

Commit

Permalink
fixed out of bounds errors
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelaziz-mahdy committed Nov 29, 2023
1 parent ddf80b5 commit 41e7bda
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/controllers/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class GridController {
}

void updateBlockState(int row, int column) {
if(rows<0 || columns<0 || row>=rows || column>=columns){
print("out of bounds");
return;
}
if (isChangingWallStateAllowed) {
final currentBlockState = matrix[row][column].value;
BlockState newBlockState = currentBlockState;
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class _GridState extends State<Grid> {
int justUpdatedCol = -1;
void _handlePointerMove(
PointerEvent details, double blockWidth, double blockHeight) {

int row = (details.localPosition.dy / blockHeight).floor();
int col = (details.localPosition.dx / blockWidth).floor();
if (row == justUpdatedRow && col == justUpdatedCol) {
Expand Down

0 comments on commit 41e7bda

Please sign in to comment.