google-code-export / bwip-js

Automatically exported from code.google.com/p/bwip-js
0 stars 0 forks source link

Getting rang error and script is stoped working #6

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.while generating barcode with backbone.js and ibm worklight.
2.I am to generate barcodoe for ean13 but facing problem with code 128
3.it is working fine with normal java script but facing issue with backbone.

What is the expected output? What do you see instead?
getting range error in google chrome and crashed with mozilla.

What version of the product are you using? On what operating system?
latest 0.5

Please provide any additional information below.

Original issue reported on code.google.com by rahuljmp...@gmail.com on 22 Oct 2013 at 2:15

GoogleCodeExporter commented 9 years ago
I am going to need a lot more details than what you have supplied.  Most 
importantly, is the issue reproducible using the demo?  If not, I do not know 
if I can be of assistance....

Are there particular code 128 options that cause the issue and others that do 
not cause it?  Can you supply a javascript stack trace from chrome dev tools? 

Original comment by mwar...@metafloor.com on 22 Oct 2013 at 11:35

GoogleCodeExporter commented 9 years ago
Hi,

Thanks for the response.

I checked with few of the other barcode types[ean13, ean8,code39, code one, 
aztec code,GS1-128 code 128] , but it is not generating for code 128 and  
GS1-128. For firefox it is crashed for these two barcode type.

PFB. the require config file.

require.config({
        paths: {
            jquery: 'js/libs/jquery/jquery',
            jquerymobile: 'js/libs/jquery/jquery.mobile-1.3.1',
            underscore: 'js/libs/underscore/underscore',
            backbone: 'js/libs/backbone/backbone',
            text: 'js/libs/require/text',
            'bwip': 'js/bwip'
                ,'symdesc':'js/symdesc'
                ,'needyoffset':'js/needyoffset'
                ,'canvas':'js/canvas'
                , 'renlinear': 'bwipp/renlinear'
                , 'renmatrix': 'bwipp/renmatrix'
                , 'renmaximatrix': 'bwipp/renmaximatrix'
                , 'code128': 'bwipp/code128'
                , 'hibccode128': 'bwipp/hibccode128'
                , 'hibcmicropdf417': 'bwipp/hibcmicropdf417'
                , 'hibcpdf417': 'bwipp/hibcpdf417'
                , 'micropdf417': 'bwipp/micropdf417'
                , 'pdf417': 'bwipp/pdf417'
                , 'azteccode': 'bwipp/azteccode'
                , 'hibcqrcode': 'bwipp/hibcqrcode'
                , 'qrcode': 'bwipp/qrcode'
        },
        shim: {
            underscore: {
                exports: '_'
            },
            backbone: {
                deps: [
                       'underscore',
                       'jquery'
                ],
                exports: 'Backbone'
            },
            'renlinear': { 'deps': [ 'bwip','symdesc','needyoffset','canvas'] }
            ,'renmatrix': { 'deps': [ 'bwip','symdesc','needyoffset','canvas' ] }
            ,'renmaximatrix': { 'deps': [ 'bwip','symdesc','needyoffset','canvas' ] }
            ,'code128': { 'deps': [ 'renlinear' ] }
            ,'hibccode128': { 'deps': [ 'renlinear' ] }
            ,'hibcmicropdf417': { 'deps': [ 'renmatrix' ] }
            ,'hibcpdf417': { 'deps': [ 'renmatrix' ] }
            ,'micropdf417': { 'deps': [ 'renmatrix' ] }
            ,'pdf417': { 'deps': [ 'renmatrix' ] }
            ,'azteccode': { 'deps': [ 'renmatrix' ] }
            ,'hibcqrcode': { 'deps': [ 'renmatrix' ] }
            ,'qrcode': { 'deps': [ 'renmatrix' ] }

        }
    }); 

In the view i am using the bwip and in render method i have hard coded for the 
code128 

define([
  'jquery',
  'jquerymobile',
  'underscore',
  'backbone',
  'code128', 'hibccode128', 'hibcmicropdf417', 'hibcpdf417', 'micropdf417', 'pdf417', 'azteccode', 'hibcqrcode', 'qrcode',
  'text!js/templates/hk/MainTemplate.html'
], function ($,jqm, _, 
Backbone,code128,hibccode128,hibcmicropdf417,hibcpdf417,micropdf417,pdf417,aztec
code,hibcqrcode,qrcode,hkTemplate) {

    var hkView = Backbone.View.extend({

        el: $("#page"),   
        PosTemplate: _.template(hkMainTemplate),

        initialize: function() {

        },

        events:{
            'click .menutab-div' :'displayPosDetails'
        },

        render: function() {

        this.$el.html(this.hkTemplate); 
        this.$el.trigger('create');

        },
        displayPosDetails: function(e) {
        var currentId= $(e.currentTarget).attr("id");   
        numbre=currentId.split('tab').join("");

        console.log(numbre);

        this.render1();
        $('.menutab-div').removeClass('highlighted-class');
        $('.arrow-image-order-number-pos').remove();

        $('#'+currentId).addClass('highlighted-class').append('<div class="arrow-image-order-number-pos"><img class="arrow-image-serachorder-draft" alt="" src="./images/draftorderarrow.png"></div>');

        },
      render1:  function () {
          var barcodetext="(01)95012345678903(3103)000123";
            var text1="";
            var text2="includetext parsefnc";
            /* alert('inside render'+$('#symbol')[0].selectedIndex+"<----------");
            var elt = symdesc[$('#symbol')[0].selectedIndex]; 
            alert('--->'+elt)
            alert('selected index render     '+elt.sym);*/
            var text = barcodetext.replace(/^\s+/,'').replace(/\s+$/,'');
            var altx = text1.replace(/^\s+/,'').replace(/\s+$/,'');
            var opts = text2.replace(/^\s+/,'').replace(/\s+$/,'');
            alert('before split '+opts);
            alert('alt text   '+ altx);
            var bw = new BWIPJS;

            // Convert the options to a dictionary object, so we can pass alttext with
            // spaces.
            var tmp = opts.split(' '); 
            alert('temp----'+tmp);
            opts = {};
            for (var i = 0; i < tmp.length; i++) {
                if (!tmp[i])
                    continue;
                var eq = tmp[i].indexOf('=');
                alert('inside for loop dl;fjs--->>>>'+eq);
                if (eq == -1)
                    opts[tmp[i]] = bw.value(true);
                else
                    opts[tmp[i].substr(0, eq)] = bw.value(tmp[i].substr(eq+1));
            }

            // Add the alternate text
            if (altx)
                opts.alttext = bw.value(altx);

            // Add any hard-coded options required to fix problems in the javascript
            // emulation. 
            opts.inkspread = bw.value(0);
            if (needyoffset['code128'] && !opts.textxalign && !opts.textyalign &&
                    !opts.alttext && opts.textyoffset === undefined)
                opts.textyoffset = bw.value(-10);
            /* alert('inside if'+elt.sym); */
            alert('ashdfkjsh----->>'+opts.textxalign);
            alert(opts.textyoffset+'<-----offset');
            var rot  = 'N';
            var rots = [ 'rotL', 'rotR', 'rotI' ];
            alert('rot-------->>>>>>>'+rot);
            /*for (var i = 0; i < rots.length; i++) {
                if (document.getElementById(rots[i]).checked) {
                    alert('inside if rot');
                    rot = rots[i].charAt(3);

                    break;
                }
            }*/

            bw.bitmap(new Bitmap);

            //var scl = parseInt(document.getElementById('scale').value, 10) || 2;
            bw.scale(3,3);

            var div = document.getElementById('output');
            if (div)
                div.innerHTML = '';

            bw.push(text);
            bw.push(opts);

            try {
            /*  alert(elt.sym); */
                bw.call('code128');
                //alert(bw.call(elt.sym));
                bw.bitmap().show('canvas', rot);
            } catch(e) {
                var s = '';
                if (e.fileName)
                    s += e.fileName + ' ';
                if (e.lineNumber)
                    s += '[line ' + e.lineNumber + '] ';
                alert(s + (s ? ': ' : '') + e.message);
            }
      }

    });
    return hkView;

});

Error Coming in Chrome

RangeError
1.  arguments: Array[0]
1.  length: 0
2.  __proto__: Array[0]
1.  concat: function concat() { [native code] }
2.  constructor: function Array() { [native code] }
3.  every: function every() { [native code] }
4.  filter: function filter() { [native code] }
5.  forEach: function forEach() { [native code] }
6.  indexOf: function indexOf() { [native code] }
7.  join: function join() { [native code] }
8.  lastIndexOf: function lastIndexOf() { [native code] }
9.  length: 0
10. map: function map() { [native code] }
11. pop: function pop() { [native code] }
12. push: function push() { [native code] }
13. reduce: function reduce() { [native code] }
14. reduceRight: function reduceRight() { [native code] }
15. reverse: function reverse() { [native code] }
16. shift: function shift() { [native code] }
17. slice: function slice() { [native code] }
18. some: function some() { [native code] }
19. sort: function sort() { [native code] }
20. splice: function splice() { [native code] }
21. toLocaleString: function toLocaleString() { [native code] }
22. toString: function toString() { [native code] }
23. unshift: function unshift() { [native code] }
24. __proto__: Object
2.  get message: function () { [native code] }
1.  arguments: null
2.  caller: null
3.  length: 0
4.  name: ""
5.  prototype: Object
6.  __proto__: function Empty() {}
3.  set message: function () { [native code] }
4.  stack: undefined
5.  type: "stack_overflow"
6.  __proto__: Error
1.  arguments: undefined
2.  constructor: function RangeError() { [native code] }
3.  name: "RangeError"
4.  stack: undefined
5.  type: undefined
6.  __proto__: SetUpError.d

But in mozilla it scripting is stop working.

Please Help.

Original comment by rahuljmp...@gmail.com on 23 Oct 2013 at 9:20

GoogleCodeExporter commented 9 years ago
I really need a stack trace to help debug this.  Something that gives line 
numbers and file names at the point where the RangeError occurs.  The 
object-dump above just enumerates the standard methods of Array and others.

I tested the bar text and options from your source code in the demo and it 
works without issue.

I recommend you put some `debugger;` traps at key points in bwipp/code128.js 
and walk through execution.  It will be a bit laborious, but it will let you 
home in on where the bug is occurring.

Without some solid details of the error or a way to reproduce in the demo, I 
cannot be of much help.

Original comment by mwar...@metafloor.com on 23 Oct 2013 at 2:54

GoogleCodeExporter commented 9 years ago
One more option to help debug the issue.  

Use stacktrace.js : http://stacktracejs.com/

See the second usage example "Custom Error Stack Traces" on the home page.  Use 
console.log() to display the stack trace and copy/paste into an issue thread 
here.

Original comment by mwar...@metafloor.com on 23 Oct 2013 at 3:03

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi,

In code128.js file -- I am getting these two values undefined--1>
1>this.dict[this.stk[this.ptr-2]]
2>this.stk[this.ptr-1])

Then  $f10() and $f12() calling recursively and getting alert stack exceeds the 
limit.
Please help me figure out these problem.

I am trying this thing with backbone.js and require.js.
PFB.
function $f5(){
        console.log("inside code 128 $f5 if b////////////////////");
        this.dict[this.stk[this.ptr-2]]=this.stk[this.ptr-1]; this.ptr-=2;
        console.log(this.dict[this.stk[this.ptr-2]]+" "+" "+this.stk[this.ptr-1]);
    }

inside code 128//////////////////// 
:10080/customerprofile/apps/services/preview/searchcustomer/common/0/default/bwi
pp/code128.js:17
inside code 128 $f5 if b//////////////////// 
:10080/customerprofile/apps/services/preview/searchcustomer/common/0/default/bwi
pp/code128.js:109
undefined  undefined 
:10080/customerprofile/apps/services/preview/searchcustomer/common/0/default/bwi
pp/code128.js:111
inside code 128 $f5 if b//////////////////// 
:10080/customerprofile/apps/services/preview/searchcustomer/common/0/default/bwi
pp/code128.js:109
undefined  undefined 
:10080/customerprofile/apps/services/preview/searchcustomer/common/0/default/bwi
pp/code128.js:111
inside code 128 $f5 if b//////////////////// 
:10080/customerprofile/apps/services/preview/searchcustomer/common/0/default/bwi
pp/code128.js:109
undefined  undefined 
:10080/customerprofile/apps/services/preview/searchcustomer/common/0/default/bwi
pp/code128.js:111
inside code 128 $f12  b//////////////////// 
:10080/customerprofile/apps/services/preview/searchcustomer/common/0/default/bwi
pp/code128.js:303
inside code 128 $f10 if b//////////////////// 

Original comment by rahuljmp...@gmail.com on 24 Oct 2013 at 1:11

GoogleCodeExporter commented 9 years ago
Unfortunately, that doesn't give me any real information to work with.  I 
really need a stack trace to understand how the code is getting to that 
particular point in the execution (debugging machine generated code can be very 
hard).

Please use stacktrace.js and add to the beginning of $f5(): 

if (this.stk[this.ptr-1] === undefined) {
  console.log(printStackTrace().join('\n\n'));
}

Original comment by mwar...@metafloor.com on 24 Oct 2013 at 4:02

GoogleCodeExporter commented 9 years ago
Hi,

i checked that thing it is not going inside if.

I write this "console.log(printStackTrace().join('\n\n'));" inside that 
function .

function $f5(){
         console.log(this.ptr1+"ILSDHHHHHHHHHHHHHHHHHHHHHHHHHHHH"+this.stk[this.ptr-1]);
         console.log(printStackTrace().join('\n\n'));
        if (this.stk[this.ptr-1] === undefined) {
            console.log("skdfhsdjfhsdkjfhsdjkfhsdjkfh inside if"+ this.stk[this.ptr-1]);
              console.log(printStackTrace().join('\n\n'));
            }
        this.dict[this.stk[this.ptr-2]]=this.stk[this.ptr-1]; this.ptr-=2;
    }

Three time I am getting this.stk[this.ptr-1]) as true then in forth time i am 
getting this value 0 and line no 732 of bwip.js(t[i] = this.gclone(o[i]) and 
too much recursion is coming in console of mozila  and script stopped working.

I am also attaching my dummy project.
-It is created in IBM worklight devloper edition and backbone js.

Original comment by rahuljmp...@gmail.com on 25 Oct 2013 at 4:42

Attachments:

GoogleCodeExporter commented 9 years ago
gclone() is part of the graphics context.  It does not get called (for code128) 
until renlinear is invoked at the very end.  The function $f5() that you said 
is where the bug happens is part of the options parsing logic, which occurs are 
the very start of the code128 call.  That doesn't make any sense.

I do not use worklight or backbone.  In order for me to help you, you need to 
provide a test case that shows the bug in the demo.  The demo can exercise 100% 
of the available functionality, so the bug should be reproducible there.

Original comment by mwar...@metafloor.com on 25 Oct 2013 at 5:24

GoogleCodeExporter commented 9 years ago
I believe this was a bug in the host embedding....

Original comment by mwar...@metafloor.com on 4 Apr 2014 at 12:47