Callbacks are not working for me (Ver. 0.69)

Started by Aiiro, 04 January 2016, 17:20:19

Aiiro

Hello,

I have issues with callbacks with my buttons in my project :
Button::Ptr quit(gui);
    quit->load("widgets/White.conf");
    quit->setText("Quit");
    quit->setSize(230,50);
    quit->setCallbackId(12);
    quit->bindCallback(tgui::Button::LeftMouseClicked);
    quit->setPosition(800,600);

This is a bit of code in one of my functions, but all buttons are the same (with different callback IDs of course) and here it is how I handle it :
while (window.isOpen())
    {

        sf::Event event;

        while (window.pollEvent(event))
        {

            if (event.type == sf::Event::Closed)
            {

                window.close();

            }

            gui.handleEvent(event);


        }

            tgui::Callback callback;
            while (gui.pollCallback(callback))
            {

                if (callback.id == 12)
                {

                    window.close();

                }

Again it's a just a bit of code, but all other callbacks are handled the same way.
The thing is that I can't even click on the buttons, it's not like nothing is appearing when I click on them, I don't even see I click on them.
I tried a lot of things, but I just can't figure out why it is not working.

Thanks for your help.

texus

You should try to write a minimal and complete code that reproduces the issue.

If I turn your code fragments into a minimal and complete code then it works fine.
Code (cpp) Select
#include <TGUI/TGUI.hpp>
int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI Window");
    tgui::Gui gui(window);
    if (gui.setGlobalFont("TGUI/fonts/DejaVuSans.ttf") == false)
        return 1;

    tgui::Button::Ptr quit(gui);
    quit->load("TGUI/widgets/White.conf");
    quit->setText("Quit");
    quit->setSize(230,50);
    quit->setCallbackId(12);
    quit->bindCallback(tgui::Button::LeftMouseClicked);
    quit->setPosition(100, 200);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

            gui.handleEvent(event);
        }

        tgui::Callback callback;
        while (gui.pollCallback(callback))
        {
            if (callback.id == 12)
                std::cout << "CLICKED" << std::endl;
        }

        window.clear();
        gui.draw();
        window.display();
    }

    return 0;
}


So unless that code isn't working for you, the error must be in some other part of the code.

Aiiro

Thanks for the reply.
I was in a rush, so I couldn't do a proper example code, sorry about that.

So I tried the code you provided me and it still doesn't work.
I really don't know what is wrong with all of it :/

Thanks again

texus

Are you sure it isn't working? I changed your window.close() in a cout for some reason, is there nothing being printed in the terminal?

Aiiro

Yes, it doesn't work, I saw your little change in the code.
It's really strange...

Thanks again

texus

Then I have no idea what it can be since it works fine here.
Did you download the precompiled libraries or did you compile tgui yourself? If precompiled, for which compiler?
What compiler are you using?
Are you linking statically/dynamically in release/debug and with the same kind of libraries? (e.g. not using release lib in debug mode)
Have you been using tgui for some time (a few days) already or did you just started with writing something? In the former case, did you ever get a working callback in another situation or are callbacks just not working at all?

Aiiro

I downloaded the precompiled for MinGW compiler (default one in Code Blocks)
I followed the tutorials on TGUI and SFML official websites to set up the libs in Code::Blocks, so it should be okay (I also checked more than once if everything was alright and everything seems fine).

It worked once some months ago and then it stopped working for some reasons (I didn't change anything in the settings and nothing in the code that could have break it) but it was on another PC, so not the same Code Blocks, I actually reinstalled everything again yesterday.

Thanks again

texus

The only thing that I can think of why it doesn't work if is if one of the libraries are incompatible (either wrong compiler version or debug/release mismatch). That leads to undefined behavior but I have only seen crashes due to this, never some part of the code that isn't functioning.

In codeblocks when you go to the settings you should have a tab "Toolchain executables". It states what c++ compiler executable you are using. Could you run that executable from the command line as "mingw-executable -v" and show the output?

Aiiro

Here is what I get :
Using built-in specs.
COLLECT_GCC=mingw32-g++.exe
COLLECT_LTO_WRAPPER=c:/program files (x86)/codeblocks/mingw/bin/../libexec/gcc/m
ingw32/4.7.1/lto-wrapper.exe
Target: mingw32
Configured with: ../../src/gcc-4.7.1/configure --build=mingw32 --enable-language
s=c,c++,ada,fortran,objc,obj-c++ --enable-threads=win32 --enable-libgomp --enabl
e-lto --enable-fully-dynamic-string --enable-libstdcxx-debug --enable-version-sp
ecific-runtime-libs --with-gnu-ld --disable-nls --disable-win32-registry --disab
le-symvers --disable-build-poststage1-with-cxx --disable-werror --prefix=/mingw3
2tdm --with-local-prefix=/mingw32tdm --enable-cxx-flags='-fno-function-sections
-fno-data-sections' --with-pkgversion=tdm-1 --enable-sjlj-exceptions --with-bugu
rl=https://tdm-gcc.tdragon.net/bugs
Thread model: win32
gcc version 4.7.1 (tdm-1)

texus

You are using SFML 2.3.2 procompiled libraries from the sfml website, right?
Then I have no more ideas on why it wouldn't work for you.

You could still try to remove everything of tgui from your pc (including the dlls in your project if you are linking dynamically), download the source code and build it yourself with cmake.

The only other thing you could do is start using v0.7-dev which is so different that the same issue can't happen. But that means that you have to rewrite the code that you already have.

Aiiro

Alright, so I compiled everything myself with a MinGW compilator that I downloaded apart from Code::Blocks.

And it seems to work !

It was just a problem with my compilator version, I guess.
Anyway, thanks for your help.

Keep up the good work, this library is really well-done !