while (appletMainLoop()){ currentMs = SDL_GetTicks(); if(currentMs - lastFell > fallms){ bool hitground = tetroDown(tetroptr); lastFell = SDL_GetTicks(); if(hitground){ free(tetroptr); tetroptr = newTetro(tetroptr,3,3,1); Had to cut alot rendering and logic code to fit in a post but I think the relevant parts are these. Does anyone know why this crashes when a new tetromino is supposed to spawn? The first tetromino hits the bottom, can't move, and then the program crashes.
Use a debugger. I can't be arsed to read your tiny program but it's probably an out-of-bounds access or null dereference, which are extremely simple mistakes which debuggers are good at catching.
Grayson Anderson
It's nintendo switch homebrew, IDK how to use a debugger on one these unless I convert it to a linux program. Also it's not tiny it's just that I hit the 2000 character limit so had to take out the parts I think are irrelevant.
Andrew Brooks
I'd just like to interject for a moment. What you're referring to as Linux, is in fact, GNU/Linux, or as I've recently taken to calling it, GNU plus Linux. Linux is not an operating system unto itself, but rather another free component of a fully functioning GNU system made useful by the GNU corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX. Many computer users run a modified version of the GNU system every day, without realizing it. Through a peculiar turn of events, the version of GNU which is widely used today is often called "Linux", and many of its users are not aware that it is basically the GNU system, developed by the GNU Project. There really is a Linux, and these people are using it, but it is just a part of the system they use. Linux is the kernel: the program in the system that allocates the machine's resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. Linux is normally used in combination with the GNU operating system: the whole system is basically GNU with Linux added, or GNU/Linux. All the so-called "Linux" distributions are really distributions of GNU/Linux.
Jose Brown
kys memester
Connor Gomez
You're right, I meant to say GNU/linux. The normies brainwashed me and made misspeak. Here's some more code I couldn't fit but I don't think it matters. hidScanInput();
// hidKeysDown returns information about which buttons have been // just pressed in this frame compared to the previous one u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
switch(kDown){ case KEY_LSTICK_RIGHT: tetroptr->col++; break; case KEY_LSTICK_LEFT: tetroptr->col--; break; }
SDL_RenderClear(renderer); SDL_RenderCopy(renderer,bgtexture,NULL,NULL); for(int i =0; i
Daniel Edwards
wow that's some ugly coding
the newTetro() doesn't need to take the struct tetro* argument at all, it's used only as local variable would be. Also single letter global constants/enum names. Although don't see any bug there.
drawBlock() has semicolon at the end?
I don't see any access after free() though. I also don't see any bound checks in tetroDown() when it's already at the edge of field. My bet would be the block runs out of border and you write into some memory outside field.
William Green
Use pastebin, the code you posted is fucked. You are calling tetroDown from tetroDown.
Elijah Cook
>if(field[i+tetromino->potentialrow][j+tetromino->potentialcol] != 0) This is out of bounds array access.
Brody King
Good idea. pastebin.com/kA4MsW52 The name of the tetromino blocks are only 1 letter. Also I know that it doesn't need that arguement but I was trying weird stuff in hope it would stop crashing. If it was writing into some memory outside field would crash much faster I think? Oh you think so? It only moves by one and there is a layer of blocks at the bottom so I don't think it should be out of bounds in this specific testing build and after that it should create a new block. but I do think I should check and try to prevent out of bounds checking there.
Juan Hill
You said this happens when first block reaches the bottom, which is exactly when you'd check if it can move any further bottom and do an out of bounds array access.
Ryder Edwards
It takes like 30 seconds to crash and I think an out of bounds would crash immediately? I'll try returning true when ever the position is greater than field length can check first and see if that helps.
Luis Reed
I mean, if you don't even want to explain properly how the crash happens, I don't think I want to help you debug it.
Henry Hernandez
Imagine developing for platform you can't properly debug on and not isolating platform-dependent code. Sounds like hell.
Parker Walker
>The block falls to ground >No new block spawns >it stays there for about 30 seconds >crash I only missed the 30 seconds part sorry.
Aaron Martinez
Well, out of bounds read is not guaranteed to break the program. You're just reading memory in some other place. But if you venture too far and read from some location in virtual memory that is marked in any way as not readable, you are going to get a segmentation fault, so I think it is possible for a program to behave this way.
Elijah Young
Now that I think about it I can probably get rid of the switch code and make a linux version more quickly then It's been taking me to fix this bug. hopefully gdb knows what's wrong.
Robert Gomez
I added code that should prevent out of bounds checking. if(tetromino->potentialrow > 15){ cantmove = true; } if(!cantmove){ for(int i = 0; ipotentialcol] != 0){ cantmove = true; break; } } } } } Same exact problem though. I didn't think that was what's wrong in this instance.
Sebastian Harris
I strongly recommend clang sanitizers or valgrind.
Juan Peterson
>appletMainLoop() Doing switch homebrew dev? I can hook you up with a quick thing I wrote some time ago that uses SDL if you want to.
Joseph Gonzalez
No thanks, I just want someone to tell me what's wrong with my code
Daniel Lopez
When a blockshape hits the bottom, you're writing outside the array bounds
Levi Nelson
sure it be interesting to see other people's stuff. you aren't me, stop impersonating me. right I should try to stop it from writing out of bounds too. I forgot out about that.
Ryan Sullivan
pastebin.com/7Y9psSgz Basically I'm circling though pictures of mario dabbing while playing party rock. Probably won't help you pinpoint your bug though.
Julian Barnes
Don’t want to make a new thread. So here is my problem. I ‘m young and I am really interested in programming, but I don’t know which language should I pick. And I really can’t understand what I want to do in programming. Are there any ways to choose the direction? Maybe there are some special tests or some other things?
Jacob Gonzalez
Added new code that should prevent that. No dice. bool tetroDown(struct tetro * tetromino){ tetromino->potentialrow = tetromino->row+1; tetromino->potentialcol = tetromino->col; bool cantmove = false; if(tetromino->potentialrow > 15){ cantmove = true; } if(!cantmove){ for(int i = 0; ipotentialcol] != 0){ cantmove = true; break; } } } } } if(cantmove){ for(int i = 0; icol < 9){ field[i+tetromino->row][j+tetromino->col] = blockshape[i][j]; } } } } return true; } else{ tetromino->row = tetromino->potentialrow; tetromino->col = tetromino->potentialcol; return false; } } At least I don't feel a brainlet anymore since everyone else can't fix it either. The linux port is crashing as well but much quicker for some reason. When I ran it in gdb it froze, my program is so bad it broke the debugger.
Ayden Sanchez
Learn C.
John Torres
Don't learn C, it feels impossible write code that doesn't seg fault. Learn Go or python instead and only use this 70s language when you absolutely must.
Carson Miller
Right here. -Wshadow would have saved you hours of time and looking like an idiot on the internet.
If you're going to program in C: >Use a debugger >Use sanitizers >Turn on all warnings >Don't give anything but local variables 1-2 letter names
Getting rid of that line doesn't do anything though? That line didn't even exist until recently.
Joseph Foster
I have great faith in your ability to fuck up dozens of things like this. Turn on your warnings, fix them all, then run it in a debugger with AddressSanitizer and UBSanitizer turned on and fix all the problems that finds. Then come back and post it when you're not just wasting people's time trying to figure out which of your 50 bugs is crashing it.
Leo Rodriguez
I don't know how to do that. Can't you just tell me my bugs? I even removed the irrelevant parts of the code.
Anthony Jenkins
>I don't know how to do that. So fucking learn dipshit. I assume you're doing this to learn, not because you think the world needs another shitty tetris clone .
Oliver Mitchell
trash ide
Nolan Thomas
gdb has shown me that for(int i = 0; icol < 9){ // field[i+tetromino->row][j+tetromino->col] = blockshape[i][j]; // } // } // } // } is the problem but I don't really know how to fix it lol. Removing that part makes it not crash but it also doesn't write the old block to the array. Stop impersonating me. Wasn't me. Also I actually had a cool idea for a 2 player mode on nintendo switch. It is mostly for learning though.