Subject: CGAL users discussion list
List archive
[cgal-discuss] Fatal error on calling the constraint triangulation as a DLL function
Chronological Thread
- From: StevenChen06 <>
- To:
- Subject: [cgal-discuss] Fatal error on calling the constraint triangulation as a DLL function
- Date: Sat, 24 Sep 2011 01:42:49 -0700 (PDT)
It happens on CGAL3.8, Windows 7 32 bit. For some kind of input data and some
kind of programming language, the host program will definitely crash if it
call the constraint triangulation procedure as a DLL function.
For instance, Let's see a test DLL library:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_triangulation_2.h>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_2<K> Vb;
typedef CGAL::Constrained_triangulation_face_base_2<K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> TDS;
typedef CGAL::Exact_predicates_tag Itag;
typedef CGAL::Constrained_triangulation_2<K, TDS, Itag> CT;
typedef CT::Point Point;
extern "C" int __declspec(dllexport)
TestTriangulate()
{
//TEST CODE
std::fstream file;
file.open("E:\\TriDebug.md", std::ios::binary|std::ios::in);
assert(file.good());
int seg_cnt;
file.read((char*)&seg_cnt, 4);
CT ct;
for(int i = 0; i < seg_cnt; ++i)
{
double sx, sy, ex, ey;
file.read((char*)&sx, 8);
file.read((char*)&sy, 8);
file.read((char*)&ex, 8);
file.read((char*)&ey, 8);
ct.insert_constraint(Point(sx, sy), Point(ex, ey));
}
file.close();
assert(ct.is_valid());
int face_cnt = ct.number_of_faces();
return face_cnt;
}
It reads constraint segments from file, adds them to CT, then checks the
validation of triangulation. very simple.
Next is the c++ host program:
#include <iostream>
#include <windows.h>
using namespace std;
typedef int (_stdcall *TestFunc)();
int main()
{
HINSTANCE hDllInst = LoadLibrary("NewTri.dll");
if(hDllInst)
{
TestFunc testf;
testf = (TestFunc)GetProcAddress(hDllInst, "TestTriangulate");
if(testf)
{
cout << testf() << endl;
}
FreeLibrary(hDllInst);
}
system("pause");
return 0;
}
Every time it runs good. No crash. No memory problem.
However, Let's try delphi 7:
program test_dll_mem_delphi7;
{$APPTYPE CONSOLE}
uses
SysUtils;
function TestTriangulate: integer; cdecl; external 'NewTri.dll' name
'TestTriangulate';
var
cnt: Integer;
begin
cnt := TestTriangulate;
Writeln(cnt);
end.
it will definitely crash. By debug mode the compiler reports a stackoverflow
exception.
I also tested it by some other programming language and found:
FOR c++(vs2008), c#(vs2008), python(2.7), It runs smoothly and no exception.
FOR Delphi7, DelphiXE, ruby(1.9.2-p0), It always crashes.
I uploaded the dll library and test data.
http://cgal-discuss.949826.n4.nabble.com/file/n3838960/TriDebug.zip
TriDebug.zip
Hope some one could help me, thanks!
BTW, I have another question. What kind of input data does the constraint
triangulation Algorithm favor? What kind of input data should I get rid of?
Because all the crashes only happen under a small number of input data.
--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/Fatal-error-on-calling-the-constraint-triangulation-as-a-DLL-function-tp3838960p3838960.html
Sent from the cgal-discuss mailing list archive at Nabble.com.
- [cgal-discuss] Fatal error on calling the constraint triangulation as a DLL function, StevenChen06, 09/24/2011
Archive powered by MHonArc 2.6.16.