Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

how to check for graphics existence ?
Started by d.mach Mar 18 2019 01:59 AM

- - - - -
10 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 846 posts
  • Corona SDK

I get some errors like this:

 

level.lua ERROR: ?:0: attempt to index field 'halloweenfx' (a nil value) on device: iPhone

 

And I have code like this:

           if gfx.halloweenfx and gfx.halloweenfx.timer then
                timer.cancel(gfx.halloweenfx.timer)
                gfx.halloweenfx.timer=nil
                display.remove(gfx.halloweenfx)
                gfx.halloweenfx=nil
            end

Now I wonder how I still can get the error? What am I missing here?

 

 



[TOPIC: post.html]
#2

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 770 posts
  • Corona SDK

its odd that you get an error on the "halloweenfx" field instead of "gfx.halloweenfx"



[TOPIC: post.html]
#3

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 846 posts
  • Corona SDK

I'm using an error listener with this code for the output:

analytics.logEvent( "level.lua ERROR: "..event.errorMessage.." on device: "..targetDevice )



[TOPIC: post.html]
#4

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 770 posts
  • Corona SDK

usually variable=nil errors are easy to track down



[TOPIC: post.html]
#5

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,787 posts
  • Corona SDK

What does event.stackTrace say?

[TOPIC: post.html]
#6

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 846 posts
  • Corona SDK

unfortunately I didn't use the event.stackTrace in the code. I will change this asap.

 

One more thing:

 

How can I locate an error like this:

level.lua ERROR: ?:0: attempt to index field '?' (a nil value) on device: iPhone

 

This seems impossible to track down. Is the stackTrace helping here also?



[TOPIC: post.html]
#7

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,787 posts
  • Corona SDK

Well the stack trace should give you a line number, but on device you may need to add neverStripDebugInfo = true to the settings > build table in build.settings.

[TOPIC: post.html]
#8

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 770 posts
  • Corona SDK

i use my own report function but it includes the code to get the line the error happens at.

perhaps it can be of use.

report(debug.getinfo(1).currentline.." : "..event.response)


[TOPIC: post.html]
#9

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,660 posts
  • Enterprise

Are there other places you are referencing gfx.halloweenfx that you're not checking if gfx.halloweenfx isn't nil before working with it? The lack of information for line numbers in the stack trace is pointing to it to happening is a library function than in your code. So look on places where you're passing gfx.halloweenfx to an API call.

 

It's basically saying that somewhere someone is looking for halloweenfx in gfx and it's not there.

 

Rob



[TOPIC: post.html]
#10

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 846 posts
  • Corona SDK

I'm creating it in another module. I already have checked this also but will do so again.

Should it be enough whenever I have to use the gfx.halloweenfx image to check first with something like:

if gfx.halloweenfx then
    -- do something with the image
end

Or is this not a safe check?



[TOPIC: post.html]
#11

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,660 posts
  • Enterprise

gfx.halloweenfx = "Fred", is a valid value, but it's not a display object. You can check to see:

if gfx and gfx.halloweenfx and gfx.halloweenfx.removeSelf then
    -- gfx is valid
    -- gfx.halloweenfx exists (not nil)
    -- gfx.halloweenfx.removeSelf is a display object method, so this is quite likely a display object.
    -- 
    -- do something with your display object.
end

Rob




[topic_controls]
[/topic_controls]