从不兼容的类型void分配浮动

时间:2013-06-05 15:55:31

标签: calloc cocos3d

这让我很生气。我不得不在实现CCNODE类的下一个赋值中进行GLfloat,该类在侧视图中模拟了watter(它来自我在cocos2dForum中找到的类) 更新:

-(id)initWithBounds:(CGRect)bounds count:(int)count damping:(float)damping diffusion:(float)diffusion;
{

    if((self = [super init])){
        _bounds = bounds;
        _count = count;
        _damping = damping;
        _diffusion = diffusion;

        _color = ccc4f(1.0f, 1.0f, 1.0f, 1.0f);

        _h1 = calloc(_count, sizeof(float));//Here 
        _h2 = calloc(_count, sizeof(float));// And here, is where I get the error.




        WaterTexture = [[CCTextureCache sharedTextureCache] addImage:@"watter.png"];
        //shader_ = [[CCShaderCache sharedShaderCache] programForKey:kCCShader_Position_uColor];
        shader_ = [[CCShaderCache sharedShaderCache] programForKey:kCCShader_PositionTexture];
        _textureLocation = glGetUniformLocation(shader_->_program, "u_texture");
        texturesize= 256*CC_CONTENT_SCALE_FACTOR();
        offset=0;

    }

    return self;
}

- (void)dealloc
{
free(_h1);
free(_h2);

[super dealloc];
}

此类在Cocos3d项目中实现。在添加Box2d库之前,所有工作正常,水被模拟,但在添加Box2D库之后,XCode开始抱怨说“从不兼容类型void向GLfloat转移” 为什么会这样?这真的很罕见...... 问候。 卡洛斯。

1 个答案:

答案 0 :(得分:1)

我假设_h1是CGFloat *或CGFloat []类型 - 如果它不是指针类型那么这是一个问题。另一件事是calloc返回void *所以你需要转换它的返回值:

_h1 = (CGFloat*)calloc(..);

添加Box2D后发生错误很可能是因为Objective-C ++的行为与Objective-C编译器不同,显然它在这种情况下不执行隐式转换,需要您手动添加转换。也许虽然编译器已经警告过你,但现在它被认为是一个错误(因此建议:永远不要忽视警告!)。

相关问题