| Summary: | exception when using SDL_FreeSurface | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Hugh McLenaghan <hughmcl> |
| Component: | *don't know* | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED INVALID | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | hughmcl, sylvain.becker |
| Version: | 2.0.10 | ||
| Hardware: | x86 | ||
| OS: | Windows 10 | ||
| Attachments: |
example code
modified version for linux buildmenu screenshot |
||
Strange, I bet the malloc are done correctly. Can you provide a test-case ? You can also both update SDL2 and SDL2_ttf. I've got the latest SDL & SDL_ttf libraries. It's very possible I'm doing something wrong too. What I can do if you're interested is give you a copy of my source code (i've got it cut down to somewhat minimal, and it's still showing the bug. I've got my libraries in D:\SDL2\SDL2\ i know that if i take out the SDL_FreeSurface command, it will run, but after about 5-10 minutes, it stops with an out of memory error, so I know the memory is being assigned and used. Just for some reason i'm not able to free it. I'm using Visual Studio 2019 to compile. http : // www.mclenaghan.com/HughSDL2.zip If you don't feel comfortable downloading, then let me know what you'd like me to do for troubleshooting. I'm not a C++, Windows, or SDL expert, so it is possible I've not done something right. I can't download it, so please attach it. Hope your code is quite reduced. Maybe you can also check for invalid read/write before, with visual studio. Created attachment 4250 [details]
example code
Code attached. total code size is only about 14K. Created attachment 4251 [details]
modified version for linux
Hi, I quickly looked but I have no Window version updated.
So I modified it to run on linux (see the files attached, remove the build menu, should be minor),
and it worked well, without invalid memory r/w.
So. Can you test it and see if you still have the issue with this version ?
Maybe I removed unintentionally the issue ..., or maybe the issue is with the window menu set up.
Created attachment 4252 [details]
buildmenu screenshot
It didn't appear to help removing the buildmenu call. Screenshot attached of the run. So this still crashes with my files. Whereas, on linux it runs fine. I'd say: - I believe this has nothing to do with SDL_ttf, you can try to remove this dependency. (remove the string text renderering, use a dummy surface). - update to latest SDL2 sources also ? - I see you use std:mutex, could this be releated ? If i replace this line:-
SDL_Surface* textSurface = TTF_RenderText_Shaded(myFont, textureText.c_str(), textColor, bgColor);
with the following:-
SDL_Surface* textSurface = SDL_CreateRGBSurface(0, 30, 30, 32, 0, 0, 0, 0);
SDL_FillRect(textSurface, NULL, SDL_MapRGB(textSurface->format, 255, 0, 0));
Then it works, and i see a red box on the screen.
So this indicates to me that it appears to be an issue with the TTF_RenderText_Shaded function in some way.
Ok, call me stupid *heh* I just worked out what the issue was. It's not a bug! It was me! I forgot to copy the SDL_ttf.dll to the debug/release directory. I re-downloaded the SDL_TTF libraries, and when i was copying them into where all the libraries/includes etc. go, I noticed that the SDL_ttf was a .dll and not a .lib. Then i thought, well crap, that means it's a runtime and needs to be in the same dir as the .exe. Once I did that the program no longer crashed and did what it was supposed to. Thanks for the time you spent on this. Sorry if I caused any issues. At least maybe my forgetfulness will help others :) It does have SDL2_ttf.lib, so if i'm building a static program with /MT, why is it that the program fails to run unless I have the SDL2_ttf.dll in the runtime directory? Shouldn't it statically build that library into the .exe? It sounds like the original issue is resolved, thanks! |
Here is some sample code I'm using:- SDL_Surface* textSurface = TTF_RenderText_Shaded(myFont, textureText.c_str(), textColor, bgColor); if (textSurface == NULL) { printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError()); printf("text: %s\n",textureText.c_str()); exit(2); } else { //Create texture from surface pixels mTexture = SDL_CreateTextureFromSurface(myRenderer, textSurface); if (mTexture == NULL) { printf("Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError()); exit(1); } else { //Get image dimensions mWidth = textSurface->w; mHeight = textSurface->h; setBlendMode(SDL_BLENDMODE_NONE); } //Get rid of old surface SDL_FreeSurface(textSurface); } When SDL_FreeSurface is called it causes an exception:- SDL_Malloc.c (void)SDL_AtomicDecRef(&s_mem.num_allocations); test.exe has triggered a breakpoint. occurred Critical error detected c0000374