I ran a test on pixel formats from the renderer, and I got an error:
source code:
- void display_renderer_info(SDL_Renderer *rend)
- {
-
SDL_RendererInfo ri;
-
Uint32 *pfe;
-
int i;
-
SDL_GetRendererInfo(rend, &ri);
-
std::cout << "Name of renderer: " << ri.name << std::endl;
-
std::cout << "Renderer flags: " << std::hex << ri.flags <<
std::endl;
11. std::cout << "Number of texture formats: " << std::dec <<
ri.num_texture_formats << std::endl;
12.
13. pfe = ri.texture_formats;
14.
15. for (i = 0; i < ri.num_texture_formats; i++) {
16. std::cout << "Texture format " << std::dec << i <<
std::endl;
17. std::cout << "Texture format name: " <<
SDL_GetPixelFormatName(pfe[i]) << std::endl;
18.
19. SDL_PixelFormat *pf = SDL_AllocFormat(pfe[i]);
20.
21. if (!pf) {
22. fatal_sdl_error(“SDL_AllocFormat”);
23. }
24.
25. std::cout << "Bits per pixel: " << std::dec <<
(int)pf->BitsPerPixel << std::endl;
26. std::cout << "Bytes per pixel: " << std::dec <<
(int)pf->BytesPerPixel << std::endl;
27. std::cout << "Red mask: " << std::hex <<
(int)pf->Rmask << std::endl;
28. std::cout << "Green mask: " << std::hex <<
(int)pf->Gmask << std::endl;
29. std::cout << "Blue mask: " << std::hex <<
(int)pf->Bmask << std::endl;
30. std::cout << "Alpha mask: " << std::hex <<
(int)pf->Amask << std::endl;
31. }
32. }
error message:
terminate called after throwing an instance of 'std::runtime_error’
what(): SDL_AllocFormat: Parameter ‘format’ is invalid
Aborted (core dumped)
question:
Why is SDL_AllocFormat choking on a pixel format that was returned by
SDL_GetRendererInfo?