不能填写故障错误,可能与ARC有关

时间:2012-05-21 09:00:54

标签: objective-c automatic-ref-counting xcode4.3 fault

我有一个包含名为currentBusiness

的变量的单例

我像这样连接了currentBusiness属性

-(Business *) currentBusiness
{
    if ([[NSThread currentThread] isMainThread])
    {
        DLog(@"I am a main thread");
    }
    else
    {
        assert (false);
        DLog(@"I am not a main thread");
    }

    CLog(@"_currentBusiness %@ withObjectID: %@", _currentBusiness, _currentBusiness.objectID);

    if (IsEmpty(_currentBusiness))
    {
        //assert(false);
    }
    if (_currentBusiness.isFault)
    {
        assert(false); //This is reached
    }
    return _currentBusiness;
}

另外,我把一个业务类别陷阱陷阱

- (void)willTurnIntoFault
{
    if ([[NSThread currentThread] isMainThread])
    {
        CLog(@"Faulting: %@", self); //called sometimes and during time of interest never called
        if (self == [BNUtilitiesQuick currentBusiness])
        {
            CLog(@"Current Business is Faulting");//never called
        }
    }

    [super willTurnIntoFault];
}

所以,起初一切都很好。正如所料[BNUtilities currentBusiness]为视图控制器提供必要的信息。但是,在随机(虽然几乎可以肯定)的位置,如果我改变视图,说我想激活调用(使用简单的代码)。突然

    if (_currentBusiness.isFault)
    {
        assert(false); //This is reached
    }

我知道什么都不会改变_currentBusiness。基础业务不会被删除。

我还把tripwire放在

-(void) setCurrentBusiness:(Business *)currentBusiness
{
    if ([[NSThread currentThread] isMainThread])
    {
        DLog(@"I am a main thread");
    }
    else
    {
        assert (false);
        DLog(@"I am not a main thread");
    }
    _currentBusiness = currentBusiness;
}

并注意到它未到达。所以_currentBusiness,无处不在突然变得错误

这是_currentBusiness

的“正常”内容
2012-05-21 15:42:24.952 BadgerNew[2292:17003] <0x87909a0 UtilitiesQuick.m:(69)> _currentBusiness <Business: 0x96a8980> (entity: Business; id: 0x9683b30 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Business/p15> ; data: {
    Aliases = "<relationship fault: 0x96b8540 'Aliases'>";
    Bookmark = 0;
    Building = "0x9683b30 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Business/p15>";
    City = "0x9694880 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/City/p2>";
    Distance = "689.0068307560858";
    DistanceGrouping = "0x96b9b90 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/DistanceGrouping/p890>";
    Districts =     (
        "0x92a6450 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/District/p4>"
    );
    Email = nil;
    ID = "universitas-indonusa-esa-unggul__-6.19_106.78";
    Images =     (
        "0x93edb50 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Image/p20>"
    );
    InBuildingAddress = nil;
    LatitudeLongitude = "0x96bd6a0 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/LatitudeLongitude/p15>";
    Like = 0;
    OpeningHour = nil;
    PeopleCount = 295;
    Phones =     (
        "0x92dcbf0 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Phone/p4>"
    );
    Price = 0;
    Promotions = "<relationship fault: 0x9693480 'Promotions'>";
    Rating = "0x96a0f00 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Rating/p15>";
    RatingGroup = "0x9682bd0 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/RatingGroup/p15>";
    Reviews =     (
    );
    Street = "Jl. Arjuna Utara";
    Tags =     (
        "0x92b5c10 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Tag/p12>"
    );
    Tenants = "<relationship fault: 0x96e6fd0 'Tenants'>";
    TimeStamp = nil;
    Title = "Universitas Indonusa Esa Unggul";
    URLs = "<relationship fault: 0x968d930 'URLs'>";
    Website = nil;
    Zip = 11510;
    checkIn = nil;
    pinAndLineNumber = 2;
    timeLike = nil;
    updated = 1;
})

当它出现故障并在

处休息时
    if (_currentBusiness.isFault)
    {
        assert(false); //This is reached
    }

结果如下:

2012-05-21 15:42:36.782 BadgerNew[2292:17003] <0x87909a0 UtilitiesQuick.m:(69)> _currentBusiness <Business: 0x96a8980> (entity: Business; id: 0x9683b30 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Business/p15> ; data: <fault>)

所以我做了一些po和

(lldb) po [_currentBusiness objectID]
error: warning: couldn't get required object pointer (substituting NULL): Couldn't load 'self' because its type is unknown
warning: couldn't get object pointer (substituting NULL): Couldn't load '_cmd' because its type is unknown
Execution was interrupted, reason: Attempted to dereference an invalid pointer..
The process has been returned to the state before execution.

好像_currentBusiness的内容已经改变了。 current_Business仍在那里。它仍然具有相同的地址。

到底是怎么回事?

不,这不仅仅是错误。这是一个无法摆脱的错误。

所以我添加了更多的tripwire

-(Business *) currentBusiness
{
    if ([[NSThread currentThread] isMainThread])
    {
        DLog(@"I am a main thread");
    }
    else
    {
        assert (false);
        DLog(@"I am not a main thread");
    }

    CLog(@"_currentBusiness %@ withObjectID: %@", _currentBusiness, _currentBusiness.objectID); //add ObjectID

    if (IsEmpty(_currentBusiness))
    {
        //assert(false);
    }
    if (_currentBusiness.isFault)
    {
        CLog(@"_currentBusiness.Title %@", _currentBusiness.Title); //Try to unfault
        assert(false);
    }
    return _currentBusiness;
}

我打赌我无法解决。

所以这就是结果:

2012-05-21 16:08:37.950 BadgerNew[2625:17003] <0x9510470 UtilitiesQuick.m:(69)> _currentBusiness <Business: 0x9589410> (entity: Business; id: 0x95889d0 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Business/p15> ; data: {
    Aliases = "<relationship fault: 0x953cdf0 'Aliases'>";
    Bookmark = 0;
    Building = "0x95889d0 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Business/p15>";
    City = "0x958dde0 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/City/p2>";
    Distance = "689.0068307560858";
    DistanceGrouping = "0x9582f40 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/DistanceGrouping/p924>";
    Districts =     (
        "0x874b0d0 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/District/p4>"
    );
    Email = nil;
    ID = "universitas-indonusa-esa-unggul__-6.19_106.78";
    Images =     (
        "0x95c4be0 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Image/p20>"
    );
    InBuildingAddress = nil;
    LatitudeLongitude = "0x958f430 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/LatitudeLongitude/p15>";
    Like = 0;
    OpeningHour = nil;
    PeopleCount = 295;
    Phones =     (
        "0x9237680 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Phone/p4>"
    );
    Price = 0;
    Promotions = "<relationship fault: 0x954bae0 'Promotions'>";
    Rating = "0x9584b50 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Rating/p15>";
    RatingGroup = "0x9586970 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/RatingGroup/p15>";
    Reviews =     (
    );
    Street = "Jl. Arjuna Utara";
    Tags =     (
        "0x8769120 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Tag/p12>"
    );
    Tenants = "<relationship fault: 0x955fd90 'Tenants'>";
    TimeStamp = nil;
    Title = "Universitas Indonusa Esa Unggul";
    URLs = "<relationship fault: 0x955f620 'URLs'>";
    Website = nil;
    Zip = 11510;
    checkIn = nil;
    pinAndLineNumber = 2;
    timeLike = nil;
    updated = 1;
}) withObjectID: 0x95889d0 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Business/p15>

然后

2012-05-21 16:08:42.797 BadgerNew[2625:17003] <0x9510470 UtilitiesQuick.m:(69)> _currentBusiness <Business: 0x9589410> (entity: Business; id: 0x95889d0 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Business/p15> ; data: <fault>) withObjectID: 0x95889d0 <x-coredata://3993C454-9EE9-4EDC-B1FD-7073A9CEC194/Business/p15>
2012-05-21 16:08:42.797 BadgerNew[2625:17003] <0x9510470 UtilitiesQuick.m:(77)> _currentBusiness.Title (null)
(lldb) po [_currentBusiness objectID]
error: warning: couldn't get required object pointer (substituting NULL): Couldn't load 'self' because its type is unknown
warning: couldn't get object pointer (substituting NULL): Couldn't load '_cmd' because its type is unknown
Execution was interrupted, reason: Attempted to dereference an invalid pointer..
The process has been returned to the state before execution.

因此_currentBusiness的地址不会改变。 objectID不会改变。不知怎的,它变成了错误。同时调用_currentBusiness.Title会导致(null)

这似乎不是在ARC更新之前发生的,虽然我不确定ARC是否引起了它。

1 个答案:

答案 0 :(得分:0)

我已经发现了问题。每次调用托管对象上下文时都会重新创建它。愚蠢的错误。我会把它作为一个答案,所以如果有人有同样的问题,他们应该首先看一下。

托管对象上下文通常是延迟加载的。