Segmentation fault return code 11

I wanted to add player to my tiled map, but I got segmentation fault.
Here are files:

GameScene.cpp:
#include "GameScene.h"
#include "globals.h"

USING_NS_CC;

Scene* GameScene::createScene()
{
    return GameScene::create();
}

// Print useful error message instead of segfaulting when files are not there.
static void problemLoading(const char* filename)
{
    printf("Error while loading: %s\n", filename);
    printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in HelloWorldScene.cpp\n");
}

// on "init" you need to initialize your instance
bool GameScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Scene::init() )
    {
        return false;
    }

    level = new Level;
    level->loadMap("level1.tmx");
    level->retain();
    auto director = Director::getInstance();
    level->getMap()->setScale(SCALE_FACTOR);
    this->addChild(level->getMap());
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("solbrain.plist");
    cocos2d::Sprite::createWithSpriteFrameName("idle");
    player_sprite->setScale(SCALE_FACTOR);
    player_sprite->setFlippedX(true);
    Point point = Point(10, 2);
    Size size = player_sprite->getContentSize();
    player_sprite->setPosition(level->positionForTileCoordinate(size, point));
    player = new Player();
    player->retain();
    this->addChild(player_sprite);
    return true;
}

GameScene.h:

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
#include "Level.h"
#include "Player.h"
USING_NS_CC;
class GameScene : public cocos2d::Scene
{
public:
    Level* level;
    Player* player;
    Sprite* player_sprite;
    static cocos2d::Scene* createScene();

    virtual bool init();
    
    // a selector callback
    void menuCloseCallback(cocos2d::Ref* pSender);
    
    // implement the "static create()" method manually
    CREATE_FUNC(GameScene);
};

#endif

Level.cpp:

#include "Level.h"
#include "globals.h"

void Level::loadMap(const char *mapname) {
    map = TMXTiledMap::create(mapname);
    map->retain();
}

TMXTiledMap *Level::getMap() {
    return map;
}

Level::Level() {

}

Level::~Level() {
    map->release();
}

Point Level::positionForTileCoordinate(Size s, Point point) {
    float x = floor(s.width / 2 * SCALE_FACTOR + point.x * map->getTileSize().width * SCALE_FACTOR);
    float y = floor(s.height / 2 * SCALE_FACTOR + point.y * map->getTileSize().height * SCALE_FACTOR);
    return Point(x, y);
}

Level.h:

#pragma once
#include "cocos2d.h"
using namespace cocos2d;


class Level : public Ref{
public:
    TMXTiledMap* map;
    void loadMap(const char* mapname);
    TMXTiledMap* getMap();
    Point positionForTileCoordinate(Size s, Point point);
    Level();
    virtual ~Level();

};
Player.cpp:
#include "Player.h"

Player::Player() {
    state = Player::State::Standing;
    facingRight = true;
    grounded = true;
    stateTime = 0;
    velocity = Point(0, 0);
    position = Point();
}

Player::~Player() {

}

Player.h:

#pragma once

#include "cocos2d.h"

USING_NS_CC;


class Player : public Ref{
public:
    enum State {
        Standing, Walking, Jumping
    };
    State state;
    bool facingRight;
    bool grounded;
    float stateTime;
    Point position;
    Point velocity;
    Player();
    virtual ~Player();
};

Am I stupid or it’s not my fault? :slight_smile:

I’m using cocos2d-x3.17, Ubuntu 16.04

Where is the seg fault? Do you have anymore info about it?

Edit: I trimmed up your source because you were including files we dont need to see. They are usually standard for every project.

Here is output:
Ready for GLSL
Ready for OpenGL 2.0

{
gl.supports_OES_depth24: false
gl.supports_BGRA8888: false
gl.supports_discard_framebuffer: false
gl.supports_NPOT: true
gl.supports_PVRTC: false
gl.supports_ATITC: false
cocos2d.x.version: cocos2d-x-3.17
gl.vendor: X.Org
cocos2d.x.compiled_with_gl_state_cache: true
gl.supports_S3TC: true
cocos2d.x.build_type: DEBUG
gl.supports_OES_map_buffer: false
cocos2d.x.compiled_with_profiler: false
gl.renderer: AMD REDWOOD (DRM 2.50.0 / 4.13.0-43-generic, LLVM 5.0.0)
gl.version: 3.0 Mesa 17.2.8
gl.supports_OES_packed_depth_stencil: false
gl.supports_vertex_array_object: true
gl.max_texture_size: 16384
gl.max_texture_units: 80
gl.supports_ETC1: false
}

cocos2d: SpriteFrameCache: Trying to use file solbrain.png as texture

Process finished with exit code 11

Does this exist? What location?

How are you loading this: SpriteFrameCache::getInstance()->addSpriteFramesWithFile("solbrain.plist");

It’s in Resources folder.

So then does it contain the .png you are after?

Yes, it is

So the problem is you are trying to use this png and it can’t be found or the name is different or something related to that.

It’s pretty sad. Thanks for reply :wink:

What’s sad? Double check what you are doing. You are trying to use a resource that for some reason your app doesn’t think exists. Post some pictures if you need to.

It helped. I just copypasted name of file and everything worked well.
Thanks for help. :sunglasses: