Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Error after camera:destroy()
Started by tharek.ali Sep 01 2016 03:55 AM

2 replies to this topic
perspective camera
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

tharek.ali

[GLOBAL: userInfoPane.html]
tharek.ali
  • Observer

  • 3 posts
  • Corona SDK

I am trying to create a reload function.

camera:destroy()
composer.gotoScene( "scenes.levels.1", { effect = "fade", time = 250 } )
composer.removeScene( name )

Then at the top:

camera = perspective.createView()

After I load the scene again I get this error message.

perspective.lua:201: attempt to call method 'insert' (a nil value)

I tried debugging and the problem is with the layer number:

function view:add(obj, l, isFocus)
        print(l)

The code works perfectly when creating the level the first time, but breaks when trying to restart level.

 

Thanks.



[TOPIC: post.html]
#2

tharek.ali

[GLOBAL: userInfoPane.html]
tharek.ali
  • Observer

  • 3 posts
  • Corona SDK

I tried

composer.removeScene( "scenes.levels.1" )
        composer.gotoScene( "scenes.levels.1", { effect = "fade", time = 250 } )

 and I get no errors, but most of screen has been overlapped by a blank square.



[TOPIC: post.html]
#3

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

Hi @tharek.ali, I think what may be happening is that you're deleting your camera when changing scenes but only creating it when building the scene. You'll need to put your camera construction code within one of your scene show code sections. By putting it at the top of your code, you're only building the camera when the scene is first loaded (say, the first time you go to it or after you explicitly remove it), but you're trying to use it every time. After :destroy(), the camera is just an empty shell that you can nil out. Trying to use it will result in errors because it's no longer functional.

local perspective = require("perspective")

local camera

function scene:show(event)
  if "will" == event.phase then
    camera = perspective.createView()
  end
end

-- Continue as normal

Let me know if that helps.

 

- Caleb




[topic_controls]
[/topic_controls]