[Resolved] Ansca mobile still have not fixed this? This is serious!

A lot people seem to be having this problem and i still haven’t found a fix for it. I’ve searched all over the web. Maybe i’m just being a little shallow but i dont think Corona people have found a fix for this.

I am creating an instance of a display object, once that instance is created, i add to to my local display group. It works fine the first time i load that scene. But after game over or if i retry that scene, when i try to create the display object again, i get an insert error. The scene was completely purged() and removed() yet i keep getting an insert error.

Globals.lua:

TableOfBullets = {}  
TableOfBulletsIndex = 0  

BulletClass.lua:

function newBullet(Type, Muzzle, EndPoint, Damage)  
... some code   
 if(Type == "Normal") then  
 ThisBullet = display.newRect(Muzzle.x, Muzzle.y, 5, 20)   
 end  
... some more code  
 return ThisBullet  
  
 end  
  

Stage1:

function scene:createScene( event )  
 local Stage1DisplayGroup = self.view  
  
 -- HUD display layer for pause button, aiming cursor and text displays.  
 local HUD\_DisplayLayer = display.newGroup()  
  
 -- Game action layer for player, bullets, explosions and enemies.  
 local GameActionLayer = display.newGroup()  
  
... some code  
  
 local function checkActions()  
  
 if(PlayerIsTouchingTheScreen == true) then  
 local Fired = false  
 Fired = fireWeapon(MainCharacter, Weapons[GAMEINV\_EquipedWeapon])  
  
 -- If a bullet was fired.  
 if(Fired == true) then  
 -- Create the bullet  
 TableOfBullets[TableOfBulletsIndex] = newBullet("Normal", MainCharacter, EndOfBulletAim, Weapons[GAMEINV\_EquipedWeapon].DAMAGE)  
 GameActionLayer:insert(TableOfBullets[TableOfBulletsIndex])   
 TableOfBulletsIndex = TableOfBulletsIndex + 1  
  
 end   
  
 end  
  
 end  
  
... some more codes  
  
 -- Frame listener  
 Runtime:addEventListener("enterFrame", checkActions)  
  
 Stage1DisplayGroup:insert(GameActionLayer)  
 Stage1DisplayGroup:insert(HUD\_DisplayLayer)  
  
end  

On the first run everything is prefect but after Game over or if i pause and retry the stage, i get error. When i try to:
GameActionLayer:insert(TableOfBullets[TableOfBulletsIndex])

the error says: attempt to call method ‘insert’ ( a nil value)

Please what am i doing wrong? Or is this a known bug (which i doubt) [import]uid: 119483 topic_id: 35442 reply_id: 335442[/import]

I’m not sure exactly what is going on but based on what I see above, where are you doing the Runtime:addEventListener(“enterFrame”, checkActions) call? And… do you ever remove it when you’re exiting the scene or destroying the scene?

What I suspect is happening is that your checkActions function is getting called twice every frame and perhaps that’s doing something weird inside of checkActions. It fits the symptoms: runs first time, breaks 2nd time and you have removed the scene completely. Runtimes are not removed when scenes are purged/removed, only handlers on objects are removed.

[import]uid: 199310 topic_id: 35442 reply_id: 140842[/import]

i’m calling the Runtime:addEventListener(“enterFrame”, checkActions) inside scene:createScene().

let me try, removing the runtime and see what happens. [import]uid: 119483 topic_id: 35442 reply_id: 140843[/import]

Thanks Rob Mi. that did the trick. I never thought that runtimes weren’t removed from purge() or remove().

I guess i’ll now tell others who where having similar problem. [import]uid: 119483 topic_id: 35442 reply_id: 140846[/import]

really appreciate your help [import]uid: 119483 topic_id: 35442 reply_id: 140847[/import]

No problem! [import]uid: 199310 topic_id: 35442 reply_id: 140859[/import]

Bit of a sensational thread title… [import]uid: 33275 topic_id: 35442 reply_id: 140882[/import]

haha great title :slight_smile: [import]uid: 147488 topic_id: 35442 reply_id: 140883[/import]

I’m not sure exactly what is going on but based on what I see above, where are you doing the Runtime:addEventListener(“enterFrame”, checkActions) call? And… do you ever remove it when you’re exiting the scene or destroying the scene?

What I suspect is happening is that your checkActions function is getting called twice every frame and perhaps that’s doing something weird inside of checkActions. It fits the symptoms: runs first time, breaks 2nd time and you have removed the scene completely. Runtimes are not removed when scenes are purged/removed, only handlers on objects are removed.

[import]uid: 199310 topic_id: 35442 reply_id: 140842[/import]

i’m calling the Runtime:addEventListener(“enterFrame”, checkActions) inside scene:createScene().

let me try, removing the runtime and see what happens. [import]uid: 119483 topic_id: 35442 reply_id: 140843[/import]

Thanks Rob Mi. that did the trick. I never thought that runtimes weren’t removed from purge() or remove().

I guess i’ll now tell others who where having similar problem. [import]uid: 119483 topic_id: 35442 reply_id: 140846[/import]

really appreciate your help [import]uid: 119483 topic_id: 35442 reply_id: 140847[/import]

No problem! [import]uid: 199310 topic_id: 35442 reply_id: 140859[/import]

Bit of a sensational thread title… [import]uid: 33275 topic_id: 35442 reply_id: 140882[/import]

haha great title :slight_smile: [import]uid: 147488 topic_id: 35442 reply_id: 140883[/import]