0

Hooooookay 그래서 여기에 또 다른 문제 "나는 무슨 일이 일어나고 아무 생각이 없다"입니다. 각각의 후속 호출은, 그러나,NSObject의 PerformSelector 문제

또한 (엑스 코드 또는 뭔가 -nan(0x400000000)) 대신에 진정한 가치의 nan을 반환, 내가 nanSFLog 값 인쇄에 내 "디버그"라인을 넣어하지만 올바른 값을 반환하는 경우! 나는 (내가 설정 레벨에 따라하지 NSLog에 대한 정의 # 단지 인 - 특별한 것이) SFLog을 주석 경우 View에서 값이 isnan()에 의해 체포되지는 있지만 Window

WindowViewisnan()으로 체크 하나의 스레드에 앉아있는 동안 DataModuleDCMPix은 다른 스레드에 앉아 있습니다 (메인 스레드라고 생각합니다). DCMPix 또한 Core-Data 객체 (일부분은 fImage)에서 데이터를 가져옵니다.

void Window::PopUp() 
{ 
    // Grab the View from the Pipe Thread and cast it to my local namespace subclass View 
    View *view = static_cast< View* >(getPipe()->getView(event.context.view)); 

    float fullww = view->getFullWW(); 
    float fullwl = view->getFullWL(); 
    //SFLog(@"WindowLevel Window %f", wl); 

    // set SLider Values 
    if (!isnan(fullwl)){ 
     [[vc winLevel] setMinValue:fullwl]; 
     [[vc winLevel] setMaxValue:(-1.0f*fullwl)]; 
    } 
} 


float View::getFullWL() 
{ 
    float wl = _callPixMethod(@selector(fullwl)).floatValue; 
    if (isnan(wl)) wl = _wl * 2.0f; //<-- is never detected as NaN here 
    //SFLog(@"WindowLevel View %f", wl); //<-- but is *printed* as NaN here 
    return wl; 
} 

// A Union to "cast" the return from the [object performSelector:] method. 
// Since it returns `id` and (float)(id) doesn't work. 
union performReturn { 
    id OBJC_ID; 
    int intValue; 
    float floatValue; 
    bool boolValue; 
}; 


performReturn View::_callPixMethod(SEL method) 
{ 
    DataModule* data; 
    DataVisitor getdata(&data); 
    getConfig()->accept(getdata); 
    performReturn retVal; 
    retVal.OBJC_ID = data->callPixMethod(_datasetIndex, _datasetID, method); 
    return retVal; 
} 


id DataModule::callPixMethod(int index, std::string predicate, SEL method) 
{ 
    DCMPix *pix =[[getSeriesData(predicate) pixList_] objectAtIndex:index]; 

    pthread_mutex_lock(&_mutex); 

    id retVal = [pix performSelector:method]; 

    pthread_mutex_unlock(&_mutex); 

    return retVal; 
} 

// DCMPix.m (from API, can't change) 
- (float) fullwl 
{ 
if(fullww == 0 && fullwl == 0) [self computePixMinPixMax]; 
return fullwl; 
} 

- (void)computePixMinPixMax 
{ 
    float pixmin, pixmax; 

    if(fImage == nil || width * height <= 0) return; 

    [checking lock]; 

    @try 
    { 
     if(isRGB) 
     { 
      pixmax = 255; 
      pixmin = 0; 
     } 
     else 
     { 
      float fmin, fmax; 

      vDSP_minv (fImage, 1, &fmin, width * height); 
      vDSP_maxv (fImage , 1, &fmax, width * height); 

      pixmax = fmax; 
      pixmin = fmin; 

      if(pixmin == pixmax) 
      { 
       pixmax = pixmin + 20; 
      } 
     } 

     fullwl = pixmin + (pixmax - pixmin)/2; 
     fullww = (pixmax - pixmin); 
    } 
    @catch (NSException * e) 
    { 
     NSLog(@"***** exception in %s: %@", __PRETTY_FUNCTION__, e); 
    } 

    [checking unlock]; 
} 

도움말! Window에서 올바른 값을 얻지 못하는 이유는 무엇입니까?

동일한 실행 경로를 따르더라도 view->getFullWW()을 호출 할 때 nan도 호출되지 않습니다. (하지만 @selector(fullww))

아니요 오류나 예외가 발생합니다. 그 기괴한 행동.

감사합니다. 가 발생 하였을 때 나는 NSLog를 어디다

float View::getFullWL() 
{ 
    float wl = _callPixMethod(@selector(fullwl)).floatValue; 
    if (isnan(wl)) wl = _wl * 2.0f; //<-- is never detected as NaN here 
    NSLog(@"WindowLevel View %f", wl); //<-- is *printed* as NaN here 
    return wl; //<-- returns expected value 
} 

float View::getFullWL() 
{ 
    float wl = _callPixMethod(@selector(fullwl)).floatValue; 
    if (isnan(wl)) wl = _wl * 2.0f; //<-- is never detected as NaN here 
    return wl; //<-- returns `nan` 
} 
더 많은 테스트 후

, 그것은 (중요하지 않습니다) 문 : 추가 테스트 후


는 다음과 같은 변화는 모든 차이를 만드는 float fullwl =이 할당되기 전에

void Window::PopUp() 
{ 
    // Grab the View from the Pipe Thread and cast it to my local namespace subclass View 
    View *view = static_cast< View* >(getPipe()->getView(event.context.view)); 

    float fullww = view->getFullWW(); 
    NSLog("Putting this here, makes fullwl work. Removing it, stores fullwl as nan"); 
    float fullwl = view->getFullWL(); 
    //SFLog(@"WindowLevel Window %f", wl); 

답변

1

새끼, 여기에 다시을 내 자신의 질문 에 대답하고 있지만 대답은 ... RTFM입니다.

aSelector 인수는 인수를 취하지 않는 메서드를 식별해야합니다. 객체 이외의 것을 반환하는 메서드의 경우 NSInvocation을 사용합니다.

그래서 대답은 사용 NSInvocation하지 [obj performSelector:]

관련 문제