V3.13.1 and Design Resolution issues

Aha…
On ARIES_101v2 android 4.4.2 :

Being build with 3.12, my app freeze the whole device sometimes on the lines:
Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); // actually, on this one, even if another is commented;

After few hours of testing, creating the empty new projects with different cocos2dx versions::
Director * d2 = 0; d2->getVisibleOrigin(); // app nicely closes if build with 3.10; but 3.12 or 3.13.1 - freezes the device.
//by the way, this is absolutely not allowed in c++, so VS-2015 app closes.

this->addChild(0); // app nicely closes if build with 3.10 or 3.12; but 3.13.1- freezes the device.

Looks like:

  1. I have a bad and ugly device, not suitable for newer Cocos version; (but most apps works ok on it);
  2. Newer Cocos versions was not tested on ugly, bad devices.
  3. Maybe someone has turned off some checks, to get faster performance in every next version?

I tried to count, how many times Director::getInstance() returns null - zero times. Confused. :frowning:
I will try to make my app more safety, wasting time to adding more checking before using all pointers.

It should work fine.
As I understand now the standard “Hello World” project is working for you. Right?

This is illogical.
If you need a label but you do not want to use it right now then use something like

auto label0 = Label::create();
// or Label::createWithTTF("Hello label0", "fonts/Font.ttf", 28);
label->setVisible(false);
this->addChild(label0);

This is illogical. Why are you doing this?

To find out, why my app began to freeze some device with newer cocos2dx version, seems at this line:
Vec2 origin = Director::getInstance()->getVisibleOrigin(); // seems like Director::getInstance() sometimes returns null; but I could not catch it doing that

Does it matter whether the application is closed or freezed? This is not normal in any case.

Are you sure that the problem is Director::getInstance()? Are you using a standard Multi Resolution Support?

this->addChild(0);

Add nothing as a child??

Hm… later I will google what is it and how it should be properly used.
Also I will really need pre-build template for some latest stable version - 12 or 13.1; as I remember you succeed in that.

Just to find out, why new empty a-bit-modified app freeze on lines like this:
auto sprite = Sprite::create("some.png"); this->addChild(sprite); - may be object is not created.

check perhaps to see?

As I said, I think the problem in my empty project was in line
Vec2 origin = Director::getInstance()->getVisibleOrigin(); // app may freeze here on one my device
so I tried to count, how many times Director::getInstance() mey return null (on device, build with 3.12) - zero times. Confused.
int s = 0; for (int iii = 0; iii < 999999; iii++) { Director * d = Director::getInstance(); if (0==d) s++; // it remains zero; }

Just show me your AppDelegate.cpp please. Maybe getVisibleOrigin() is the problem.

I think that this->addChild(0) is not expected use.

Classes.zip (4.9 KB) - Here they are - default but modified a bit: removed setContentScaleFactor and GLViewImpl::create() used instead of GLViewImpl::createWithRect().

I can not open it right now. Please show the AppDelegate.cpp in your post.

#include "AppDelegate.h"
#include "HelloWorldScene.h"

USING_NS_CC;

static cocos2d::Size designResolutionSize = cocos2d::Size(640, 700);
static cocos2d::Size smallResolutionSize = cocos2d::Size(480, 800);
static cocos2d::Size mediumResolutionSize = cocos2d::Size(768, 1024);
static cocos2d::Size largeResolutionSize = cocos2d::Size(1536, 2048);

AppDelegate::AppDelegate()
{
}

AppDelegate::~AppDelegate()
{
}

void AppDelegate::initGLContextAttrs()
{
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};

GLView::setGLContextAttrs(glContextAttrs);

}

static int register_all_packages()
{
return 0; //flag for packages manager
}

bool AppDelegate::applicationDidFinishLaunching() {
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
glview = GLViewImpl::createWithRect(“Addition for kids”, cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
glview = GLViewImpl::create(“Addition for kids”);
#endif
director->setOpenGLView(glview);
}

FileUtils::getInstance()->addSearchPath("res");

register_all_packages();

auto scene = HelloWorld::createScene();
director->runWithScene(scene);

return true;

}

void AppDelegate::applicationDidEnterBackground() {
Director::getInstance()->stopAnimation();
}

void AppDelegate::applicationWillEnterForeground() {
Director::getInstance()->startAnimation();
}

Ok. I see now.

Multi Resolution Support (MRS) is a concept related with the cocos.

setContentScaleFactor(), setDesignResolutionSize(), getVisibleSize() and getVisibleOrigin() are parts of this concept.

Since you remove setContentScaleFactor() and setDesignResolutionSize()… you have the problem.

1 Like

Thanks a lot;
setContentScaleFactor() - I want it to be 1; will it has this default value if I won’t call it?
setDesignResolutionSize() - I want it to be the same as screen size; I will try to call it with value I get from getVisibleSize(), or is there a better way? At the very start?

It depends on the cocos version.

No. getVisibleSize() is a part of Design Resolution.

MRS is a relatively complex concept. I can not explain it briefly. Sorry.

@serpri
I think you have to start from the standard template. Also, you can read this.
And the wiki on this site.

@slackmoehrle
Maybe you need to move this to a separate topic since error is not related with the 3.13.1 version.Preformatted text

1 Like

This is now a new topic.

@slackmoehrle

Thank you!

@serpri

What is the screen resolution of your device? Is there an action bar on the screen?

edited

I will think that the resolution is 720x1280, portrait mode, there is no a virtual action bar.

If it is not, then just change static cocos2d::Size designResolutionSize = cocos2d::Size(720, 1280);.

Try this AppDelegate.cpp.

This code does not do real Multi Resolution Support. This is only a temporary solution so that you can test on your device, until you do not implement your MRS.

#include "AppDelegate.h"
#include "HelloWorldScene.h"

USING_NS_CC;

static cocos2d::Size designResolutionSize = cocos2d::Size(720, 1280);

AppDelegate::AppDelegate()
{
}

AppDelegate::~AppDelegate() 
{
}

// if you want a different context, modify the value of glContextAttrs
// it will affect all platforms
void AppDelegate::initGLContextAttrs()
{
    // set OpenGL context attributes: red,green,blue,alpha,depth,stencil
    GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};

    GLView::setGLContextAttrs(glContextAttrs);
}

// if you want to use the package manager to install more packages,  
// don't modify or remove this function
static int register_all_packages()
{
    return 0; //flag for packages manager
}

bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
        glview = GLViewImpl::createWithRect("HelloCpp", cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
        glview = GLViewImpl::create("HelloCpp");
#endif
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0f / 60);

    // Set the design resolution
    glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::SHOW_ALL);
   
        director->setContentScaleFactor(1.0);

    register_all_packages();

    // create a scene. it's an autorelease object
    auto scene = HelloWorld::createScene();

    // run
    director->runWithScene(scene);

    return true;
}

// This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
void AppDelegate::applicationDidEnterBackground() {
    Director::getInstance()->stopAnimation();

    // if you use SimpleAudioEngine, it must be paused
    // SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
    Director::getInstance()->startAnimation();

    // if you use SimpleAudioEngine, it must resume here
    // SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
}

1280*800; no action bar, just status bar (disappears when cocos app started) and navigation bar (disappears when cocos app started, if it built with 3.13.1).
I do not want designResolutionSize to be preset - I want to fit my virtual screen to any device screen size (in real pixels); going to find how to do that - how to find out device screen size on app very first steps.

I asked about the navigation bar because it will be hidden only on devices with android version 4.4 and above.

Typically, the design resolution is preset, and it depends on the selected MRS policy and your app.
But of course you can implement your own logic.

glview->getFrameSize() returns the screen resolution minus the navigation bar if there is a virtual navigation bar and it was not hidden.

Please let me know if this solves the problem.

edited

1 Like

Yes, glview->getFrameSize() solved the problem, thank you very much :smiley:

director->setContentScaleFactor(1.0f); glview->setDesignResolutionSize(400, 400, ResolutionPolicy::NO_BORDER); // fake, temporary; auto frameSize = glview->getFrameSize(); glview->setDesignResolutionSize(frameSize.width, frameSize.height, ResolutionPolicy::NO_BORDER); //looks like I can not call here setFrameSize and getDesignResolutionSize and even getContentScaleFactor

But seems I don’t have action bar on my devices (only status and navigation); so I will need a device with action bar to test how my app will looks like on it.

I am glad to know it. :slight_smile:

I do not try to call it in the AppDelegate.cpp. But why not?

I am sorry. I used the wrong term. I meant the navigation bar.

edited

Do you use your own solution for the adaptation of app for different screen resolutions?
If not, your application will look very differently on different screen resolutions.