Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1106473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:47:56+00:00 2026-05-17T01:47:56+00:00

I think I’m making just a fundamental mistake, but I cannot for the life

  • 0

I think I’m making just a fundamental mistake, but I cannot for the life of me see it.

I’m calling a method on an Objective-C object from within a C++ class (which is locked). I’m using NSInvocation to prevent me from having to write hundreds methods just to access the data in this other object.

These are the steps I’m going through. This is my first call, and I want to pass s2. I can’t really provide a compilable example, but hopefully it’s just a DUHRRRRR problem on my part.

float s2[3];
id args2s[] = {(id)&_start.x(),(id)&_start.y(),(id)&s2};
_view->_callPixMethod(@selector(convertPixX:pixY:toDICOMCoords:),3,args2s);

This is the View method being called

invokeUnion View::_callPixMethod(SEL method, int nArgs, id args[])
{
    DataModule* data;
    DataVisitor getdata(&data);
    getConfig()->accept(getdata);
    invokeUnion retVal;
    retVal.OBJC_ID = data->callPixMethod(_index, _datasetKey, method, nArgs, args);
    return retVal;
}

Invoke Union is a union so I can get the float value returned by NSInvocation.

union invokeUnion {
id OBJC_ID;
int intValue;
float floatValue;
bool boolValue;
};

This is the method in the data Object (pthread locked with lock() and unlock());

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

    lock();

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSMethodSignature *signature;
    NSInvocation *invocation;

    signature = [DCMPix instanceMethodSignatureForSelector:method];
    invocation = [NSInvocation invocationWithMethodSignature:signature];

    [invocation setSelector:method];
    [invocation setTarget:pix];

    if (nArgs > 0) for (int n = 0; n < nArgs; n++) {
        SFLog(@"invocation: i=%d, *ptr=0x%x, valf=%f, vald=%d",n,args[n],*args[n],*args[n]);
        [invocation setArgument:args[n] atIndex:2+n];
    }

    id retVal;

    [invocation invoke];
    [invocation getReturnValue:&retVal];

    [pool release];

    unlock();

    return retVal;
}

The method in the DCMPix object (which I can’t modify, it’s part of a library) is the following:

-(void) convertPixX: (float) x pixY: (float) y toDICOMCoords: (float*) d pixelCenter: (BOOL) pixelCenter
{
    if( pixelCenter)
    {
        x -= 0.5;
        y -= 0.5;
    }

    d[0] = originX + y*orientation[3]*pixelSpacingY + x*orientation[0]*pixelSpacingX;
    d[1] = originY + y*orientation[4]*pixelSpacingY + x*orientation[1]*pixelSpacingX;
    d[2] = originZ + y*orientation[5]*pixelSpacingY + x*orientation[2]*pixelSpacingX;
}

-(void) convertPixX: (float) x pixY: (float) y toDICOMCoords: (float*) d
{
    [self convertPixX: x pixY: y toDICOMCoords: d pixelCenter: YES];
}

It’s crashing when it tries to access d[0]. BAD_EXC_ACCESS which I know means it’s accessing released memory, or memory outside of it’s scope.

I’m getting lost keeping track of my pointers to pointers. the two float values come across fine (as does other info in other methods) but this is the only one asking for a float* as a parameter. From what I understand the convertPixX: method was converted over from a C program written for Mac OS 9… which is why it asks for the c-array as an out value… I think.

Anyway, any insight would be greatly appreciated.

I’ve tried sending the value like this:

float *s2 = new float[3];
void* ps2 = &s2;
id args2s[] = {(id)&_start.x(),(id)&_start.y(),(id)&ps2};
_view->_callPixMethod(@selector(convertPixX:pixY:toDICOMCoords:),3,args2s);

But that gives a SIGKILL – plus I’m sure it’s bogus and wrong. … but I tried.

anyway… pointers! cross-language! argh!

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:47:56+00:00Added an answer on May 17, 2026 at 1:47 am

    An array is not a pointer. Try adding the following line

    NSLog(@"%p, %p", s2, &s2);
    

    just above.

    id args2s[] = {(id)&_start.x(),(id)&_start.y(),(id)&s2};
    

    s2 and &s2 are both the address of the first float in your array, so when you do:

    [invocation setArgument:args[n] atIndex:2+n];
    

    for n = 2, you are not copying in a pointer to the first float, but the first float, possibly the first two floats if an id is 64 bits wide.

    Edit:

    To fix the issue, this might work (not tested).

    float s2[3];
    float* s2Pointer = s2;
    id args2s[] = {(id)&_start.x(),(id)&_start.y(),(id)&s2Pointer};
    _view->_callPixMethod(@selector(convertPixX:pixY:toDICOMCoords:),3,args2s);
    

    s2Pointer is a real pointer that will give you the double indirection you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I have a basic understanding of this, but am hoping that someone
I think this could be a very easy question for you. But I have
I think this has probably been asked, but after reading a lot, I'm not
I think that asking this might be kind of silly but I'm still wondering
I think it will be very hard for you to read the code but
i think this should be very easy , but i really don't know how
I think I need to create a specialist ObjectMapper and cannot find any sample
I think this is specific to IE 6.0 but... In JavaScript I add a
Think this is my target key in registry: [HKEY_CURRENT_USER\System\Majid\0] GUID=hex:60,de,2a,56,51,b2,e0,11,80,01,44,45,53,54,00,00 as you can see
I think I'm on to a good idea, but don't know how to implement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.