We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2428

Summary: SDL_CreateTextureFromSurface fails when creating textures at maximum texture dimensions
Product: SDL Reporter: mattreecebentley
Component: renderAssignee: 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
Setup:
XP SP3
AMD/ATI HD 5800
Latest Catalyst drivers

While I can create many textures at maximum texture resolution (as supplied by rendererinfo, 8192x8192) using SDL_CreateTexture, 

depending on circumstance I can either create 1 or 0 textures using SDL_CreateTextureFromSurface from a surface with dimensions 8192x8192.

Either SDL gives an error of 'Out of Memory' when no texture is able to be created, 
or an error of 'Invalid Texture' when only one texture is able to be created.

I would prefer to be using SDL_CreateTexture but the previously logged bug around incorrect pixelformats as supplied by CreateTexture prevents my use of it.
Comment 1 mattreecebentley 2014-03-04 04:24:15 UTC
mingw32 (latest stable release)
4gb ram, 3gb available
Comment 2 mattreecebentley 2014-03-04 06:22:57 UTC
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.
Comment 3 Sam Lantinga 2014-03-05 05:12:01 UTC
Can you provide a minimal test case to reproduce this?

Thanks!
Comment 4 mattreecebentley 2014-03-05 07:51:00 UTC
Will work on this and get back to you over the next few days-
Cheers!
Comment 5 mattreecebentley 2014-03-06 09:19:52 UTC
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
Comment 6 mattreecebentley 2014-03-06 09:21:03 UTC
ps. The code does not throw errors on my eeepc 1005ha (cheap intel graphics onboard). Could be vendor-specific.
Comment 7 mattreecebentley 2014-03-07 11:08:57 UTC
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-
Comment 8 mattreecebentley 2014-03-08 23:08:41 UTC
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;
	}
}
Comment 9 Ryan C. Gordon 2018-08-06 21:20:24 UTC
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.