Cocos2d-x Touch Event coordinate system

I’m using cocos2d-x 3.7.1

I have a Node in my Scene, I’m adding child Nodes to that Node. (HexField is a subclass of Node)

int rhombusSizeX = 1;
int rhombusSizeY = 2;

for (int y = 0; y < rhombusSizeY; ++y){
    for (int x = 0; x < rhombusSizeX; ++x){
        HexField* field = HexField::create();
        field->setPosition(Vec2(x*30 + y*15, y*30));
        field->setName("HexField " + to_string(x) + "," + to_string(y));

        auto listener = EventListenerTouchOneByOne::create();
        listener->setSwallowTouches(true);
        listener->onTouchBegan = CC_CALLBACK_2(HexField::onTouchBegan, field);
        listener->onTouchMoved = CC_CALLBACK_2(HexField::onTouchMoved, field);
        listener->onTouchEnded = CC_CALLBACK_2(HexField::onTouchEnded, field);
        Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, field);

        this->addChild(field, 1);
    }
}

If there is only one HexField added

int rhombusSizeX = 1;
int rhombusSizeY = 1;

The touch->getLocation() in HexField::onTouchBegan is reported as expected in World Coordinates.

If there is more than one HexField added

int rhombusSizeX = 5;
int rhombusSizeY = 5;

touch->getLocation() returns coordinates relative to the “one before last” added HexField which in this case will be HexField 3,4.

Why is that so? Is it a bug?

I came to an answer now.

It all happened because I didn’t call:

 Director::getInstance()->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);

after:

 Director::getInstance()->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
 Director::getInstance()->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);

in my draw function.

Looks like that error escalated to other parts of my program causing some strange behavior.