*

Aiiro

  • *
  • 12
    • View Profile
Callbacks are not working for me (Ver. 0.69)
« on: 04 January 2016, 17:20:19 »
Hello,

I have issues with callbacks with my buttons in my project :
Code: [Select]
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 :
Code: [Select]
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

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Callbacks are not working for me (Ver. 0.69)
« Reply #1 on: 04 January 2016, 17:28:18 »
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.
#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

  • *
  • 12
    • View Profile
Re: Callbacks are not working for me (Ver. 0.69)
« Reply #2 on: 04 January 2016, 17:44:13 »
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

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Callbacks are not working for me (Ver. 0.69)
« Reply #3 on: 04 January 2016, 17:46:46 »
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

  • *
  • 12
    • View Profile
Re: Callbacks are not working for me (Ver. 0.69)
« Reply #4 on: 04 January 2016, 17:51:16 »
Yes, it doesn't work, I saw your little change in the code.
It's really strange...

Thanks again

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Callbacks are not working for me (Ver. 0.69)
« Reply #5 on: 04 January 2016, 17:58:16 »
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

  • *
  • 12
    • View Profile
Re: Callbacks are not working for me (Ver. 0.69)
« Reply #6 on: 04 January 2016, 18:32:26 »
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

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Callbacks are not working for me (Ver. 0.69)
« Reply #7 on: 04 January 2016, 18:40:57 »
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

  • *
  • 12
    • View Profile
Re: Callbacks are not working for me (Ver. 0.69)
« Reply #8 on: 05 January 2016, 08:02:39 »
Here is what I get :
Code: [Select]
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

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Callbacks are not working for me (Ver. 0.69)
« Reply #9 on: 05 January 2016, 11:07:52 »
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

  • *
  • 12
    • View Profile
Re: Callbacks are not working for me (Ver. 0.69)
« Reply #10 on: 05 January 2016, 14:47:28 »
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 !