How get access to Urho3d main thread from Android?


Is any way to call a method in Urho3D main thread from Android?
I try to change plane objects texture, but I can’t do it in non main thread.
As result I’ve got log message:
com.github.urho3d E/libEGL: call to OpenGL ES API with no current context (logged once per thread)

Better if you add some code…

My project is experemental. Basic project is RenderToTexture from Urho3d samples.

Java code:

native void setTexture();

 public void onClick(View view) {

C++ code:

class EngineGateway {

Urho3D::Application* application;

Urho3D::Application *getApplication() const;
void setApplication(Urho3D::Application *application);


EngineGateway *engineGateway;

    extern "C"{

  Java_com_mydomen_test2_BasicFragment_setTexture(JNIEnv *env, jobject instance) {

    RenderToTexture *app = dynamic_cast<RenderToTexture*>(engineGateway->getApplication());



 void RenderToTexture::CreateScene() {


  StaticModel *boxObject = screenNode->CreateComponent<StaticModel>();

    SharedPtr<Material> renderMaterial(new Material(context_));
    renderMaterial->SetTechnique(0, cache->GetResource<Technique>("Techniques/Diff.xml"));
    renderTexture = SharedPtr<Texture2D>(new Texture2D(context_));

    renderTexture->SetSize(1024, 768, Graphics::GetRGBFormat(), TEXTURE_DYNAMIC);

    int textureWidth = renderTexture->GetWidth();
    int textureHeight = renderTexture->GetHeight();

    SharedPtr<Image> texImg = SharedPtr<Image>(new Image(context_));
    texImg->SetSize(textureWidth, textureHeight, 3);
    for (int i = 0; i < width; ++i) {
        for (int j = 0; j < height; ++j) {
            texImg->SetPixel(i, j, Color(0, 0, 1));

    renderMaterial->SetTexture(TU_DIFFUSE, renderTexture);  
    boxObject->SetMaterial(renderMaterial);   // It works, so it is colled in engine main thread

void RenderToTexture::setImage() {

const int width = renderTexture->GetWidth();
const int height = renderTexture->GetHeight();

Image* texImg = new Image(context_);
texImg->SetSize(width, height, 3);
for (int i = 0; i < width; ++i) {
    for (int j = 0; j < height; ++j) {
        texImg->SetPixel(i, j, Color(1, 1, 1));
renderTexture->SetData(texImg);		// It dosn't work, so it is colled in Android MainUI thread

It doesn’t look like the 10_RenderToTexture sample… did you tried that?

This sample has a good model - a screen is above the floor. I’ve made some changes in the 10_RenderToTexture sample. For example I use color fill as a texture.
I try to change a texture on this screen.