Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift crash/Obj-C warning when setting numerator on MIKMutableMIDIMetaTimeSignatureEvent #57

Closed
pwightman opened this issue Feb 25, 2015 · 3 comments
Assignees

Comments

@pwightman
Copy link
Contributor

The following Objective-C:

MIKMutableMIDIMetaTimeSignatureEvent *event = [[MIKMutableMIDIMetaTimeSignatureEvent alloc] init];
event.numerator = 4;

Yields the following warning in the console:

[NSConcreteMutableData replaceBytesInRange:withBytes:length:]: range {0, 1} exceeds data length 0

but does not crash. The following Swift:

let event = MIKMutableMIDIMetaTimeSignatureEvent()
event.numerator = UInt8(4)

Raises an NSRangeException:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSConcreteMutableData subdataWithRange:]: range {8, 4026531840} exceeds data length 0'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010ad36b95 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010c88bbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010ad36acd +[NSException raise:format:] + 205
    3   Foundation                          0x000000010b1812b7 -[NSData(NSData) subdataWithRange:] + 252
    4   MIKMIDI                             0x000000010cacb24d -[MIKMIDIMetaEvent metaData] + 237
    5   MIKMIDI                             0x000000010cacdb53 -[MIKMIDIMetaTimeSignatureEvent setNumerator:] + 243

The length of the range (4026531840) is different every time I run it.

MIKMutableMIDIMetaTimeSignatureEvent, MIKMIDIMetaTimeSignatureEvent and MIKMIDIMetaEvent all don't have constructors, so it falls all the way back to MIKMIDIEvent, and initializes as a NULL event type with empty internalData. So when it accesses metadata, its dataLength is a garbage value. Or at least I think that's what's going on.

@pwightman
Copy link
Contributor Author

So the Objective-C actually gets past the metadata call (where Swift is crashing) and warns about the next line.

@armadsen
Copy link
Member

Nice catch. I'll fix this tomorrow morning (if you don't get to it before me).

On Feb 24, 2015, at 10:08 PM, Parker notifications@github.com wrote:

So the Objective-C actually gets past the metadata call (where Swift is crashing) and warns about the next line.


Reply to this email directly or view it on GitHub.

@armadsen armadsen self-assigned this Feb 25, 2015
armadsen added a commit that referenced this issue Feb 25, 2015
…IDIEventSomeSubclass init] correct sets event type. Passing nil data to full initializer also works now.
armadsen added a commit that referenced this issue Feb 25, 2015
…y the minimum internal data size they require.
armadsen added a commit that referenced this issue Feb 25, 2015
armadsen added a commit that referenced this issue Feb 25, 2015
@armadsen
Copy link
Member

Should be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants