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

dispatch_main_async_safe(callCompletedBlockClosure);崩溃 #3717

Open
Gx952743985 opened this issue Jun 5, 2024 · 8 comments
Open

dispatch_main_async_safe(callCompletedBlockClosure);崩溃 #3717

Gx952743985 opened this issue Jun 5, 2024 · 8 comments

Comments

@Gx952743985
Copy link

Uploading Snipaste_2024-06-05_09-17-18.p <img width="1441" alt="Snipaste_2024-06-05_09-17-42" src="https://github.com/SDWebImage/SDWebImage/assets/16395032/70d44564-f865-4aff-9e51-7e6f9a09d4cd"> ng…

@Gx952743985
Copy link
Author

Snipaste_2024-06-05_09-17-18

@Gx952743985
Copy link
Author

Snipaste_2024-06-05_09-17-42

@dreampiggy
Copy link
Contributor

dreampiggy commented Jun 5, 2024

dispatch_group_enter/dispatch_group_leave is your App code, not SDWebImage's code

You can not (currently) assume each sd_setImage call must always callback. So the enter and leave may not get balanced. I guess this is a bug, but need more info to investigate

@Gx952743985
Copy link
Author

这个错误我也捕捉不到,我也是根据崩溃反馈,所拿到的崩溃在sebwebimg里面了,求大佬指点
Snipaste_2024-06-09_14-31-10

@Gx952743985
Copy link
Author

Snipaste_2024-06-09_14-32-36

@Gx952743985
Copy link
Author

Snipaste_2024-06-09_14-58-33

@Gx952743985
Copy link
Author

#import "NK_MicIconsView.h"

@implementation NK_MicIconsView

  • (void)setCellData:(NK_ChatMsgModel *)nk_model finished:(void (^)(CGFloat totalW))finished{

    if (nk_model.enter_user_type == 1) {
    _userTypeImgV.image = kImageNamed(@"room_mic_fang");
    }else if (nk_model.enter_user_type == 2) {
    _userTypeImgV.image = kImageNamed(@"room_mic_guan");
    }else if (nk_model.enter_user_type == 3) {
    _userTypeImgV.image = kImageNamed(@"room_mic_chao");
    }else {
    _userTypeImgV.image = nil;
    }

    _jwImgVWC.constant = 0;

    _vipImgVLeftCon.constant = 0;
    _vipImgVWC.constant = 0;

    _gxImgVLeftCon.constant = 0;
    _gxImgVWC.constant = 0;

    _mlImgVLeftCon.constant = 0;
    _mlImgVWC.constant = 0;

    _expLevlImgVLeftCon.constant = 0;
    _expLevlImgVWC.constant = 0;

    _userImgVLeftCon.constant = 0;

    dispatch_group_t group = dispatch_group_create();

    WEAK_SELF
    __block CGFloat totalW = 0;
    if (nk_model.nobility_image.length > 0) {
    dispatch_group_enter(group);
    [_jueweiImgV nk_setImageWithURL:kURL(nk_model.nobility_image) completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
    if (image){
    CGSize size = image.size;
    CGFloat h = size.height>0 ? size.height : 1;
    CGFloat newW = size.width/h * 24;
    nk_weakSelf.jwImgVWC.constant = newW;
    totalW += (newW+5);
    }
    dispatch_group_leave(group);
    }];
    }

    if (nk_model.vip_level_image.length > 0) {
    _vipImgVLeftCon.constant = 5;
    dispatch_group_enter(group);
    [_vipImgV nk_setImageWithURL:kURL(nk_model.vip_level_image) completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
    if (image){
    CGSize size = image.size;
    CGFloat h = size.height>0 ? size.height : 1;
    CGFloat newW = size.width/h * 20;
    nk_weakSelf.vipImgVWC.constant = newW;
    totalW += (newW+5);
    }
    dispatch_group_leave(group);
    }];

    }

    if (nk_model.contribution_level_image.length > 0) {
    _gxImgVLeftCon.constant = 5;
    _gxImgVWC.constant = 20;
    dispatch_group_enter(group);
    [_gxImgV nk_setImageWithURL:kURL(nk_model.contribution_level_image) completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
    if (image){
    CGSize size = image.size;
    CGFloat h = size.height>0 ? size.height : 1;
    CGFloat newW = size.width/h * 20;
    nk_weakSelf.gxImgVWC.constant = newW;
    totalW += (newW+5);
    }
    dispatch_group_leave(group);
    }];

    }

    if (nk_model.charm_level_image.length > 0) {
    _mlImgVLeftCon.constant = 5;
    dispatch_group_enter(group);

      [_mlImgV nk_setImageWithURL:kURL(nk_model.charm_level_image) completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
          if (image){
              CGSize size = image.size;
              CGFloat h = size.height>0 ? size.height : 1;
              CGFloat newW = size.width/h * 20;
              nk_weakSelf.mlImgVWC.constant = newW;
              totalW += (newW+5);
          }
          dispatch_group_leave(group);
      }];
    

    }

    if (nk_model.exp_level_image.length > 0) {
    _expLevlImgVLeftCon.constant = 5;
    dispatch_group_enter(group);

      [_expLevlImgV nk_setImageWithURL:kURL(nk_model.exp_level_image) completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
          if (image){
              CGSize size = image.size;
              CGFloat h = size.height>0 ? size.height : 1;
              CGFloat newW = size.width/h * 20;
              nk_weakSelf.expLevlImgVWC.constant = newW;
              totalW += (newW+5);
          }
          dispatch_group_leave(group);
    
      }];
    

    }

    if (nk_model.enter_user_type == 1 || nk_model.enter_user_type == 2 || nk_model.enter_user_type == 3) {
    totalW += 25;
    _userImgVLeftCon.constant = 5;
    _userImgVWC.constant = 20;
    }

    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
    if (finished){
    finished(totalW);
    }
    // MYLog(@"--------totalW--------%.2f",totalW);
    [self mas_updateConstraints:^(MASConstraintMaker *nk_make) {
    nk_make.width.mas_equalTo(totalW);
    }];
    });
    }

@EnD

@ipad4
Copy link

ipad4 commented Jun 12, 2024

dispatch_group_enter/dispatch_group_leave is your App code, not SDWebImage's code

You can not (currently) assume each sd_setImage call must always callback. So the enter and leave may not get balanced. I guess this is a bug, but need more info to investigate

If dispatch_group_enter/dispatch_group_leave cannot be used, how to achieve similar requirements?

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

3 participants