sourcemars / cocos2d-android-1

Automatically exported from code.google.com/p/cocos2d-android-1
0 stars 0 forks source link

Null Pointer Exception when CCQuadParticleSystem #29

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create new project based on template.
2. Create scene and add CCQuadParticleSystem to it inside of the onCreate 
method of the activity
3. Null Pointer Exception when application starts

This is because CCQuadParticle system attempts to access the CCDirector.gl 
object before it is assigned. The constructor is called before 
onSurfaceViewCreated() is called inside the director.

What is the expected output? What do you see instead?
Should be able to initialize without error as sprites do.

Actual result is:
12-17 18:17:39.608: ERROR/AndroidRuntime(9276): java.lang.NullPointerException
12-17 18:17:39.608: ERROR/AndroidRuntime(9276):     at 
org.cocos2d.particlesystem.CCQuadParticleSystem.<init>(CCQuadParticleSystem.java
:68)

What version of the product are you using? On what operating system?
Latest from source.

Please provide any additional information below.
Particle system works fine when added outside of constructors.

Original issue reported on code.google.com by ghemp...@gmail.com on 18 Dec 2010 at 2:24

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I will try that later today. For the time being I just put in a splash scene 
before I load the game scene.

BTW, you are awesome for creating this project and putting the time in to port 
the latest version of cocos2d to android. Definitely the best game 2d lib for 
android!

Original comment by ghemp...@gmail.com on 19 Dec 2010 at 8:39

GoogleCodeExporter commented 8 years ago
This looks like here we need to implement deffered call too as in Texture2D, 
I'll try to fix this soon.

Original comment by opengen...@gmail.com on 19 Dec 2010 at 9:17

GoogleCodeExporter commented 8 years ago
I made some changes, hava a try.

Original comment by opengen...@gmail.com on 19 Dec 2010 at 10:15

GoogleCodeExporter commented 8 years ago
Yep runs without issues now. Thanks!

Original comment by ghemp...@gmail.com on 20 Dec 2010 at 2:42

GoogleCodeExporter commented 8 years ago
Actually, this now ONLY works when done in the constructor. When I add a splash 
scene before the scene with the CCQuadParticle instance it doesn't work anymore.

Original comment by ghemp...@gmail.com on 20 Dec 2010 at 5:32

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Previous version is in master now, please post more, I need to reproduce the 
problem somehow. Where is your not in constructor? and stack trace too, please.

Original comment by opengen...@gmail.com on 20 Dec 2010 at 11:37

GoogleCodeExporter commented 8 years ago
I've attached  project which contains the issue. It is basically just a simple 
scene with a CCParticleMeteor created after 5 seconds. This won't work after 
the fix was added, but did work before (and now since you reverted). If you 
change it so that the CCParticleMeteor is created immediately it works with the 
fix.

Original comment by ghemp...@gmail.com on 20 Dec 2010 at 1:49

Attachments:

GoogleCodeExporter commented 8 years ago
OK, thanks, I'll take a look.

Original comment by opengen...@gmail.com on 20 Dec 2010 at 7:22

GoogleCodeExporter commented 8 years ago
Try now.

Original comment by opengen...@gmail.com on 20 Dec 2010 at 11:25

GoogleCodeExporter commented 8 years ago
We had/have the same problem, even with the latest version, but I found a fix, 
not sure if this is correct.

In CCDirector::drawCCScene(),
the tick/update function of each node is called. There we make a 
SceneTransition.

Now, CCDirector::drawCCScence() continues and call GLResourceHelper.update to 
load for example the particle buffers (at this time no particle effects have 
been created)

Now, CCDirector::drawCCScene actually recognizes the SceneTranstition by 
checking nextCCScene and creates the new scene which in our case calls its 
constructors in which we load particle effects.

Now, CCDirector::drawCCScene calls the visit function and tries to draw the not 
yet GL loaded particle effect.

We can fix this by moving  GLResourceHelper.sharedHelper().update(gl);
right after 

if( nextCCScene_ != null)
        setNextScene();

Hope this helps...

Original comment by oonneett...@gmail.com on 21 Dec 2010 at 8:12

GoogleCodeExporter commented 8 years ago
Thanks, fixed and pushed.

Original comment by opengen...@gmail.com on 21 Dec 2010 at 8:45

GoogleCodeExporter commented 8 years ago
Hello, I'm trying to develop a cross platform game using Cocos2d-X for IOS and 
cocos2d-android-1 for android. I have a .plist file which is working just fine 
with IOS but with cocos2d-android-1 I just keep getting NULL exceptions when I 
try to use CCQuadParticleSystem. Yes, I'm using it outside of CTORs as 
instructed here.

I tried this in a test class extending CCLayer:

@Override
public boolean ccTouchesEnded(MotionEvent event) {

CGPoint location = 
CCDirector.sharedDirector().convertToGL(CGPoint.ccp(event.getX(), 
event.getY()));

CCQuadParticleSystem p = (CCQuadParticleSystem) 
CCQuadParticleSystem.particleWithFile("fire.plist");

if (p==null)
   // failed !
   return true;

p.setPosition(location);
p.resetSystem();        

return true;
}

It just doesn't work. I don't get it. Everything else but this is working 
great, so can anybody please tell me what I am doing wrong ?!

Original comment by AmitFark...@gmail.com on 2 May 2013 at 5:51