| Summary: | SDL_CreateTextureFromSurface fails when creating textures at maximum texture dimensions | ||
|---|---|---|---|
| Product: | SDL | Reporter: | mattreecebentley |
| Component: | render | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED ABANDONED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | major | ||
| Priority: | P2 | ||
| Version: | 2.0.1 | ||
| Hardware: | x86 | ||
| OS: | Windows (XP) | ||
|
Description
mattreecebentley
2014-03-04 04:22:57 UTC
mingw32 (latest stable release) 4gb ram, 3gb available Second texture fail is most common scenario. Interestingly, Freeing the first surface and destroying the first texture makes no difference. Neither does retaining the first surface and creating the second texture from it after destroying the first texture. Last couple of times I tried this I got SDL Error: CreateTexture(): UNKNOWN. Can you provide a minimal test case to reproduce this? Thanks! Will work on this and get back to you over the next few days- Cheers! Here you go-
assuming that sdl, window, renderer are all correctly initiated, and the following function is defined:
-----------------------------
inline SDL_Surface * plf_create_surface(int width, int height)
{
/* SDL interprets each pixel as a 32-bit number, so our masks must depend
on the endianness (byte order) of the machine */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
return SDL_CreateRGBSurface(0, width, height, 32, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
#else
return SDL_CreateRGBSurface(0, width, height, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
#endif
}
------------------------------
Then the following code:
-----------------------------
SDL_RendererInfo s_renderer_info;
SDL_GetRendererInfo(s_renderer, &s_renderer_info)
SDL_Surface *surf1 = plf_create_surface(s_renderer_info.max_texture_width, s_renderer_info.max_texture_height);
if (surf1 == NULL)
{
std::cerr << "failed to create surface 1 of size " << s_renderer_info.max_texture_width << "/" << s_renderer_info.max_texture_height << ". SDL error: " << SDL_GetError() << std::endl;
}
SDL_Texture *tex1 = SDL_CreateTextureFromSurface(platforma.get_renderer()->get(), surf1);
if (tex1 == NULL)
{
std::cerr << "failed to create texture 1 from surface 1 of size " << s_renderer_info.max_texture_width << "/" << s_renderer_info.max_texture_height << ". SDL error: " << SDL_GetError() << std::endl;
}
SDL_Surface *surf2 = plf_create_surface(s_renderer_info.max_texture_width, s_renderer_info.max_texture_height);
if (surf2 == NULL)
{
std::cerr << "failed to create surface 2 of size " << s_renderer_info.max_texture_width << "/" << s_renderer_info.max_texture_height << ". SDL error: " << SDL_GetError() << std::endl;
}
SDL_Texture *tex2 = SDL_CreateTextureFromSurface(platforma.get_renderer()->get(), surf1);
if (tex2 == NULL)
{
std::cerr << "failed to create texture 2 from surface 2 of size " << s_renderer_info.max_texture_width << "/" << s_renderer_info.max_texture_height << ". SDL error: " << SDL_GetError() << std::endl;
}
---------------------------------
Will result in the following text or similar under ati catalyst drivers (have tried latest and an older version now). I don't have multiple graphics cards to test this on. To test, you will need an ati card, possibly XP (?). I have an HD 5800. Have tried changing 3d driver settings, no difference:
----------------------------------
failed to create texture 1 from surface 1 of size 8192/8192. SDL error: Out of memory
failed to create texture 2 from surface 2 of size 8192/8192. SDL error: CreateTexture(): UNKNOWN
ps. The code does not throw errors on my eeepc 1005ha (cheap intel graphics onboard). Could be vendor-specific. Ah, sorry- the code for the texture creation I hadn't translated from my own engine yet- it should read: SDL_CreateTextureFromSurface(s_renderer, surf1); for the first line and SDL_CreateTextureFromSurface(s_renderer, surf2); for the second one. Apologies- Consolidated code here:
inline SDL_Surface * plf_create_surface(int width, int height)
{
/* SDL interprets each pixel as a 32-bit number, so our masks must depend
on the endianness (byte order) of the machine */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
return SDL_CreateRGBSurface(0, width, height, 32, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
#else
return SDL_CreateRGBSurface(0, width, height, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
#endif
}
void main()
{
// Initialise SDL, window, renderer here. s_renderer = pointer to renderer.
SDL_RendererInfo s_renderer_info;
SDL_GetRendererInfo(s_renderer, &s_renderer_info)
SDL_Surface *surf1 = plf_create_surface(s_renderer_info.max_texture_width, s_renderer_info.max_texture_height);
if (surf1 == NULL)
{
std::cerr << "failed to create surface 1 of size " << s_renderer_info.max_texture_width << "/" << s_renderer_info.max_texture_height << ". SDL error: " << SDL_GetError() << std::endl;
}
SDL_Texture *tex1 = SDL_CreateTextureFromSurface(s_renderer, surf1);
if (tex1 == NULL)
{
std::cerr << "failed to create texture 1 from surface 1 of size " << s_renderer_info.max_texture_width << "/" << s_renderer_info.max_texture_height << ". SDL error: " << SDL_GetError() << std::endl;
}
SDL_Surface *surf2 = plf_create_surface(s_renderer_info.max_texture_width, s_renderer_info.max_texture_height);
if (surf2 == NULL)
{
std::cerr << "failed to create surface 2 of size " << s_renderer_info.max_texture_width << "/" << s_renderer_info.max_texture_height << ". SDL error: " << SDL_GetError() << std::endl;
}
SDL_Texture *tex2 = SDL_CreateTextureFromSurface(s_renderer, surf2);
if (tex2 == NULL)
{
std::cerr << "failed to create texture 2 from surface 2 of size " << s_renderer_info.max_texture_width << "/" << s_renderer_info.max_texture_height << ". SDL error: " << SDL_GetError() << std::endl;
}
}
Hello, and sorry if you're getting dozens of copies of this message by email. We are closing out bugs that appear to be abandoned in some form. This can happen for lots of reasons: we couldn't reproduce it, conversation faded out, the bug was noted as fixed in a comment but we forgot to mark it resolved, the report is good but the fix is impractical, we fixed it a long time ago without realizing there was an associated report, etc. Individually, any of these bugs might have a better resolution (such as WONTFIX or WORKSFORME or INVALID) but we've added a new resolution of ABANDONED to make this easily searchable and make it clear that it's not necessarily unreasonable to revive a given bug report. So if this bug is still a going concern and you feel it should still be open: please feel free to reopen it! But unless you respond, we'd like to consider these bugs closed, as many of them are several years old and overwhelming our ability to prioritize recent issues. (please note that hundred of bug reports were sorted through here, so we apologize for any human error. Just reopen the bug in that case!) Thanks, --ryan. |