Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with Distance text accessing invalid memory #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

netpoetica
Copy link

@PolyMarsDev this fixes the issue you describe in your video (which I was able to recreate on my local). It wasn't actually any issue with SDL_TTF lib, but with the fact that you were returning a ptr to your local variable which was allocated on the stack and not on the heap. Of course it was very strange that high score worked fine but distance didn't, but such is the way with memory in C/C++.

I also removed some stuff that triggered compiler warnings! Thanks for putting this example together :) I agree with people that the controls are borderline impossible (jumping while still pushing with your cursor without killing your guy is rough), but I still would like to see you finish this game someday! Cheers and thanks for the video!

Fix score functions returning local variables that become inaccessible
Remove unused variables triggering compiler warnings
Add .gitignore to keep emscripten-generated files out
Add emscripten compile to Makefile

Fix score functions returning local variables that become inaccessible
Remove unused variables triggering compiler warnings
Add .gitignore to keep emscripten-generated files out
Add emscripten compile to Makefile
@netpoetica
Copy link
Author

Oh and FWIW, this is just speculation, but I suspect the reason this issue only became pronounced in the browser is because of the way Emscripten uses heap/stack memory in the WASM world. I suspect in C++ executable land, this memory doesn't get garbage collected and you just had a memory leak, whereas in WASM, this unreferenced memory was getting garbage collected and pointers were becoming nullptr.

@mandar1jn
Copy link

Thanks? This also fixes issues on ARM processors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants