Garbage Value?

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
MagicFlyingGoat
Posts: 20
Joined: April 17th, 2014, 4:13 am

Garbage Value?

Post by MagicFlyingGoat » July 26th, 2014, 1:23 pm

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.
PROBLEM SADNESS.zip
(185.78 KiB) Downloaded 170 times

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Garbage Value?

Post by LuisR14 » July 26th, 2014, 11:34 pm

heh, so far i've seen 3 errors
1st one causing crash is

Code: Select all

Game.h
	Sprite mouseTile;   <-- this one should be declared
	
	EmbedSprite bricktile;   <-- after this one
2nd error causing crash

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?
and 3rd error which would cause a crash on exit (one i find funny :lol:)

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 :mrgreen: --

MagicFlyingGoat
Posts: 20
Joined: April 17th, 2014, 4:13 am

Re: Garbage Value?

Post by MagicFlyingGoat » July 27th, 2014, 12:12 am

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 :D

Thanks for the help :D

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Garbage Value?

Post by LuisR14 » July 27th, 2014, 2:29 am

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 :mrgreen: --

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Garbage Value?

Post by chili » July 27th, 2014, 4:42 am

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

MagicFlyingGoat
Posts: 20
Joined: April 17th, 2014, 4:13 am

Re: Garbage Value?

Post by MagicFlyingGoat » July 27th, 2014, 5:22 am

Ah well i didn't know that, thanks for the help guys :D

Post Reply