Exception triggered by fl_vertex.cxx in my program

21 views
Skip to first unread message

Osman Zakir

unread,
May 24, 2017, 7:06:07 AM5/24/17
to fltk.general
I've attached a file to this message that shows the code in the aforementioned .cxx file from the FLTK libraries that triggered an exception I've encountered.  The file also shows the unhandled exception messages  I get when I run the code in the debugger without catching the exception.  

The main problem right now is that I can't see anything on my window.  No error message for the caught exception shows up on the window.  

I've also attached my code and the library interface headers and .cpp files provided by Dr. Stroustrup for the book I'm using, along with other code I'm directly or indirectly.  [There are four headers for a Matrix, but I'm not using that so I decided to not attach those ones.]
fltk_user_code_exception.txt
GUI.h
GUI.cpp
Window.h
Window.cpp
main.cpp
fltk.h
cust_std_lib_facilities.h
cust_std_lib_facilities.cpp
Graph.h
Graph.cpp
Simple_window.h
Simple_window.cpp
Point.h

Albrecht Schlosser

unread,
May 24, 2017, 9:39:59 AM5/24/17
to fltkg...@googlegroups.com
On 24.05.2017 13:06 Osman Zakir wrote:
> I've attached a file to this message that shows the code in the
> aforementioned .cxx file from the FLTK libraries that triggered an
> exception I've encountered. The file also shows the unhandled exception
> messages I get when I run the code in the debugger without catching the
> exception.
>
> I've also attached my code and the library interface headers and .cpp
> files provided by Dr. Stroustrup for the book I'm using, along with
> other code I'm directly or indirectly. [There are four headers for a
> Matrix, but I'm not using that so I decided to not attach those ones.]

I tried to compile your project. I had to tweak a few things to make it
compile under Linux and Windows, but there's (at least) one missing file:

1>[...]\stroustrup\GUI.cpp(2): fatal error C1083: Cannot open include
file: 'std_lib_facilities.h': No such file or directory
===== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =====

So could you please post std_lib_facilities.h and all files that may be
included by this file (if there are any such files you didn't post
already) ?

Osman Zakir

unread,
May 24, 2017, 10:27:31 AM5/24/17
to fltk.general, Albrech...@online.de
I could've sworn I changed all instances of "std_lib_facilties.h" to "cust_std_lib_facilities.h" since the book says to use them myself only until Chapter 10.  Well, I'm attacking that one to this post anyway.  Look at it, please.  It's just one header file and no .cpp files (since it's mostly templates).  It only includes the needed standard headers, though, so there aren't any custom headers included in it.
std_lib_facilities.h

Albrecht Schlosser

unread,
May 24, 2017, 12:12:57 PM5/24/17
to fltkg...@googlegroups.com
On 24.05.2017 16:27 Osman Zakir wrote:
>
> I could've sworn I changed all instances of "std_lib_facilties.h" to
> "cust_std_lib_facilities.h" since the book says to use them myself only
> until Chapter 10. Well, I'm attacking that one to this post anyway.
> Look at it, please. It's just one header file and no .cpp files (since
> it's mostly templates). It only includes the needed standard headers,
> though, so there aren't any custom headers included in it.

<rant>
The question is: why are all these templates and advanced functions
necessary to teach a simple GUI approach? Does any reader of the book
(do you) know what's going on under the hood? I guess no. :-(
</rant>

Well, I could compile and link your sources successfully after some
tweaks, as I said before. The following line:

std::string::const_iterator p = find(s.begin(), s.end(), '.');

in Graph.cpp (~ line #301) would neither compile with g++ (Linux or
Windows/MinGW) nor with clang (the latter under Linux only).

Error message from clang for completeness:

Building CXX object CMakeFiles/stroustrup.dir/Graph.cpp.o
FAILED: /usr/bin/clang++ -I/home/albrecht/git/fltk-1.3/build/Debug
-I/home/albrecht/git/fltk-1.3 -g -std=gnu++14 -MMD -MT
CMakeFiles/stroustrup.dir/Graph.cpp.o -MF
CMakeFiles/stroustrup.dir/Graph.cpp.o.d -o
CMakeFiles/stroustrup.dir/Graph.cpp.o -c ../../Graph.cpp
../../Graph.cpp:301:35: error: no matching function for call to 'find'
std::string::const_iterator p = find(s.begin(),
s.end(), '.');
^~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/streambuf_iterator.h:369:5:
note: candidate template ignored: could not match 'istreambuf_iterator'
against '__normal_iterator'
find(istreambuf_iterator<_CharT> __first,
^
1 error generated.

Note: I had to use C++11 features, but I also tried C++14 (see command
line). The same statement compiles with VS 2015. I don't know which
compiler is "correct" for whatever that means...


That said, when I ran the program I saw a window with a "Next" button. I
didn't get an exception though, even if I clicked "Next", which closed
the window and exited.

I put a breakpoint on

void Box::draw_lines() const

in main.cpp to see if this was called, but it was never reached. This is
likely the cause why the program doesn't show anything, but I really
don't know why that is so. There's *way too much* code to check to find
out why draw_lines() is never called. I even tried to add

void Box::draw() {
draw_lines();
}

but nothing happened. I gave up.

For those interested to test: I added CMakeLists.txt and could
successfully generate:

- Unix Makefiles for Linux
- MSYS Makefiles for MinGW (Windows)
- VS 2015/64 solution for Visual Studio 2015 (Windows)

Others may try to help, but I'm out of the game. Sorry.

Instructions: save all files from Osman's two recent posts in one
directory, run `patch -p1 osman_dr-s.diff` with the attached patch file,
then

$ mkdir build
$ cd build
$ cmake[-gui] -G "<your generator>" ..
$ make, ninja, start VS2015/17 etc..

osman_dr-s.diff

Osman Zakir

unread,
May 24, 2017, 12:23:12 PM5/24/17
to fltk.general, Albrech...@online.de
The advanced templates and stuff in the standard library access header isn't for the GUI alone, it's for using with the book itself which teaches more than just GUI stuff.  

Anyway, I got an unhandled exception error when I tried to run in the debugger in VS2017 without the try-catch block.   

But do you think there's too much code in my own main.cpp?  

Osman Zakir

unread,
May 24, 2017, 12:39:42 PM5/24/17
to fltk.general, Albrech...@online.de
Did you try running the code without the try-catch block?  When I commented it out and left only the code in lines 45-50 (with them being outside any try-catch blocks), and then ran the code, I got the same problem with the program going unresponsive due to unhandled exception.  I got a box with no corners drawn on the window before it froze and I had to kill it.   

Albrecht Schlosser

unread,
May 24, 2017, 12:49:57 PM5/24/17
to fltkg...@googlegroups.com
No, I meant that the GUI stuff in the "standard library headers" is too
much to just read and understand. So I gave up because I don't have any
more spare time.

> Did you try running the code without the try-catch block? When I
> commented it out and left only the code in lines 45-50 (with them being
> outside any try-catch blocks), and then ran the code, I got the same
> problem with the program going unresponsive due to unhandled exception.
> I got a box with no corners drawn on the window before it froze and I
> had to kill it.

Yes, I did, but I didn't see any changes. However, this was done only
with VS2015.

See more in my reply to Ian's post ...
Reply all
Reply to author
Forward
0 new messages