Cocoanetics / DTCoreText

Methods to allow using HTML code with CoreText
BSD 2-Clause "Simplified" License
6.35k stars 1.18k forks source link

DTAttributedTextContentView will cause Zombie layer object crash when Using DTTiledLayerWithoutFade #1250

Open ximmyxiao opened 2 years ago

ximmyxiao commented 2 years ago

@odrobnik Can you do me a favour to look at this problem? This crash bothered my project for years , and I don't know how to fix it

the problem seems like when DTAttributedTextContentView 's layer is using DTTiledLayerWithoutFade, any subview added to DTAttributedTextContentView will be deallocated unexpected when the whole tableview deallocating . and this will cause some crash.

image

I reproduce the crash with the official example of DTCoreText, You guys can see the commit here: https://github.com/ximmyxiao/DTCoreText/commit/cbad674d10ff33fd5cce7c9d6ca5e19602a58f93

ximmyxiao commented 2 years ago

seems DTAttributedTextContentView emebed in TableViewCell is also a key point to crash

ximmyxiao commented 2 years ago

And I found this problem only exist in TableviewCells(or the view directly added as UITableView's subview) who got a DTAttributedTextContentView as its subview , and if this DTAttributedTextContentView has any subview , this subview's layer will be deallocated before the subview deallocated . so this makes the zombie happen

odrobnik commented 2 years ago

I guess you shouldn't use tiling inside table view cells!

ximmyxiao commented 2 years ago

@odrobnik But in DTAttributedTextContentView's layoutSubviews , there will be a warning about this

    if (!_isTiling && (self.bounds.size.width>1024.0 || self.bounds.size.height>1024.0))
    {
        if (![self.layer isKindOfClass:[CATiledLayer class]])
        {
            NSLog(@"Warning: A %@ with size %@ is using a non-tiled layer. Set the layer class to a CATiledLayer subclass with [DTAttributedTextContentView setLayerClass:[DTTiledLayerWithoutFade class]].", NSStringFromClass([self class]), NSStringFromCGSize(self.bounds.size));
        }
    }

And In my project the DTAttributedTextContentView 's size may bigger that 1024 often. may be this warning should be suggest that , if you are using DTAttributedTextContentView in a tableview cell , this warning can be omited?

odrobnik commented 2 years ago

That's from a long time ago. If you find that non-tiling works with greater view sizes, then you can increase the size and send a PR.

ximmyxiao commented 2 years ago

OK, I 'll test non-tiling mode in my project for a while , In fact , the HTML to be rendered in my project may contains many pictures( 100 + pictures,each of them got a file size bigger then 500K) , If it turns out that non-tiling works well for even this extreme situation , I will let you know and send a PR . . Thanks @odrobnik

odrobnik commented 2 years ago

@ximmyxiao what was the PR you wanted to suggest? Just to take out the warning?

ximmyxiao commented 2 years ago

@odrobnik YES,in my project I just omit this warning , maybe a variable indicated that this DTAttributedTextContentView is contained in the UITableView or not , and the warning will be generated on this variable . Both of these method seems not so beautiful maybe , What do you think is the best way to fix this

odrobnik commented 2 years ago

@ximmyxiao well, we can probably simple remove the warning. Or possibly put in a check if the view has a tableview in its super path to warn about tiling instead. i.e. inside a tableview cell, we warn if there is tiling, otherwise we warn if the view is large and there is no tiling.

ximmyxiao commented 2 years ago

@odrobnik OK, I have just just published my app with this change(omit the warning) , I 'll let you know if this change is good or not after one or two weeks

ximmyxiao commented 2 years ago

@odrobnik After watching my app in 2 weeks ,everything go well after 1 remove the using of DTTiledLayerWithoutFade 2 omit the warning . I think the new version of DTCoreText can do something similar change