Crash when calling operator += with lazy_exact_nt

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Crash when calling operator += with lazy_exact_nt

shiranchok
Hi,
I have encountered a problem when using CGAL and I was wondering if anyone
knows how to fix this. The problem is that when I run the following code the
application crashes.

The code:
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>

typedef CGAL::Exact_predicates_exact_constructions_kernel    KERNEL;
typedef KERNEL::FT      
        NUMBER_TYPE;

int main( int argc, char* argv[])
{
    NUMBER_TYPE num1 = 4;
    NUMBER_TYPE num2 = 3;

   
    for (int i =0; i< 100000; i++)
    {
        num1+=num2;
    }
    num1 = 5;
    num2 =4;
};

I compile the code with the following preprocessor definitions :
CGAL_USE_GMP;_SECURE_SCL=0

I use CGAL 3.3.1 downloaded from the site using the windows installer (when
tested with vs2005) and boost 1.35 from the Boost Consulting web site.
The code is compiled using Visual Studio 2005 and Visual Studio 2008 compilers
on Windows XP, Windows Vista. The application was tested on various different
computers (both Intel and AMD based). The runtime library is Multi-threaded
Debug when compiled in Debug and Multi-threaded when compiled in Release.
It falls both for Debug and Release.
What I have noticed that when I run the loop for a small number of iterations
the application does not crash. When I increase the number of iterations, the
application crashes in Debug but not in Release. When I increase the number of
iterations furthermore, it also falls in Release.


Here is the call stack when I run it in Debug:
1.
test+.exe!CGAL::Lazy_exact_nt<CGAL::Gmpq>::~Lazy_exact_nt<CGAL::Gmpq>()  + 0x9
bytes C++
2.
test+.exe!CGAL::Lazy_exact_binary<CGAL::Gmpq,CGAL::Gmpq,CGAL::Gmpq>::~Lazy_exact_binary<CGAL::Gmpq,CGAL::Gmpq,CGAL::Gmpq>()
 + 0x54 bytes    C++
3.
test+.exe!CGAL::Lazy_exact_Add<CGAL::Gmpq,CGAL::Gmpq,CGAL::Gmpq>::~Lazy_exact_Add<CGAL::Gmpq,CGAL::Gmpq,CGAL::Gmpq>()
 + 0x2b bytes   C++
4.
test+.exe!CGAL::Lazy_exact_Add<CGAL::Gmpq,CGAL::Gmpq,CGAL::Gmpq>::`scalar
deleting destructor'() + 0x2b bytes C++
 and  166 loops of the following:
5. test+.exe!CGAL::Handle::~Handle()  Line 58 + 0x36 bytes    
C++
6.
test+.exe!CGAL::Lazy<CGAL::Interval_nt<0>,CGAL::Gmpq,CGAL::Lazy_exact_nt<CGAL::Gmpq>,CGAL::To_interval<CGAL::Gmpq>
>::~Lazy<CGAL::Interval_nt<0>,CGAL::Gmpq,CGAL::Lazy_exact_nt<CGAL::Gmpq>,CGAL::To_interval<CGAL::Gmpq>
>()  + 0x2b bytes       C++
7.
test+.exe!CGAL::Lazy_exact_nt<CGAL::Gmpq>::~Lazy_exact_nt<CGAL::Gmpq>()  + 0x2b
bytes    C++
8.
test+.exe!CGAL::Lazy_exact_binary<CGAL::Gmpq,CGAL::Gmpq,CGAL::Gmpq>::~Lazy_exact_binary<CGAL::Gmpq,CGAL::Gmpq,CGAL::Gmpq>()
 + 0x63 bytes    C++
9.
test+.exe!CGAL::Lazy_exact_Add<CGAL::Gmpq,CGAL::Gmpq,CGAL::Gmpq>::~Lazy_exact_Add<CGAL::Gmpq,CGAL::Gmpq,CGAL::Gmpq>()
 + 0x2b bytes   C++
10.   test+.exe!CGAL::Lazy_exact_Add<CGAL::Gmpq,CGAL::Gmpq,CGAL::Gmpq>::`scalar
deleting destructor'() + 0x2b bytes C++

Thank you in advance
Shiran Ben Israel
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Crash when calling operator += with lazy_exact_nt

Sylvain Pion
Administrator
[hidden email] a écrit :

> I have encountered a problem when using CGAL and I was wondering if anyone
> knows how to fix this. The problem is that when I run the following code the
> application crashes.
>
> The code:
> #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
>
> typedef CGAL::Exact_predicates_exact_constructions_kernel    KERNEL;
> typedef KERNEL::FT      
> NUMBER_TYPE;
>
> int main( int argc, char* argv[])
> {
>     NUMBER_TYPE num1 = 4;
>     NUMBER_TYPE num2 = 3;
>
>    
>     for (int i =0; i< 100000; i++)
>     {
> num1+=num2;
>     }
>     num1 = 5;
>     num2 =4;
> };
>
> I compile the code with the following preprocessor definitions :
> CGAL_USE_GMP;_SECURE_SCL=0
>
> I use CGAL 3.3.1 downloaded from the site using the windows installer (when
> tested with vs2005) and boost 1.35 from the Boost Consulting web site.
> The code is compiled using Visual Studio 2005 and Visual Studio 2008 compilers
> on Windows XP, Windows Vista. The application was tested on various different
> computers (both Intel and AMD based). The runtime library is Multi-threaded
> Debug when compiled in Debug and Multi-threaded when compiled in Release.
> It falls both for Debug and Release.
> What I have noticed that when I run the loop for a small number of iterations
> the application does not crash. When I increase the number of iterations, the
> application crashes in Debug but not in Release. When I increase the number of
> iterations furthermore, it also falls in Release.

Thanks for the nicely detailed report.

What you experience is however expected.  Each arithmetic operation on
CGAL::Lazy_exact_nt<> (the type of NUMBER_TYPE) allocates a new node in memory,
so memory gets filled quickly.  Basically, it is not designed to support this
kind of cascaded/iterated operations.  Maybe one way to make your example work
would be to call, say every 100 loop iterations, "num1.exact()".

Anyway, it could be more interesting to see your original application, to see
what the best solution is.

--
Sylvain Pion
INRIA Sophia-Antipolis
Geometrica Project-Team
CGAL, http://cgal.org/
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss