Well i'm currently trying to my own sort of framework so that i can make the platformer (i haven't yet watched the tutorials, i want to try by myself first). I did a bit of googling on collisions as i found that bounding box collisions on every entity is very slow and wanted to speed it up abit. I am using a method called spatial partitioning (basically sets up a grid on the screen and only does hit detection on the objects located in the same grid cells as to minimize hit tests needed). I have set up a vector of pointers for each entity to record each cell they are contained in, to set the array i use nested for loops to iterate through the cells in which it is located, get pointers to them and store it in the array. However the problem is that the width/height values of the entity seem to contain garbage values, i followed the debugger through the constructing of the objects and am unsure as to why it contains these values as they seem to set fine when they are constructed. So i get a "vector is out of subscript range" error as it is trying to put a ridiculous amount of elements into it. Any help would be appreciated
Note: i am aware the loop in the game will create new sprites every frame without deleting them, it is just a test to make sure the spatial partitioning is working.
Garbage Value?
Re: Garbage Value?
heh, so far i've seen 3 errors
1st one causing crash is
2nd error causing crash
and 3rd error which would cause a crash on exit (one i find funny )
1st one causing crash is
Code: Select all
Game.h
Sprite mouseTile; <-- this one should be declared
EmbedSprite bricktile; <-- after this one
Code: Select all
DisplayObject.cpp
const int cellXEnd = floor(x + (width / colMap.getCellSize())); // do you
const int cellYEnd = floor(y + (height / colMap.getCellSize())); // intend for this?
const int cellXEnd = floor((x + width) / colMap.getCellSize()); // or do you
const int cellYEnd = floor((y + height) / colMap.getCellSize()); // intend for this?
Code: Select all
CollisionMap.h
CollisionCell* newCell = new CollisionCell(i * cellSize, j * cellSize, cellSize);
cells[i].push_back(newCell);
delete newCell; <-- haha, getting rid of upon creating
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
-
- Posts: 20
- Joined: April 17th, 2014, 4:13 am
Re: Garbage Value?
Haha i also laughed at the last one, i picked it up just after i posted this haha.
But is the first one really an error? because i constructed them in the right order so i didn't think it would make a difference.
and for the 2nd error i meant the 2nd one haha, now i see why i was getting weird values
Thanks for the help
But is the first one really an error? because i constructed them in the right order so i didn't think it would make a difference.
and for the 2nd error i meant the 2nd one haha, now i see why i was getting weird values
Thanks for the help
Re: Garbage Value?
hehe, yea, the order in which variables are declared in the class declaration is what matters, not really the order they're initialized in the initializer list :p
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Re: Garbage Value?
Yeah, that one can get you sometimes. Probably one of the biggest arguments against using initializer lists... still, I love me some init lists.
Chili
-
- Posts: 20
- Joined: April 17th, 2014, 4:13 am
Re: Garbage Value?
Ah well i didn't know that, thanks for the help guys