SDL 2 - Android

Hi,

I have an android application(using SLD) that opens up the contact list for the user to select a contact.
When the contact screen closes and the application reopens, I create a new text image using SDL_TTF, however the image comes out black.

I believe this is because the renderer I am passing in to create the texture is no longer valid; as in the android log, there are messages saying “surfaceDestroyed()”, “surfaceCreated()” and “surfaceChanged()”.
All the old text is still fine, it is only text created after the application comes back into focus that is a problem.

Can anyone give me an idea on how to fix this problem?
How do I get the new render data?

Thanks

There are no Android experts out there?

I’m still stuck on this. Please let me know if you need more information.

Thanks

Sorry, for the long delay. I’ve been busy with other things.

So When I init SDL I call the following code.

Code:

if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0)
{
	return false;
}

unsigned int flags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL;
if (aWindowed)
{
	flags |= SDL_WINDOW_RESIZABLE;
}

SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

mWindow = SDL_CreateWindow("Help Me", 0, 0, aXRes, aYRes, flags | SDL_WINDOW_BORDERLESS);

SDL_SetWindowFullscreen(mWindow, !aWindowed ? SDL_TRUE : SDL_FALSE);

mRenderer = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

TTF_Init();

SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
SDL_EventState(SDL_TEXTEDITING, SDL_ENABLE);

Then when I want to create so text I call the following code.

Code:

	SDL_Color black = { 0x00, 0x00, 0x00, 255 }; 
	SDL_Surface *fg_surface = TTF_RenderText_Blended(font, aText.c_str(), aColour); 
	SDL_Surface *bg_surface = NULL;
	if (fg_surface)
	{
		bg_surface = TTF_RenderText_Blended(font, aText.c_str(), black); 
		fg_surface = GuiManager::GetInstance()->CreateShadow(fg_surface, bg_surface, offset);
	}
	mTexture = SDL_CreateTextureFromSurface(aRenderer, fg_surface);
	SDL_FreeSurface(fg_surface);

I am guessing when the application is swapped out and then back the aRenderer variable is no longer valid. (aRenderer is passed in the the text create code from the first code).
I have tested the code and the problem isn’t the CreateShadow code.

Does this help any?
Cheers
Brad

In case any one is interested.

I have fixed this. The problem was the fonts needed to be recreated, which I now destroy on loosing focus and recreate on gaining focus.

Thanks

I’m glad you figured it out!On Tue, Nov 20, 2012 at 10:04 PM, BJ wrote:

**
In case any one is interested.

I have fixed this. The problem was the fonts needed to be recreated, which
I now destroy on loosing focus and recreate on gaining focus.

Thanks


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

Hi Sam,

I am not sure if you have fixed this. I am using the version that you asked me to download for the previous problem.

The onKey function in the DummyEdit, never happens; below is the code to fix this.

Code:

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
	ic = new SDLInputConnection(this, false);

	outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI | 33554432 /*
																		 * API
																		 * 11
																		 * :
																		 * EditorInfo
																		 * .
																		 * IME_FLAG_NO_FULLSCREEN
																		 */;
	
	outAttrs.inputType = InputType.TYPE_NULL;

	return ic;
}

I changed ic = new SDLInputConnection(this, true); to ic = new SDLInputConnection(this, false);
and added the following line outAttrs.inputType = InputType.TYPE_NULL;

Cheers
Brad

PS Have you figured out how to get the height of the keyboard?