gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > My program hates me for using structs!!!!!!!

#10822 - DiscoStew - Tue Sep 16, 2003 10:43 pm

This is one of the weirdest problems I have ever faced.
I started working with a single sprite (just to see how it works along with animation), and my program ran just fine.
Now I've added structs so that my sprites have unique data (such as x/y coordinates, flip flags, etc.). My one sprite still show like usual, but now there's an 8x8 block showing a part of my sprite at the top of the screen, above my 1 sprite. Using VBA, I found that this one block is actually the 2nd sprite. But that can't be! I hadn't made any references to any other sprites other than the first one! After some more checking, I found that when I move some of the substructures from within my main structure for my sprites, my sprite does funky stuff. So from all that I have gathered together, it seems that my defined sprite structure is affecting the sprite attribute data (that is used to copy to the OAM), almost like these structures are overlapping each other in memory. Please help!
_________________
DS - It's all about DiscoStew

#10823 - sajiimori - Tue Sep 16, 2003 11:32 pm

Perhaps you could post a minimal bit of compilable code that has the problem.

#10824 - DiscoStew - Tue Sep 16, 2003 11:37 pm

Who feels like a freakin' idiot? I do!!!

One thing you need to know (referring to myself) about moving from one programming language to another is to get your languages straight and to not take habits across languages. In my case, declaring an array in VB 6.0 is not the same in C.
Sure, I had my structure as I wanted it to be, but declaring Sprites[0] does not mean the array has one index in C (it does however in VB).
The fact that no warning or error during compiling is probably what threw me off. I guess since it had no actual memory address to start from, it decided to start from some random place, which coincidentally was where the sprite attributes were.
Well, it's now fixed, for the time being.

For all those people declaring arrays, make sure to declare it with an index of the exact count, not one less.
_________________
DS - It's all about DiscoStew