EXC_BAD_ACCESS when using CCSkeletonAnimation - cocos2d-x-2.x

I'm new in cocos2d-x. When I put these code in init() method
CCSkeletonAnimation* skeletonNode = CCSkeletonAnimation::createWithFile("spine/miner.json", "spine/miner.atlas");
skeletonNode->setAnimation("run",true);
addchild(skeletonNode);
, it throws out an error message
void CCObject::release(void)
{
CCAssert(m_uReference > 0, "reference count should greater than 0");
--m_uReference;
if (m_uReference == 0)
{
delete this;
}
}
In SpineTest of TestCpp they do the same but no errors. So what exactly cause this error?
Any help would be appreciated.

Related

What is an async scope for a delegate in Vala?

I am trying the async examples from the GNOME project site. I get the follwoing warning which I don't under stand on how to fix.
async.vala:8.2-8.17: warning: delegates with scope="async" must be owned
Code
async double do_calc_in_bg(double val) throws ThreadError {
SourceFunc callback = do_calc_in_bg.callback;
double[] output = new double[1];
// Hold reference to closure to keep it from being freed whilst
// thread is active.
// WARNING HERE
ThreadFunc<bool> run = () => {
// Perform a dummy slow calculation.
// (Insert real-life time-consuming algorithm here.)
double result = 0;
for (int a = 0; a<100000000; a++)
result += val * a;
output[0] = result;
Idle.add((owned) callback);
return true;
};
new Thread<bool>("thread-example", run);
yield;
return output[0];
}
void main(string[] args) {
var loop = new MainLoop();
do_calc_in_bg.begin(0.001, (obj, res) => {
try {
double result = do_calc_in_bg.end(res);
stderr.printf(#"Result: $result\n");
} catch (ThreadError e) {
string msg = e.message;
stderr.printf(#"Thread error: $msg\n");
}
loop.quit();
});
loop.run();
}
The warning is pointing at the run variable inside the async function. Who or what needs to be owned? The reference to the closure?
The delegate needs to have a well defined owner all the time. The error message is a bit misleading.
To fix it you have to explicitly transfer the ownership from the delegate to the thread constructor:
new Thread<bool>("thread-example", (owned) run);
Instead of
new Thread<bool>("thread-example", run);
See also: https://wiki.gnome.org/Projects/Vala/Tutorial#Ownership
PS: The generated C code is fine in both cases. (at least with valac 0.46.6)

toCompletableFuture() stucks for asynchronous cache

Hello there I am trying to force a promise to end to get the result from it but it just stucks on loading.
public class CacheController extends Controller {
private AsyncCacheApi cache;
public Result cache()
{
String test = "nice";
cache.set("item.key", test, 15);
Customer user = new Customer("Ana", 12);
CompletionStage<Done> result = cache.set(user.getName(), user);
block(result);
return ok("Cached");
}
public Result checkCache() throws Exception
{
Logger.info("start");
//CompletionStage<String> news = cache.get("item.key");
//news.thenRun(() -> System.out.println("works"));
CompletionStage<Customer> result = cache.get("Ana");
Logger.info("step 1");
Logger.info(cache.get("Ana").toString());
Logger.info("Step 2");
Customer c = block(result);
Logger.info("Step 3 " + c.getName());
//result.thenRun(() -> setUser(result)).thenRun(() -> Logger.info(user.getName() + " " + user.getAge()));
return ok("cancan");
}
private <T> T block(CompletionStage<T> stage) {
try {
return stage.toCompletableFuture().get();
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
}
When trying to load the page it gets stuck after step2 at line 56: Customer c = block(result); by my guesses
Any ideas to fix it?
#Codrin
I had the same problem. But, see https://www.playframework.com/documentation/2.6.x/JavaCache#Setting-the-execution-context
By default, all Ehcache operations are blocking, and async implementations will block threads in the default execution context.
Maybe CompletableFuture.get() gets stuck because it is executed in the same thread with the caller.
Referring to the linked page, I added snippet below to my application.conf and it worked.
play.cache.dispatcher = "contexts.blockingCacheDispatcher"
contexts {
blockingCacheDispatcher {
fork-join-executor {
parallelism-factor = 3.0
}
}
}

GDX-SQLite android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1

I work in Android Studio with libgdx and gdx-sqlite. I want a simple query from my database with the following code.
try {
cursorSettings = dbHandler.rawQuery("SELECT "+COLUMN_SETTING+" FROM "+TABLE_SETTINGS+" WHERE "+COLUMN_SETTINGSID+" =13");
System.out.println(cursorSettings.getLong(0));
} catch (SQLiteGdxException e) {
e.printStackTrace();
}
The Desktop-Version works without problems, but in the android version I get the following error:
05-25 10:21:47.341 11978-12232/ch.shuttering.rapporte E/AndroidRuntime: FATAL EXCEPTION: GLThread 82275
Process: ch.shuttering.rapporte, PID: 11978
android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:460)
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:74)
at com.badlogic.gdx.sqlite.android.AndroidCursor.getLong(AndroidCursor.java:61)
at ch.shuttering.rapporte.Manager.SQLiteManager.SaveMangerSQLite.creatSQLiteSettings(SaveMangerSQLite.java:295)
at ch.shuttering.rapporte.RapporteMain.create(RapporteMain.java:66)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:311)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1546)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1262)
So every time I make a getXXX () query from the cursor I get an error, but if I now use the following code:
try {
cursorSettings = dbHandler.rawQuery("SELECT * FROM "+TABLE_SETTINGS);
} catch (SQLiteGdxException e) {
e.printStackTrace();
}
while (cursorSettings.next()) {
Gdx.app.log("FromDb", String.valueOf(cursorSettings.getString(1)));
}
I have a correct output with all data.
Does anyone have an idea what the problem is?
Thank you for your help
Okay I found the problem by myself, that was the code in the Android class
#Override
public long getLong (int columnIndex) {
try {
return cursor.getLong(columnIndex);
} catch (SQLiteException e) {
Gdx.app.log(DatabaseFactory.ERROR_TAG, "There was an error in getting the long", e);
throw new SQLiteGdxRuntimeException(e);
}
}
The problem is that in android the cursor points to -1 so it must first be set to the correct position, the following code solves the problem
#Override
public long getLong (int columnIndex) {
try {
cursor.moveToFirst();
return cursor.getLong(columnIndex);
} catch (SQLiteException e) {
Gdx.app.log(DatabaseFactory.ERROR_TAG, "There was an error in getting the long", e);
throw new SQLiteGdxRuntimeException(e);
}
}
You can found this code in the library gdx-sqlite-android.jar in the class AndroidCursor.
I hope the solution helps someone.

Setting default TWAIN data source without using API UI menu

Using the twaindotnet library in C#, I'm wondering if there's a way to set the default datasource using the library.
As a feeble attempt, I've tried adding a SetDefault method to the DataSource class of twaindonet, like this
public static void SetDefault(Identity applicationId, IWindowsMessageHook messageHook, DataSource newDataSource)
{
var defaultSourceId = newDataSource.SourceId;
// Attempt to get information about the system default source
var result = Twain32Native.DsmIdentity(
applicationId,
IntPtr.Zero,
DataGroup.Control,
DataArgumentType.Identity,
Message.Set,
defaultSourceId);
if (result != TwainResult.Success)
{
var status = DataSourceManager.GetConditionCode(applicationId, null);
throw new TwainException("Error getting information about the default source: " + result, result, status);
}
}
which is called from the DataSourceManage class like this
public void SelectSource(DataSource dataSource)
{
DataSource.Dispose();
DataSource.SetDefault(ApplicationId, _messageHook, dataSource);
}
But when I try to use SetDefault, Twain32Native.DsmIdentity always results in Failure being returned.
I basically copied from SetDefault the setDefaultDataSource method from TWAIN sample Data Source and Application
pTW_IDENTITY TwainApp::setDefaultDataSource(unsigned int _index)
{
if(m_DSMState < 3)
{
cout << "You need to open the DSM first." << endl;
return NULL;
}
else if(m_DSMState > 3)
{
PrintCMDMessage("A source has already been opened, please close it first\n");
return NULL;
}
if(_index >= 0 && _index < m_DataSources.size())
{
m_pDataSource = &(m_DataSources[_index]);
// set the specific data source
TW_UINT16 twrc;
twrc = _DSM_Entry(
&m_MyInfo,
0,
DG_CONTROL,
DAT_IDENTITY,
MSG_SET,
(TW_MEMREF) m_pDataSource);
switch (twrc)
{
case TWRC_SUCCESS:
break;
case TWRC_FAILURE:
printError(0, "Failed to get the data source info!");
break;
}
}
else
{
return NULL;
}
return m_pDataSource;
}
Any help would be greatly appreciated.
The possible cause is that the version of your TWAIN DSM is too low. Only DSM 2.0 or above supports setting default TWAIN data source.

System.IndexOutOfRangeException: Cannot find table 0

I got struck with this issue since long and am unable to find a solution
I have been getting this error:
'System.IndexOutOfRangeException: Cannot find table 0.' at line 3:
if (Session["value"] != null)
{
**ds = proxy.GetId(Session["value "].ToString());**
if (ds!= null)
{
if (ds.Tables.Count == 0)
{
Response.Redirect("Timeout.aspx");
}
else
{
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
string Id = ds.Tables[0].Rows[0]["id"].ToString().Trim();
if (Id.Trim() == "0")
{
Session["ID"] = "ID NOT CREATED";
ds = proxy.Getid(Session["value "].ToString());
}
}
}
}
}
Ideally there is only value getting returned from the stored proc,so the error should not occur in line 3, since I put all checks for dataset 'ds' in below code. Request to please help me ...
Have you checked in the function GetId for possible causes for the error or if the session variable you're converting to a string has a value? I can see you getting that error if you're trying to turn a session var into a string when it hasn't been initialized.

Resources