Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » FLTK based code unable to compile?(libc++abi.dylib: terminating with uncaught exception of type std::runtime_error:)
FLTK based code unable to compile? [message #1731617] Sun, 08 May 2016 01:55 Go to next message
Michelle Uy is currently offline Michelle UyFriend
Messages: 6
Registered: May 2016
Junior Member
Good evening all,

I have created a FLTK based code that prints out squares and its intersection in different colors however whenever I run it and put input of 100 and above I'm getting the libc++abi.dylib error and am no longer able to run

libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: Bad rectangle: non-positive side

I'm running the code however the squares that I am inputting are all positive integers.

Here is my code
#include <iostream>
#include <cstdlib>
#include "Simple_window.h" // get access to our window library
#include "Graph.h" //get access to our graphics library facilities

#include "std_lib_facilities.h"
using namespace std;
using namespace Graph_lib;// our graphics facilities are in Graph_lib


int main()
{
Point tl(0,0);//to become top left corner of window
Simple_window win (tl,500,500,"Squares");//make a simple window

int area;//Length of 3 squares
int intersection; //area of intersection
int pos1x, pos1y,
	pos2x, pos2y,
	pos3x, pos3y,//For random postions
	br_pos1x, br_pos1y,
	br_pos2x, br_pos2y,
	br_pos3x, br_pos3y; //bottom right positions

//FOR SQUARE1
	while(true){
cout<<"Input Length of squares:";
cin>>area;
		if((area >= 500)){
			cout << "Invalid input, pls try again." << endl;
			continue;
		}
		if((area <= 0)){
				break;
				}
		if((area < 500 )){
pos1x = rand()%(500-area) + 0; //Any random postion(X) from 0 to 500-length of first square
pos1y = rand()%(500-area) + 0; //Any random postion(Y) from 0 to 500-length of first square
br_pos1x = pos1x + area - 1;
br_pos1y = pos1y + area - 1;

Rectangle r1(Point(pos1x,pos1y), area, area);// top-left corner, width, height for square 1
win.attach(r1);

pos2x = rand()%(500-area) + 0; //Any random postion(X) from 0 to 500-length of second square
pos2y = rand()%(500-area) + 0; //Any random postion(Y) from 0 to 500-length of second square
br_pos2x = pos2x + area - 1;
br_pos2y = pos2y + area - 1;

Rectangle r2(Point(pos2x,pos2y), area, area);// top-left corner, width, height for square 2
win.attach(r2);

pos3x = rand()%(500-area) + 0; //Any random postion(X) from 0 to 500-length of second square
pos3y = rand()%(500-area) + 0; //Any random postion(Y) from 0 to 500-length of second square
br_pos3x = pos3x + area - 1;
br_pos3y = pos3y + area - 1;

Rectangle r3(Point(pos3x,pos3y), area, area);// top-left corner, width, height for square 2
win.attach(r3);

r1.set_fill_color(Color::red);
r2.set_fill_color(Color::red);
r3.set_fill_color(Color::red);

if (br_pos1x > pos2x && br_pos1y > pos2y && br_pos1x < br_pos2x && br_pos1y < br_pos2y)
{
    intersection = pos2x - br_pos1x;
    Rectangle intrect12(Point(pos2x,pos2y), intersection, intersection);
    win.attach(intrect12);
    intrect12.set_fill_color(Color::white);
}

if (br_pos1x > pos3x && br_pos1y > pos3y && br_pos1x < br_pos3x && br_pos1y < br_pos3y)
{
    intersection = pos3x - br_pos1x;
    Rectangle intrect13(Point(pos3x,pos3y), intersection, intersection);
    win.attach(intrect13);
    intrect13.set_fill_color(Color::white);
}

if (br_pos2x > pos1x && br_pos2y > pos1y && br_pos2x < br_pos1x && br_pos2y < br_pos1y)
{
    intersection = pos1x - br_pos2x;
    Rectangle intrect21(Point(pos1x,pos1y), intersection, intersection);
    win.attach(intrect21);
    intrect21.set_fill_color(Color::white);
}

if (br_pos2x > pos3x && br_pos2y > pos3y && br_pos2x < br_pos3x && br_pos2y < br_pos3y)
{
    intersection = pos3x - br_pos2x;
    Rectangle intrect23(Point(pos3x,pos3y), intersection, intersection);
    win.attach(intrect23);
    intrect23.set_fill_color(Color::white);
}
if (br_pos3x > pos1x && br_pos3y > pos1y && br_pos3x < br_pos1x && br_pos3y < br_pos1y)
{
    intersection = pos1x - br_pos3x;
    Rectangle intrect31(Point(pos1x,pos1y), intersection, intersection);
    win.attach(intrect31);
    intrect31.set_fill_color(Color::white);
}

if (br_pos3x > pos2x && br_pos3y > pos2y && br_pos3x < br_pos2x && br_pos3y < br_pos2y)
{
    intersection = pos2x - br_pos3x;
    Rectangle intrect32(Point(pos2x,pos2y), intersection, intersection);
    win.attach(intrect32);
    intrect32.set_fill_color(Color::white);
}

win.wait_for_button(); // give control to the display engine
		}
}
return 0;
}


Any idea why this happens? My code was running fine earlier when it ran from line 0 to 65 (or until setting "r3.set_fill_color(Color::red);")

Help would be much appreciated, thank you!
  • Attachment: FLTK_6.cpp
    (Size: 3.74KB, Downloaded 156 times)
Re: FLTK based code unable to compile? [message #1731629 is a reply to message #1731617] Sun, 08 May 2016 12:12 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
This is Off Topic. It has nothing to do with Eclipse CDT. You are asking for someone to debug your code.

Learn to use the debugger. Try looking for places where the values can go negative or be zero. Put in guard statements before each call to Rectangle. I didn't read through this but did notice that in several places you have statements like if (A > B ... intersection = B - A . If A>B then B-A will be negative. Those would be a likely candidates for getting a non-positive value. Whether or not that's what you want, I can't say.

Why did you title this FLTK based code unable to compile? when it is clearly a run time error?
Re: FLTK based code unable to compile? [message #1731636 is a reply to message #1731629] Sun, 08 May 2016 15:07 Go to previous message
Michelle Uy is currently offline Michelle UyFriend
Messages: 6
Registered: May 2016
Junior Member
I do apologize and do not know the differences. Thanks for the heads up
Previous Topic:Avr-objcopy being passed the wrong filename (the extension)
Next Topic:No project are found to import
Goto Forum:
  


Current Time: Tue Mar 19 10:27:56 GMT 2024

Powered by FUDForum. Page generated in 0.02963 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top