Strange artefacts on SDL text backgrounds

Hi SDL

We are developing a SDL2-based media player named TomahawkWorld.

We have a strange issue specially with SDL2_ttf textures.

Quite often, after SDL_RenderCopy SDL2_ttf textures, text background appears to have various colour artefacts including sometimes other images such as dock icons!

Simple test programs to render SDL2_ttf textures does not seems to have any such issue.

I used latest clang (LLVM ver. 3.5 SVN) with -fsanitize=address to check any memory corruption. But at compile or at run-time AddressSanitizer does not show any issue.

A screenshot to show this issue: http://www.tomahawkworld.com/images/screenshot-text-issue-1200.png

If you a Mac OS X user, you may download and install our player from www.tomahawkworld.com .

Appreciate if the SDL community could help me to identify the cause.

Best regards
Sagara

how do you render your ttf ?
usually SDL_tt will generate a surface, and then you either render the
surface onscreen, or to a target texture which is then rendered onscreen.
In the latter case, did you check that your target texture was
initialized (filled) with zeros ?

Le 05/09/2014 19:10, Sagara Wijetunga a ?crit :> Hi SDL

We are developing a SDL2-based media player named TomahawkWorld.

We have a strange issue specially with SDL2_ttf textures.

Quite often, after SDL_RenderCopy SDL2_ttf textures, text background
appears to have various colour artefacts including sometimes other
images such as dock icons!

Simple test programs to render SDL2_ttf textures does not seems to
have any such issue.

I used latest clang (LLVM ver. 3.5 SVN) with -fsanitize=address to
check any memory corruption. But at compile or at run-time
AddressSanitizer does not show any issue.

A screenshot to show this
issue: http://www.tomahawkworld.com/images/screenshot-text-issue-1200.png

If you a Mac OS X user, you may download and install our player from
www.tomahawkworld.com .

Appreciate if the SDL community could help me to identify the cause.

Best regards
Sagara


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

How do use SDL2_ttf is as follows:

  1. Method A
    surface = TTF_RenderUTF8_Blended(font, “Text”, colour);
    texture = SDL_CreateTextureFromSurface(renderer, surface);
    SDL_RenderCopy(…texture…);

No issue.

  1. Method B
    surfaceOrig = TTF_RenderUTF8_Blended(fontTitle, “Text”, colour);
    textureOrig = SDL_CreateTextureFromSurface(renderer, surfaceOrig);

textureScaled = SDL_CreateTexture(renderer, pixFormatOrig, SDL_TEXTUREACCESS_TARGET, w, h);
SDL_SetRenderTarget(renderer, textureScaled);
SDL_RenderCopy(renderer, textureOrig, NULL, NULL)
SDL_SetRenderTarget(renderer, NULL);
SDL_RenderCopy(…textureScaled…);

Only in this path I have issues.

Note 1, test program for Method B does not show any issue.

Note 2, texture returned from SDL_CreateTexture() is not validated in any way other than for a valid pointer. If necessary to validate, what should I do?

Thanks.

Sagara

how do you render your ttf ?
usually SDL_tt will generate a surface, and then you either render
the surface onscreen, or to a target texture which is then
rendered onscreen.
In the latter case, did you check that your target texture was
initialized (filled) with zeros ?

  1. Method A
    surface = TTF_RenderUTF8_Blended(font, “Text”, colour);
    texture = SDL_CreateTextureFromSurface(renderer, surface);
    SDL_RenderCopy(…texture…);

No issue.

  1. Method B
    surfaceOrig = TTF_RenderUTF8_Blended(fontTitle, “Text”, colour);
    textureOrig = SDL_CreateTextureFromSurface(renderer, surfaceOrig);

textureScaled = SDL_CreateTexture(renderer, pixFormatOrig, SDL_TEXTUREACCESS_TARGET, w, h);
SDL_SetRenderTarget(renderer, textureScaled);
SDL_RenderCopy(renderer, textureOrig, NULL, NULL)
SDL_SetRenderTarget(renderer, NULL);
SDL_RenderCopy(…textureScaled…);

Only in this path I have issues.


SDL mailing list SDL at lists.libsdl.org http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.orgOn Saturday, September 6, 2014 11:57 AM, Sanette wrote:

in method B, since the TTF texture has transparent pixels, I would do a
SDL_RenderClear(renderer) just after
SDL_SetRenderTarget. Otherwise you might have random pixels in the
background.
If you want to preserve transparency, you may also do a
SDL_SetRenderDrawColor(renderer,0,0,0,0) before SDL_RenderClear.

Le 06/09/2014 12:01, Sagara Wijetunga a ?crit :> How do use SDL2_ttf is as follows:

  1. Method A
    surface = TTF_RenderUTF8_Blended(font, “Text”, colour);
    texture = SDL_CreateTextureFromSurface(renderer, surface);
    SDL_RenderCopy(…texture…);

No issue.

  1. Method B
    surfaceOrig = TTF_RenderUTF8_Blended(fontTitle, “Text”, colour);
    textureOrig = SDL_CreateTextureFromSurface(renderer, surfaceOrig);

textureScaled = SDL_CreateTexture(renderer, pixFormatOrig,
SDL_TEXTUREACCESS_TARGET, w, h);
SDL_SetRenderTarget(renderer, textureScaled);
SDL_RenderCopy(renderer, textureOrig, NULL, NULL)
SDL_SetRenderTarget(renderer, NULL);
SDL_RenderCopy(…textureScaled…);

Only in this path I have issues.

Note 1, test program for Method B does not show any issue.

Note 2, texture returned from SDL_CreateTexture() is not validated in
any way other than for a valid pointer. If necessary to validate, what
should I do?

Thanks.

Sagara
On Saturday, September 6, 2014 11:57 AM, Sanette <@Sanette> wrote:

how do you render your ttf ?
usually SDL_tt will generate a surface, and then you either render the
surface onscreen, or to a target texture which is then rendered onscreen.
In the latter case, did you check that your target texture was
initialized (filled) with zeros ?

  1. Method A
    surface = TTF_RenderUTF8_Blended(font, “Text”, colour);
    texture = SDL_CreateTextureFromSurface(renderer, surface);
    SDL_RenderCopy(…texture…);

No issue.

  1. Method B
    surfaceOrig = TTF_RenderUTF8_Blended(fontTitle, “Text”, colour);
    textureOrig = SDL_CreateTextureFromSurface(renderer, surfaceOrig);

textureScaled = SDL_CreateTexture(renderer, pixFormatOrig,
SDL_TEXTUREACCESS_TARGET, w, h);
SDL_SetRenderTarget(renderer, textureScaled);
SDL_RenderCopy(renderer, textureOrig, NULL, NULL)
SDL_SetRenderTarget(renderer, NULL);
SDL_RenderCopy(…textureScaled…);

Only in this path I have issues.


SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi Sanette

Your suggestion worked. Thank you very much.

Best regards
Sagara

in method B, since the TTF texture has transparent pixels, I would do a SDL_RenderClear(renderer) just after
SDL_SetRenderTarget. Otherwise you might have random pixels in the
background.
If you want to preserve transparency, you may also do a
SDL_SetRenderDrawColor(renderer,0,0,0,0) before SDL_RenderClear.

Le 06/09/2014 12:01, Sagara Wijetunga a ?crit :

How do use SDL2_ttf is as follows:

  1. Method A
    surface = TTF_RenderUTF8_Blended(font, “Text”, colour);
    texture = SDL_CreateTextureFromSurface(renderer, surface);
    SDL_RenderCopy(…texture…);

No issue.

  1. Method B
    surfaceOrig = TTF_RenderUTF8_Blended(fontTitle, “Text”, colour);
    textureOrig = SDL_CreateTextureFromSurface(renderer, surfaceOrig);

textureScaled = SDL_CreateTexture(renderer, pixFormatOrig, SDL_TEXTUREACCESS_TARGET, w, h);
SDL_SetRenderTarget(renderer, textureScaled);
SDL_RenderCopy(renderer, textureOrig, NULL, NULL)
SDL_SetRenderTarget(renderer, NULL);
SDL_RenderCopy(…textureScaled…);

Only in this path I have issues.

Note 1, test program for Method B does not show any issue.

Note 2, texture returned from SDL_CreateTexture() is not validated in any way other than for a valid pointer. If necessary to validate, what should I do?

Thanks.

Sagara

how do you render your ttf ?
usually SDL_tt will generate a surface, and
then you either render the surface onscreen,
or to a target texture which is then
rendered onscreen.
In the latter case, did you check that your
target texture was initialized (filled) with
zeros ?

  1. Method A
    surface = TTF_RenderUTF8_Blended(font, “Text”, colour);
    texture = SDL_CreateTextureFromSurface(renderer, surface);
    SDL_RenderCopy(…texture…);

No issue.

  1. Method B
    surfaceOrig = TTF_RenderUTF8_Blended(fontTitle, “Text”, colour);
    textureOrig = SDL_CreateTextureFromSurface(renderer, surfaceOrig);

textureScaled = SDL_CreateTexture(renderer, pixFormatOrig, SDL_TEXTUREACCESS_TARGET, w, h);
SDL_SetRenderTarget(renderer, textureScaled);
SDL_RenderCopy(renderer, textureOrig, NULL, NULL)
SDL_SetRenderTarget(renderer, NULL);
SDL_RenderCopy(…textureScaled…);

Only in this path I have issues.


SDL mailing list SDL at lists.libsdl.org http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.orgOn Saturday, September 6, 2014 4:18 PM, Sanette wrote:

On Saturday, September 6, 2014 11:57 AM, Sanette wrote: