cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.13k stars 7.05k forks source link

FileUtils::getInstance() JNI Runtime Error #19553

Closed MuratAl closed 5 years ago

MuratAl commented 5 years ago

Steps to Reproduce: I've started a Game with Cocos2dx v3.15 and switched to new Version 3.17.1. Now I've realized that the C++ <-> Java "Communication" has been rewritten. FileUtils* fileUtils = FileUtils::getInstance(); produces a Runtime Error on my old smart phone Samsung Galaxy S3... but not on other devices like Xiaomi Redmi 4x and LG G4.

I did some Research and FileUtils::getInstance() leads to an error in the File JniHelper.cpp Line 48:

_jclass _claz

z = (jclass) env->CallObjectMethod(cocos2d::JniHelper::classloader, cocos2d::JniHelper::loadclassMethod_methodID, jstrClassName);

cocos2d::JniHelper::classloader = NULL cocos2d::JniHelper::loadclassMethod_methodID = NULL

some Details: JNI Error.txt

crazyhappygame commented 5 years ago

Hi. Could you reproduce this issue on latest cpp-tests from CI. https://ci.appveyor.com/api/buildjobs/69nq0r1w78srhw5m/artifacts/release%2FCppTests-release-unsigned.apk

MuratAl commented 5 years ago

Thank you @crazyhappygame. I used the cpp-tests (I built it for myself) and it worked. So I looked at Google for a solution and found other (non cocos2dx-specific threads) with almost the same issue. Seems to be a problem with JNI and unreleased resources... I dont know. I do not have time to go deeper into this topic. I'm also using JNI for some tasks (like ads, notifications, etc.)... this seems to be the problem… and this is the only difference between my Code and the cpp-tests Code.

My Code works fine with cocos2dx v3.15 (for all of my devices). I do not know how many devices will be affected by this "bug" when I release my game (with CCv3.17+) :-/

Additional Information: My Game worked one time of almost 100 tryouts. So I assume that it really has something to do with Memory corruption or similar.

crazyhappygame commented 5 years ago

Could you create simple test case?

MuratAl commented 5 years ago

yes. but that would take some time. The JNI Part of my Code/Game is no magic. it's based on SonarSystems Cocos-Helper. I'm using (of course) newer Versions of the used Services... but the JNI Part (functionality) is the same.

imtrobin commented 5 years ago

I have Samsung S3, my JNI seems working, also from older 3.X series.

MuratAl commented 5 years ago

Ok, after removing all my JNI Stuff and reimplementing it with all new APIs... My Project works now on older Devices too. My JNI implementation is the same... I just changed the APIs like UnityAds, AdMob, Google Play Services etc. I have also updated the Google Play App.