| SDL_RenderReadPixels crash on reading from Texture | 
| 
     mr_tawan 
    
  | 
  
    
 I think it's does not looks right when you're using a texture that's created from file as a render target. And from your code you're just trying to read a pixel from the texture, or may be from a surface. Usually the texture would have to be created with the flag SDL_TEXTUREACCESS_TARGET, which I don't think the SDL_CreateTextureFromSurface would set that flag (I could be wrong though). 
  I think the SDL_RenderReadPixels is meant to be used in the use case like screen capture. And if you're just reading pixel from texture, SDL_LockTexture is what you need.  | 
|||||||||||
| 
     | 
||||||||||||
| 
     mr_tawan 
    
  | 
  
    
 Oh and textures can be locked only when it has SDL_TEXTUREACCESS_STREAMING. If the texture is static then it couldn't be lock. 
  BTW, you can also get the pixel data by locking the surface as well.  | 
|||||||||||
| 
     | 
||||||||||||
| 
     LBandy 
    
  | 
  
    
 I've posted the code for the sake of simplicity. In a real life scenario I've created a texture with SDL_TEXTUREACCESS_TARGET and rendered several other textures on it, then I was trying to save the final texture as a file, so I needed a way to convert it back to a surface. The crash was the same. 
  I'm not sure I understand the SDL_LockTexture relevance, as I'm interested in reading and not writing. Should I lock it before reading too?  | 
|||||||||||
| 
     | 
||||||||||||
| 
     LBandy 
    
  | 
  
    
 Only changing SDL_TEXTUREACCESS_TARGET to SDL_TEXTUREACCESS_STREAMING seem to have solved the issue. 
   | 
|||||||||||
| 
     | 
||||||||||||

