Progrider

Programming discussion

Search

Searches topics and replies. Every word has to appear in the post.

10 posts found.

PostPosted
Help · post #5

Went with index + generation number, so a stale handle gets detected instead of pointing at the wrong enemy. Works well. Thanks, and ferrous, no.


by teo
Help · post #4

Fixes, in the order I'd try them: store an index or a handle in place of a pointer. std::deque if you only add at the ends, its references stay valid on push_back. Calling reserve() up front hides the bug until you exceed it.


by jf
Help · post #3

Say it louder.


by ferrous
Help · post #2

Yes. push_back reallocates when it runs out of capacity, and all your pointers point into the old buffer. It's the same reason Rust refuses the code in tomasz's thread, /progrider/t/AhtK41Hy5_6g, except here it compiles and you get to find …


by jf
Help · post #1

std::vector<Entity> entities; and the enemies keep an Entity* target. After some spawns, target points to garbage, and it crashes only sometimes. Valgrind says invalid read. Is it because vector moved?


by teo
Help · post #5

Yes, _physics_process runs at a fixed rate, and newer versions have physics interpolation you switch on in the project settings. Solved, thanks jf.


by teo
Help · post #4

Is this what Godot does with its physics tick?


by kettle
Help · post #3

Read the article. Jump heights are identical now. I'm clamping frame_time to 0.25s as well, otherwise dragging the window gives a spiral of updates.


by teo
Help · post #2

Variable dt makes the integration depend on the frame rate. Fixed step with an accumulator: accumulator += frame_time; while (accumulator >= STEP) { update(STEP); accumulator -= STEP; } render(accumulator / STEP); Pass the leftover fraction…


by jf
Help · post #1

Small 2D platformer in C++ with SDL. I multiply velocity by dt every frame. At steady 60 it's smooth. When it dips, the player stutters and jumps come out at a different height, which breaks some levels.


by teo
All times shown in UTC.