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; };
Kenny
this works, the other doesn't
Bro, if u can use debugger and try to see what is failing
Daniele
Are you sure the index is correct in the second case?
yes, I've tried manually setting it to 0 and even removing it. as I said the vector is made of one item of index 0 and .begin() should delete it
Daniele
Bro, if u can use debugger and try to see what is failing
debugger doesn't seem to show anything particular, it executes the method and does nothing else
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
the method .erase() gets called
Daniele
but doesn't do anything
Vlad
the method .erase() gets called
is your index within 0..size-1 range?
Daniele
is your index within 0..size-1 range?
index is hardcoded to 0 for the ship
Daniele
which meanse erase has ship.begin() for argument
Vlad
index is hardcoded to 0 for the ship
And your vector isn't empty?
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
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
Also calling erase on an empty one is ub
Daniele
So you have a pointer to it doncha?
I'm not really using pointers, I'm using vector with operator[]
Daniele
Daniele
like this
Vlad
Daniele
asteroids just disappear, the ship doesn't though
Arseny
🙈
Kenny
Did you overaloading the operator [ ] ?
Vlad
what
It's UB
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
Kenny
It's UB
What is UB btw?
Daniele
and i'm rendering it regardless lol
Arseny
Looks like shooting yourself in the foot
Daniele
What is UB btw?
undefined behaviour
Daniele
anyways it looks like I should be more careful with vectors
Vlad
maybe I got what happens, but I still don't understand why it doesn't disappear like the asteroids
Cuz if you freed the memory it doesn't mean that there are not leftovers on that pointer.
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
anyways it looks like I should be more careful with vectors
Just don't access empty one via operator[] lmao
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
Because you're trying to erase the same object on which you're calling hit
Even if it would not be so - it looks just as a erroneous design.
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
What I would do is to a have a boolean whether the object is empty
yes that's what I am implementing right now
Vlad
Instead of using for each loop
Vlad
yes
consider this: for(auto& a : vec) { // do stuff a.render(); }
Vlad
what does this do?
It's for each loop
Vlad
with a being an element of array
Vlad
And all the bounds are checked
olli
struct N { constexpr N() {} N(N const&) = delete; }; template <typename T> consteval void assert_copyable() { T t; T t2 = t; } using check = decltype(assert_copyable<N>());
I think it was illegal at some point, to increase consistency they decided to align consteval more with constexpr and not evaluate in this context. P1073R3: Immediate functions P1937R0: Fixing inconsistencies between constexpr and consteval functions
Anonymous
How to install tarbo c in laptop
DARK WEB
Thank you
olli
How to install tarbo c in laptop
#rules you shall not and instead use something modern,
Anonymous
Hello friends
Anonymous
Finee
Anonymous
I think it was illegal at some point, to increase consistency they decided to align consteval more with constexpr and not evaluate in this context. P1073R3: Immediate functions P1937R0: Fixing inconsistencies between constexpr and consteval functions
Yeeees My quiz was outdated When I was writing it I thought that it should be a compile-time error But while researching the problem I found this proposal and now it's legal
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
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
gdb
Not so.
0x0007438055
gdb
Bt little bit experience