Daniele
class Ship {
public:
static const int TEXTURE_WIDTH = 32;
static const int TEXTURE_HEIGHT = 32;
static const int VELOCITY = 640;
//Constructor and deconstructor
Ship();
//Player event handle
void handleEvent(SDL_Event& event);
//ship core
void move(float timeStep);
void render();
bool hit(std::vector<Ship>& ship, int index);
//Get Ship info
float getX();
float getY();
bool getGrace();
void setGrace();
void unsetGrace();
int getEnergy();
SDL_Rect getBB();
private:
float mShipX, mShipY;
float mSpeedX, mSpeedY;
bool mGrace;
int mEnergy;
SDL_Rect mCollider;
};
Daniele
class Asteroid {
public:
static const int TEXTURE_WIDTH = 32;
static const int TEXTURE_HEIGHT = 32;
static const int VELOCITY = 640;
//Constructor and deconstructor
Asteroid();
//Asteroid core
void move(float timeStep);
void render();
void respawn();
void hit(std::vector<Asteroid>& astrd, int index);
//Get asteroid info
float getX();
float getY();
ASTEROID_STATUS getSize();
SDL_Rect getBB();
private:
float mAstX, mAstY;
float mSpeedX, mSpeedY;
ASTEROID_STATUS mSize;
SDL_Rect mCollider;
};
Arseny
Kenny
Look Index variable, and its value
Daniele
I'll try to see what happens to the asteroid element when it gets deleted
Vlad
I guess it's sloppy coding error. Your mEnergy must be greater than zero all the time.
Daniele
Daniele
the method .erase() gets called
Daniele
but doesn't do anything
Daniele
which meanse erase has ship.begin() for argument
Vlad
Daniele
no, the vector only has one item
Daniele
actually
Kenny
So weird mmmm
Daniele
the vector after the first call becomes made up of 1000 items
Vlad
Daniele
first erase: the vector becomes empty but I can still control the ship; second erase: vector fills 1000 items with garbage data (and the first item still works)
Vlad
Vlad
Also calling erase on an empty one is ub
Daniele
Daniele
like this
Vlad
Daniele
asteroids just disappear, the ship doesn't though
Arseny
Vlad
Kenny
Did you overaloading the operator [ ] ?
Daniele
Vlad
Daniele
maybe I got what happens, but I still don't understand why it doesn't disappear like the asteroids
Daniele
well maybe i am stupid
Daniele
and i'm rendering it regardless lol
Arseny
Looks like shooting yourself in the foot
Daniele
Daniele
anyways it looks like I should be more careful with vectors
Vlad
Vlad
It's use after free basically
Arseny
why?
Because you're trying to erase the same object on which you're calling hit
Vlad
Daniele
for some reason I was thinking it wrong, like the program was making disappear. in reality I had a for cycle at the rendering section that wouldn't render if the vector was empty, likewise all other operation with the asteroid vectors had this check, while the ship didn't have one and I didn't realize.
Arseny
Vlad
What I would do is to a have a boolean whether the object is empty
Vlad
And if it is, than I won't update it/render it
Daniele
Vlad
Daniele
Vlad
Instead of using for each loop
Vlad
yes
consider this:
for(auto& a : vec) {
// do stuff
a.render();
}
Daniele
Vlad
with a being an element of array
Vlad
And all the bounds are checked
Anonymous
How to install tarbo c in laptop
DARK WEB
Thank you
Anonymous
Hello friends
Hello
Anonymous
Finee
Anonymous
CappedCrusader
Any good and easy to make project Ideas ??
Asdew
A kernel?
Roxifλsz 🇱🇹
>easy to make
>Kernel
Hmmm
Asdew
A simple kernel is not that hard to program.
Roxifλsz 🇱🇹
Well it depends on how deep you want to go with your kernel, but still
CappedCrusader
@OxFFFFFFFF hey there is a person with username "$" you have restricted him for writing here , could you please check that , and unrestrict him
Deleted Account
klimi
Anonymous
Any site where I can check the posix thread scheduling attribute related program practice?
Got only 2 program on IBM site in google
Anonymous
In c programming
su
gdb
0x0007438055
0x0007438055
gdb
Bt little bit experience