Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Debugging SFML android app  (Read 2550 times)

0 Members and 1 Guest are viewing this topic.

Cenobite

  • Newbie
  • *
  • Posts: 4
    • View Profile
Debugging SFML android app
« on: February 06, 2016, 05:47:11 pm »
I am starting out development of a small game using SFML and TGUI. So far I just have a bare bones menu example  which works fine on OS X, but when I launch it on Android it crashes and I see this in the adb logcat:

Quote
02-06 17:08:48.475  1407  1421 I sfml-error: Failed to activate the window's context
02-06 17:08:48.475  1407  1421 I sfml-error:
02-06 17:08:48.475  1407  1421 I sfml-error: Failed to activate the window's context
02-06 17:08:48.676   266   292 I WindowManager: Screen frozen for +2s833ms due to Window{9c6ed66 u0 Starting xyz.simek.theycome}
02-06 17:08:49.110   266   292 W art     : Long monitor contention event with owner method=int com.android.server.wm.WindowManagerService.relayoutWindow(com.android.server.wm.Session, android.view.IWindow, int, android.view.WindowManager$LayoutParams, int, int, int, int, android.graphics.Rect, android.graphics.Rect, android.graphics.Rect, android.graphics.Rect, android.graphics.Rect, android.graphics.Rect, android.content.res.Configuration, android.view.Surface) from WindowManagerService.java:3097 waiters=0 for 170ms
02-06 17:08:49.204    69   150 D AudioFlinger: mixer(0xb4480000) throttle end: throttle time(204)
02-06 17:08:49.416    69   150 D AudioFlinger: mixer(0xb4480000) throttle end: throttle time(12)
02-06 17:08:49.539  1407  1421 F libc    : Fatal signal 11 (SIGSEGV), code 1, fault addr 0x5c in tid 1421 (.simek.theycome)
02-06 17:08:49.698    66    66 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

What does it mean? I searched these forums and one post says it's threading issue, but I am not using threads (at least not that I know of). The android example bundled with SFML works fine, so it must be my mistake.

I have a simple state machine which stores states in a std::vector and each state has access to sfml::RenderWindow through a single Game object like this:

class Game
{
        public:
                sf::RenderWindow window;
                std::vector<GameState*> states;

                void pushState(GameState* state);
                void popState();
                void changeState(GameState* state);
                GameState* peekState();
};
...
class GameStateStart : public GameState
{
        public:
                Game* game;
                GameStateStart(Game* game) : game(game) {}

                virtual void draw(const float dt)
                {
                        this->game->window.draw(...);
                }
};
 

Full log is here: http://pastebin.com/WBe1BGnT

Any idea what might be wrong or a better way to go about debugging than using logcat?

Cenobite

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Debugging SFML android app
« Reply #1 on: February 06, 2016, 07:10:33 pm »
Ha! I removed the TGUI code and it doesn't crash, but the "sfml-error: Failed to activate the window's context" line is still there, so that's not it. I will try asking the TGUI developers.

EDIT: I narrowed it down to
gui.setFont(font);
« Last Edit: February 06, 2016, 07:50:26 pm by Cenobite »

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: Debugging SFML android app
« Reply #2 on: February 06, 2016, 08:12:49 pm »
If you have the latest TGUI version you can try removing the setFont call and see what happens as there is a built-in font.

If there are no widgets in the gui yet then the setFont just copies the font, otherwise it can trigger recalculations in all previous widgets so the segfault can occur on a lot of places. Maybe you can try running a tool like valgrind on your os x to make sure that it a problem specific to android and not something that accidentally works on os x. Or if you can send some minimal code that reproduces it then I can try it here.
TGUI: C++ SFML GUI

Cenobite

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Debugging SFML android app
« Reply #3 on: February 06, 2016, 10:42:14 pm »
So thanks to the help provided by texus, I found out that the crash in fact is not related to TGUI, but to font.loadFromFile().

This is a minimal reproducible example:

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::Window window(sf::VideoMode(800, 600), "My window");
   
    sf::Font font;

    if(!font.loadFromFile("assets/sansation.ttf")) // <-- CRASH
    {
        std::cerr << "Could not load font" << std::endl;
        return 1;
    }

    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();
        }
    }

    return 0;
}

I guess I should open a bug report at Github?

EDIT: Bug report created.
« Last Edit: February 08, 2016, 11:18:56 am by Cenobite »