Forums » C++ Framework » Loading textures when coming in from a JNI Call »
| A Slushie | Loading textures when coming in from a JNI Call | ||
|---|---|---|---|
|
Added by A Slushie about 1 year ago
I'm running into an issue of something going wrong with my OpenGL context when coming "into" my C++ code from Java. I have this function which gets called fine from the Java.
void Java_org_cocos2dx_lib_Cocos2dxActivity_nativeShowQuitOverlay() {
CCScene* scene = CCDirector::sharedDirector()->getRunningScene();
scene->addChild(QuitOverlay::node());
}
And it makes it into the init().
bool QuitOverlay::init(void) {
if (!CCLayer::init()) {
return false;
}
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("sheetQuit.plist");
return true;
}
But it crashes on the line:
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("sheetQuit.plist");
With this error in LogCat: 04-05 02:34:07.846: E/libEGL(4935): call to OpenGL ES API with no current context (logged once per thread) It seems odd that I can utilize all of my app's other functions from JNI methods except when loading textures. If anyone knows a way around this or a solution to this issue it would be much appreciated. Thanks. |
||
| Minggo Zhang | RE: Loading textures when coming in from a JNI Call | ||
|
Added by Minggo Zhang about 1 year ago
Can not invoke opengl es functions in new thread. |
||
| Andre Rudlaff | RE: Loading textures when coming in from a JNI Call | ||
|
Added by Andre Rudlaff about 1 year ago
You can mot invoke OpenGL calls on a thread that does not have an OpenGL context. A far simpler solution would be to schedule an method on CCScheduler which then makes your GL calls during the next frame. |
||
| Timothy Zhang | RE: Loading textures when coming in from a JNI Call | ||
|
Added by Timothy Zhang about 1 year ago
is CCScheduler thread-safe? |
||
| zohar schwartz | RE: Loading textures when coming in from a JNI Call | ||
|
Added by zohar schwartz 8 months ago
you can instead invoke your function from a gl thread , like that :
{
when calling in java nativeShowQuitOverlay();
|
||
| zohar schwartz | RE: Loading textures when coming in from a JNI Call | ||
|
Added by zohar schwartz 8 months ago
sry meant @ mGLView.queueEvent(new Runnable()
{
|
||
| The Devil | RE: Loading textures when coming in from a JNI Call | ||
|
Any other way to do this? I am creating a sprite during a native c++ code call from Java and need to add it to a particular layer. |
(1-6/6)