Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ccConfig.h CC_CONSTRUCTOR_ACCESS is public #13678

Closed
Almax27 opened this issue Sep 3, 2015 · 5 comments
Closed

ccConfig.h CC_CONSTRUCTOR_ACCESS is public #13678

Almax27 opened this issue Sep 3, 2015 · 5 comments

Comments

@Almax27
Copy link
Contributor

Almax27 commented Sep 3, 2015

CC_CONSTRUCTOR_ACCESS comment says default is 'protected', as it should be given the create() paradigm. However the default value is 'public', and was changed to aid binding Sprite3D. Perhaps if Sprite3D is an edge case it should not use the macro?

https://github.com/cocos2d/cocos2d-x/blob/v3/cocos/base/ccConfig.h

Last related change: f4b5751

@pandamicro
Copy link
Contributor

In fact, it helps with all the classes for JS bindings, if you don't write your game in JS, you can turn it into protected, it won't affect anything. But in JSB, the value must be public.

As we merged Cocos2d-JS into Cocos2d-x in v3.7, this is obligated.

@Almax27
Copy link
Contributor Author

Almax27 commented Sep 9, 2015

@pandamicro if that's the case should we not only define public if bindings are in use? Having protected constructors and init methods when working in c++ enforces the create() paradigm correctly.

#ifndef CC_CONSTRUCTOR_ACCESS
  #ifdef CC_ENABLE_SCRIPT_BINDING
    #define CC_CONSTRUCTOR_ACCESS public
  #else
    #define CC_CONSTRUCTOR_ACCESS protected
  #endif
#endif

@pandamicro
Copy link
Contributor

That's a good idea, we can do that

@pandamicro pandamicro reopened this Sep 9, 2015
@pandamicro
Copy link
Contributor

It's done

@mr746866
Copy link

mr746866 commented May 14, 2018

Currently changing the value of CC_ENABLE_SCRIPT_BINDING has no effect on the value of CC_CONSTRUCTOR_ACCESS. As long as there is a value assigned to CC_ENABLE_SCRIPT_BINDING, CC_CONSTRUCTOR_ACCESS is always public.

#ifndef CC_ENABLE_SCRIPT_BINDING
#define CC_ENABLE_SCRIPT_BINDING 0 // CC_CONSTRUCTOR_ACCESS is still public
#endif

The problem is the marked line shown below.

#ifndef CC_CONSTRUCTOR_ACCESS
  #ifdef CC_ENABLE_SCRIPT_BINDING // #ifdef should be #if
    #define CC_CONSTRUCTOR_ACCESS public
  #else
    #define CC_CONSTRUCTOR_ACCESS protected
  #endif
#endif

But changing #ifdef to #if and changing CC_ENABLE_SCRIPT_BINDING to 0 causes a few issues to appear.

  1. Calling protected destructor of cocos2d::experimental::FrameBuffer in CCDirector.cpp
  2. Calling protected init of cocos2d::Sprite in UISlider.cpp
  3. Calling protected destructor of cocos2d::TextureCube in CCCameraBackgroundBrush.cpp

How should these issues be handled?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants