| 43 | } |
| 44 | |
| 45 | void Bug422Layer::reset() |
| 46 | { |
| 47 | static int localtag = 0; |
| 48 | localtag++; |
| 49 | |
| 50 | // TO TRIGGER THE BUG: |
| 51 | // remove the itself from parent from an action |
| 52 | // The menu will be removed, but the instance will be alive |
| 53 | // and then a new node will be allocated occupying the memory. |
| 54 | // => CRASH BOOM BANG |
| 55 | auto node = getChildByTag(localtag - 1); |
| 56 | AXLOGD("Menu: {}", fmt::ptr(node)); |
| 57 | removeChild(node, true); |
| 58 | // [self removeChildByTag:localtag-1 cleanup:NO]; |
| 59 | |
| 60 | auto item1 = MenuItemFont::create("One", AX_CALLBACK_1(Bug422Layer::menuCallback, this)); |
| 61 | AXLOGD("MenuItemFont: {}", fmt::ptr(item1)); |
| 62 | MenuItem* item2 = MenuItemFont::create("Two", AX_CALLBACK_1(Bug422Layer::menuCallback, this)); |
| 63 | auto menu = Menu::create(item1, item2, nullptr); |
| 64 | menu->alignItemsVertically(); |
| 65 | |
| 66 | float x = AXRANDOM_0_1() * 50; |
| 67 | float y = AXRANDOM_0_1() * 50; |
| 68 | menu->setPosition(menu->getPosition() + Vec2(x, y)); |
| 69 | addChild(menu, 0, localtag); |
| 70 | |
| 71 | //[self check:self]; |
| 72 | } |
| 73 | |
| 74 | void Bug422Layer::check(Node* t) |
| 75 | { |