HumbleSoftware / Flotr2

Graphs and Charts for Canvas in JavaScript.
http://www.humblesoftware.com/flotr2/
MIT License
2.44k stars 527 forks source link

Getting a Null pointer in initPlugins function #183

Closed niki4810 closed 11 years ago

niki4810 commented 11 years ago

Hi,

I am using flotr2.amd.js for one of my project and I am running into this issue where I am getting a NPE in the initPlugins function right where it is looping through plugin.callbacks object

            _.each( plugin.callbacks, function ( fn, c ) {
                this.observe( this.el, c, _.bind( fn, this ) );
            }, this );

When I debugged through this I found that when the plugin name is download, the plugin object does not have callbacks key defined and when its reaches this _.each loop its throwing an exception.

As a quick work around I added this code to fix it locally,

 if ( plugin.hasOwnProperty( "callbacks" ) ) {
            _.each( plugin.callbacks, function ( fn, c ) {
                this.observe( this.el, c, _.bind( fn, this ) );
            }, this );
        }

i.e to check if the plugin has a callbacks property defined and if so run through the loop. Not sure if its a correct way to solve this.

Could you please provide your comments/feedback on this ?

Thanks

niki4810 commented 11 years ago

I also aboserved similar behavior when the control reaches the setStyle function in the flotr2 library, where the second parameter o is being passed as undefined.

 setStyles: function(element, o) {
    _.each(o, function (value, key) {
      element.style[key] = value;
    });
  }
niki4810 commented 11 years ago

Ok, I think i've figured out this issue, I was using an older version of underscore which did not support looping though null objects, updating the underscore to a newer version, which did an explicit null check if (obj == null) return; resolved this issue. Sorry for the false alarm :)