Skip to content

Large MIDI files cause RangeError: Maximum call stack size exceeded when writing to bytes #35

Description

When writing a large midi file using File.prototype.toBytes(), an error is thrown::

/Users/me/node_modules/jsmidgen/lib/jsmidgen.js:122
			return String.fromCharCode.apply(null, byteArray);
			                           ^

RangeError: Maximum call stack size exceeded
    at Object.codes2Str (/Users/me/node_modules/jsmidgen/lib/jsmidgen.js:122:31)
    at /Users/me/node_modules/jsmidgen/lib/jsmidgen.js:658:18
    at Array.forEach (<anonymous>)
    at File.toBytes (/Users/me/node_modules/jsmidgen/lib/jsmidgen.js:657:15)
    at end (/Users/me/Desktop/mpp2midi/main.js:72:48)
    at ReadStream.<anonymous> (/Users/me/Desktop/mpp2midi/main.js:123:34)
    at emitOne (events.js:116:13)
    at ReadStream.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)

I personally solved it by replacing the following code

jsmidgen/lib/jsmidgen.js

Lines 121 to 123 in 97c1270

codes2Str: function(byteArray) {
return String.fromCharCode.apply(null, byteArray);
},

with this

		codes2Str: function(byteArray) {
			var string = "";
			byteArray.forEach(byte => string += String.fromCharCode(byte));
			return string;
		},

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions