doesn't have an available Corona Runtime to run this task on!

Hello!

In Java part of my application I have two classes. In first one I implemented “com.naef.jnlua.NamedJavaFunction”  and on invoke method call the “call” method of it’s second class. On “call” function I wrote following code:

public static void call(final int status){ System.out.println(" calling checkAvailablityCallback function !!!!"); final com.ansca.corona.CoronaRuntimeTaskDispatcher dispatcher = new com.ansca.corona.CoronaRuntimeTaskDispatcher(state); com.ansca.corona.CoronaEnvironment.getCoronaActivity().runOnUiThread(new Runnable() { @Override public void run() { com.ansca.corona.CoronaRuntimeTask task = new com.ansca.corona.CoronaRuntimeTask() { @Override public void executeUsing(com.ansca.corona.CoronaRuntime runtime) { com.naef.jnlua.LuaState luaState = runtime.getLuaState(); luaState.rawGet(com.naef.jnlua.LuaState.REGISTRYINDEX, luaFunctionReferenceKey); luaState.unref(com.naef.jnlua.LuaState.REGISTRYINDEX, luaFunctionReferenceKey); state.pushInteger(status); luaState.call(1, 0); } }; dispatcher.send(task); } }); }

​But sometimes I get the following error in corona while my application didn’t destroy or dispose at all. 

“CoronaRuntimeTaskDispatcher.send() doesn’t have an available Corona Runtime to run this task on! Abort!”

Can you explain why I will get this message? I can’t figure out how prevent this. 

Thanks for your consideration. 

Are you using CoronaCards or Corona Enterprise?

I am using Corona Enterprise.

Hi sara.r,

When you’re creating a CoronaRuntimeTaskDispatcher, are you using a LuaState instance that’s global or the one passed into the invoke() method of the NamedJavaFunction in question? If it’s a global LuaState, you may be seeing that message about not having an available Corona Runtime because the global LuaState instance has closed.

To get around this, instead of creating your own CoronaRuntimeTaskDispatcher instance every time, you might consider using the CoronaRuntimeTaskDispatcher instance that belongs to the CoronaActivity instance. You shouldn’t have to worry about the LuaState yourself if you take this approach.

Changing your call() method to something like this should get around your problem, and also help with other common Android concerns.

public static void call(final int status) { android.util.Log.d("Corona", " calling checkAvailablityCallback function !!!!"); com.ansca.corona.CoronaActivity coronaActivity = com.ansca.corona.CoronaEnvironment.getCoronaActivity(); if (coronaActivity == null) { // App is exiting, return as other needed resources have been destroyed. return; else { coronaActivity.runOnUiThread(new Runnable() { @Override public void run() { com.ansca.corona.CoronaRuntimeTask task = new com.ansca.corona.CoronaRuntimeTask() { @Override public void executeUsing(com.ansca.corona.CoronaRuntime runtime) { com.naef.jnlua.LuaState luaState = runtime.getLuaState(); luaState.rawGet(com.naef.jnlua.LuaState.REGISTRYINDEX, luaFunctionReferenceKey); luaState.unref(com.naef.jnlua.LuaState.REGISTRYINDEX, luaFunctionReferenceKey); luaState.pushInteger(status); luaState.call(1, 0); } }; coronaActivity.getRuntimeTaskDispatcher.send(task); } }); } }

Are you using CoronaCards or Corona Enterprise?

I am using Corona Enterprise.

Hi sara.r,

When you’re creating a CoronaRuntimeTaskDispatcher, are you using a LuaState instance that’s global or the one passed into the invoke() method of the NamedJavaFunction in question? If it’s a global LuaState, you may be seeing that message about not having an available Corona Runtime because the global LuaState instance has closed.

To get around this, instead of creating your own CoronaRuntimeTaskDispatcher instance every time, you might consider using the CoronaRuntimeTaskDispatcher instance that belongs to the CoronaActivity instance. You shouldn’t have to worry about the LuaState yourself if you take this approach.

Changing your call() method to something like this should get around your problem, and also help with other common Android concerns.

public static void call(final int status) { android.util.Log.d("Corona", " calling checkAvailablityCallback function !!!!"); com.ansca.corona.CoronaActivity coronaActivity = com.ansca.corona.CoronaEnvironment.getCoronaActivity(); if (coronaActivity == null) { // App is exiting, return as other needed resources have been destroyed. return; else { coronaActivity.runOnUiThread(new Runnable() { @Override public void run() { com.ansca.corona.CoronaRuntimeTask task = new com.ansca.corona.CoronaRuntimeTask() { @Override public void executeUsing(com.ansca.corona.CoronaRuntime runtime) { com.naef.jnlua.LuaState luaState = runtime.getLuaState(); luaState.rawGet(com.naef.jnlua.LuaState.REGISTRYINDEX, luaFunctionReferenceKey); luaState.unref(com.naef.jnlua.LuaState.REGISTRYINDEX, luaFunctionReferenceKey); luaState.pushInteger(status); luaState.call(1, 0); } }; coronaActivity.getRuntimeTaskDispatcher.send(task); } }); } }