Author Topic: loop withif else statment not working inside of codeblocks executabe it created.  (Read 521 times)

Offline userx-bw

  • Multiple posting newcomer
  • *
  • Posts: 12
Yesterday, May 18, 2018 this program was working perfectly. Today when i went back into code blocks to add more to it.  compiled then ran the executable it no longer executes the else part of a if else statement within a while (1) loop. the exact same code compiled using a makefile outside of code blocks works.  I even took it down to a basic while loop and if else statement and it is still not working in code blocks, but outside of code blocks it does. that being compiled outside of code blocks using the exact same code. yesterday it was working, today it is not, I have no idea what changed to make it stop working.



Code: [Select]

#include <iostream>
#include <cstdlib> // call external program
#include <unistd.h>
#include <sys/time.h>
#include <X11/Xlib.h>

#include "wmimagedock.hpp"
#include "imagefiles.hpp"

using namespace std;

Bool XNextEventTimed(Display *display, XEvent *event_return, struct timeval *timeout)
{

    /*
     *  Usage:
     *    struct timeval = { .tv_sec = 5, .tv_usec = 0 };
     *    if (XNextEventTimed(display, &event, &timeout) == True) {
     *        //.. do your event processing switch
     *    } else {
     *        //.. do your timeout thing
     *    }
     *
     *  Return:
     *    True if an event was selected, or False when no event
     *    was found prior to the timeout or when select returned
     *    an error (most likely EINTR).
    */

    if (timeout == NULL) {
        XNextEvent(display, event_return);
        return True;
    }

    if (XPending(display) == 0) {
        int fd = ConnectionNumber(display);
        fd_set readset;
        FD_ZERO(&readset);
        FD_SET(fd, &readset);
        if (select(fd + 1, &readset, NULL, NULL, timeout) > 0) {
            XNextEvent(display, event_return);
            return True;
        } else {
            return False;
        }
    } else {
        XNextEvent(display, event_return);
        return True;
    }
}
int main(int argc, char **argv)
{
    WMWindowDock doc;
    XEvent report ;
    struct timeval interval;
    struct timeval next_tick = interval ;
    Time lastTime = 0;

    doc.parseCmLine(argc, argv);
    doc.filesGetter();
    if ( doc.getOrder() ) {  sortList(); }
    doc.openXup(argc, argv);
    int laptime = doc.getStime();
    interval.tv_sec = laptime;
    interval.tv_usec = 0;

    while (1)
    {
        if (XNextEventTimed(doc.getDisplay(), &report, &next_tick))
        {
            switch (report.type)
            {
            case ButtonRelease:
                cout<<"report.type "<<report.type<<endl;
                cout<<"tlap "<<laptime<<endl;
                break;
            default:
                break;
            }
        }
        else
        {
        cout<<"laptime "<<laptime<<endl;
        doc.DisplayImage();
        next_tick  = interval ;
        }
    }

    /*
    while (1)
    {  // cout<<" in loops"<<endl;
        if (XNextEventTimed( doc.getDisplay(), &report, &next_tick ) )
        {
            switch (report.type)
            {
                case ButtonRelease:
                    if (report.xbutton.button == Button1)
                    {
                        if (report.xbutton.time - lastTime < 250 )
                        { cout<<"clicked 2"<<endl;
                            std::string cmd = doc.getCommandOne();
                            cmd += " &";
                            if (cmd.length() > 2 )
                            {
                                cout<<cmd<<" Requested"<<endl;
                                system( cmd.c_str() );
                            }
                        }
                        else
                        {
                            lastTime = report.xbutton.time;
                        }
                    }
                    else if ( report.xbutton.button == Button3)
                    {
                        if (report.xbutton.time - lastTime < 250 )
                        {
                            std::string cmd = doc.getCommandTwo();
                            cmd += " &";
                            if (cmd.length() > 2 )
                            {
                                cout<<cmd<<" Requested"<<endl;
                                system( cmd.c_str() );
                            }
                        }
                        else
                        {
                            lastTime = report.xbutton.time;
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        else
        {
            doc.DisplayImage();
            cout<<"ticky..."<<endl;
            next_tick  = interval ;
        }
      //  doc.DisplayImage();
      cout<<"tlap "<<tlap<<endl;
    }

*/


return 0;
}

the programs output from the executable compiled in codeblocks using a terminal to run the program in.
Code: [Select]

-------------- Clean: Debug in wmimagedock (compiler: GNU GCC Compiler)---------------

Cleaned "wmimagedock - Debug"

-------------- Build: Debug in wmimagedock (compiler: GNU GCC Compiler)---------------

g++ -Wall -fexceptions -std=c++11 -g  -c /media/projects/C++Projects/wmimagedock/imagefiles.cpp -o obj/Debug/imagefiles.o
g++ -Wall -fexceptions -std=c++11 -g  -c /media/projects/C++Projects/wmimagedock/main.cpp -o obj/Debug/main.o
g++ -Wall -fexceptions -std=c++11 -g  -c /media/projects/C++Projects/wmimagedock/wmimagedock.cpp -o obj/Debug/wmimagedock.o
g++  -o bin/Debug/wmimagedock obj/Debug/imagefiles.o obj/Debug/main.o obj/Debug/wmimagedock.o  -lXext -lXpm  -lX11 -lImlib2 -lboost_system -lboost_filesystem -lX11 -lXpm -lXext -lImlib2 -lboost_system -lboost_filesystem 
/media/projects/C++Projects/wmimagedock/main.cpp: In function ‘int main(int, char**)’:
/media/projects/C++Projects/wmimagedock/main.cpp:78:10: warning: unused variable ‘lastTime’ [-Wunused-variable]
     Time lastTime = 0;
          ^
Output file is bin/Debug/wmimagedock with size 529.60 KB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 1 warning(s) (0 minute(s), 1 second(s))
 

Code: [Select]
userx@slackwhere:/media/projects/C++Projects/wmimagedock/bin/Debug
$ ls
wmimagedock  wmslideshow+
userx@slackwhere:/media/projects/C++Projects/wmimagedock/bin/Debug
$ ./wmimagedock -e ~/Pictures -t 3
Loading Files ...
Done.
it just sits there.. every three seconds it is to spit a messages out but does not.
the on click part works
Code: [Select]
userx@slackwhere:/media/projects/C++Projects/wmimagedock/bin/Debug
$ ./wmimagedock -e ~/Pictures -t 3
Loading Files ...
Done.
report.type 5
tlap 3
report.type 5
tlap 3
report.type 5
tlap 3
report.type 5
tlap 3
using the same exact code compiled outside of code blocks with a makefile.
Code: [Select]
userx@slackwhere:/media/projects/C++Projects/wmimagedock/wmimagedock-1.8
$ make
g++ -Wall -std=c++11 -O2   -c -o imagefiles.o imagefiles.cpp
g++ -Wall -std=c++11 -O2   -c -o wmimagedock.o wmimagedock.cpp
g++ -Wall -std=c++11 -O2   -c -o main.o main.cpp
g++ -Wall -std=c++11 -O2 -o wmimagedock imagefiles.o wmimagedock.o main.o -lXext -lXpm  -lX11 -lImlib2 -lboost_system -lboost_filesystem
userx@slackwhere:/media/projects/C++Projects/wmimagedock/wmimagedock-1.8
$ ./wmimagedock -e ~/Pictures -t 3
Loading Files ...
Done.
/home/userx/Pictures/productimage-picture-sweet-revenge-830_jpg_382x5000_q100.jpg
Laptime 3
/home/userx/Pictures/snap/vlcsnap-00046.png
Laptime 3
/home/userx/Pictures/snap/vlcsnap-00036.png
Laptime 3
^C
I am not sure what more information you need, all I know is that the very same exact code that work yesterday in code blocks no longer is working properly today in code blocks. nothing has been changed by me. I do not think it can be a system thing because it works on the system. Linux Slackware 14.2 64bit.


« Last Edit: May 19, 2018, 06:57:05 pm by userx-bw »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6511
    • My Best Post
Did you try doing a full project rebuild instead of doing a build or rebuild of only the single target?

Edit2: Looks like you likely did a full project rebuild; I do suggest doing it again match the release/debug used in the command line build.

Any reason your tests very between release and debug builds?

Any reason the C::B library list differs from your command line build?

Edit3: Why do you have only option "-fexceptions" in CB build?

Tim S.

« Last Edit: May 19, 2018, 08:19:48 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org