cocos2d-html5 icon indicating copy to clipboard operation
cocos2d-html5 copied to clipboard

Fix variable check for non-null & clean up

Open PimsJay01 opened this issue 6 years ago • 0 comments

I use function getTileAt of TMXLayer who accept as parameter a cc.Point or 2 integers. I found a bug present in almost every getters of class TMXLayer. If two integers are passed to function and x is equal to 0, function throw error "cc.TMXLayer.getTileAt(): pos should be non-null". Indeed, function to filter value was :

getTileAt: function (pos, y) {
    if (!pos) {
        throw new Error("cc.TMXLayer.getTileAt(): pos should be non-null");
    }
    ...
}

this check return true if :

  • null
  • undefined
  • NaN
  • empty string ("")
  • 0
  • false

I suppose that only null or undefined values have to throw error. So I suggest to change check as if(pos == null)

I also took the liberty to change every if(pos === undefined) by if(pos == null) to filter undefined and null values.

Is there any test for this class ?

PimsJay01 avatar Aug 06 '18 16:08 PimsJay01