Search code examples
iosobjective-cgpuimagexcode5.1

Value Conversion issue: Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int32_t' (aka 'int')


I have upgraded my Xcode version from 5.0 to 5.1 & started occuring below error in GPUImage Library GPUImageVideoCamera.m:301:54: Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int32_t' (aka 'int')

In below function on this line "connection.videoMaxFrameDuration = CMTimeMake(1, _frameRate);" error is occuring.

- (void)setFrameRate:(NSInteger)frameRate;
{

    _frameRate = frameRate;

    if (_frameRate > 0)
    {

        for (AVCaptureConnection *connection in videoOutput.connections)
        {

            if ([connection respondsToSelector:@selector(setVideoMinFrameDuration:)])

                connection.videoMinFrameDuration = CMTimeMake(1, _frameRate);

            if ([connection respondsToSelector:@selector(setVideoMaxFrameDuration:)])

                connection.videoMaxFrameDuration = CMTimeMake(1, _frameRate);

        }
    }

    else

    {
        for (AVCaptureConnection *connection in videoOutput.connections)

        {
            if ([connection respondsToSelector:@selector(setVideoMinFrameDuration:)])

                connection.videoMinFrameDuration = kCMTimeInvalid; 
                                // This sets videoMinFrameDuration back to default

            if ([connection respondsToSelector:@selector(setVideoMaxFrameDuration:)])

                connection.videoMaxFrameDuration = kCMTimeInvalid; 
                                // This sets videoMaxFrameDuration back to default

        }
    }
}

enter image description here


Solution

  • The problem is related with architecture. If you open your existing project in Xcode 5.1, It's default arch setting is 64-bit architectures.

    See this lines in Xcode 5.1 release nots

    Note: Be aware of the following architectures issues when opening your existing projects in Xcode 5.1:

    • When building for all architectures, remove any explicit architectures setting and use the default Standard Architectures setting. For projects that were previously opted-in using “Standard Architectures Including 64-Bit”, switch back to the “Standard architectures” setting.
    • When opening an existing project for the first time, Xcode 5.1 may display a warning about the use of the Xcode 5.0 architectures setting. Selecting the warning provides a workflow to revise the setting.
    • Projects not able to support 64-bit need to specifically set the architectures build setting to not include 64-bit.

    You can see this line in this apple's doc.

    NSInteger changes size in 64-bit code. The NSInteger type is used throughout Cocoa Touch; it is a 32-bit integer in the 32-bit runtime and a 64-bit integer in the 64-bit runtime. So when receiving information from a framework method that takes an NSInteger type, use the NSInteger type to hold the result.

    But int is a 32-bit integer, so only this arise this error. You can solve this problem by setting architecture to standard architecture including 64-bit or do simple type casting as below.

    connection.videoMinFrameDuration = CMTimeMake((int64_t)1, (int32_t)_frameRate);
    

    See CMTimeMake syntax.

    CMTime CMTimeMake (
       int64_t value,
       int32_t timescale
    );