Skip to content
This repository has been archived by the owner on Jun 19, 2019. It is now read-only.

@media queries throwing exception #24

Closed
dzindra opened this issue Dec 18, 2013 · 7 comments
Closed

@media queries throwing exception #24

dzindra opened this issue Dec 18, 2013 · 7 comments

Comments

@dzindra
Copy link
Contributor

dzindra commented Dec 18, 2013

First of all, I want to thank you for your hard work on this awesome project. I recently discovered that classy supports media queries, but following snippet of cas will throw exception when run on iPad (this also happens when using @media iphone and (version:<7.0) and removing @device iphone:

@device iphone {
    UILabel.label2 {
        @media (version: < 7.0) {
            text-color: #0f0;
        }
        @media (version: >= 7.0) {
            text-color: #00f;
        }
        font: HelveticaNeue 120;
    }
}

Stacktrace (line throwing exception is 106 in CASStyler.m, using 0.2.0 from cocapods):

2013-12-18 11:25:46.977 n42[15934:80b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM removeObjectAtIndex:]: index 3 beyond bounds [0 .. 2]'
*** First throw call stack:
(
    0   CoreFoundation                      0x020f25e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01e758b6 objc_exception_throw + 44
    2   CoreFoundation                      0x020936aa -[__NSArrayM removeObjectAtIndex:] + 442
    3   n42                                 0x0006fac3 __31-[CASStyler setFilePath:error:]_block_invoke + 515
    4   CoreFoundation                      0x0216f05d __53-[__NSArrayI enumerateObjectsWithOptions:usingBlock:]_block_invoke + 61
    5   CoreFoundation                      0x0216ef92 -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 258
    6   CoreFoundation                      0x020ec0a5 -[NSArray enumerateObjectsUsingBlock:] + 53
    7   n42                                 0x0006f215 -[CASStyler setFilePath:error:] + 1525
    8   n42                                 0x0006eba0 -[CASStyler setFilePath:] + 112
    9   n42                                 0x00077ce1 -[CASStyler setWatchFilePath:] + 129
@cloudkite
Copy link
Contributor

Thanks for reporting and including example and stack trace! Will look into it!

Also have been meaning to update the docs as there are a few hidden features :)

@cloudkite
Copy link
Contributor

@dzindra this should be fixed in the lastest commit 8174c44

Let me know if it resolves your issue, to get the very latest from github through cocoapods you can do

pod 'Classy', :head

@dzindra
Copy link
Contributor Author

dzindra commented Dec 19, 2013

@cloudkite thanks for quickly looking into this, but unfortunately, after adding :head, updating pods and cleaning the project the problem still persist.

I looked at the offending lines and I think that you can not call removeObjectAtIndex: while iterating copy of the array, because if you remove more than one object you will start removing invalid objects - indexes in copy will not be affected by removal but in the processed array indexes will change.

Maybe use some kind of filter function or add valid items to new mutable array? Using removeObject: instead of removeObjectAtIndex: is suboptimal but it fixes the issue.

@cloudkite
Copy link
Contributor

Ah yeah good point! Might be better to do by adding to new array as you suggested, will fix it up later today or if you would like to submit a pull request please feel free. thanks!

@dzindra
Copy link
Contributor Author

dzindra commented Dec 20, 2013

Sure, I'll send pull request in the morning.

@cloudkite
Copy link
Contributor

I had some free time so had a go at fixing it 76a8836
Also added a few new test cases using your example stylesheet

Let me know if you have any suggestions

@cloudkite
Copy link
Contributor

Fixed in v0.2.1 which should be in cocoapods soon

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

No branches or pull requests

2 participants