BIM Coordinator Program (INT) April 22, 2024

Find the next step in your career as a Graphisoft Certified BIM Coordinator!

Archicad C++ API
About Archicad add-on development using the C++ API.

How to use the Geometry::StripPolygon2D()?

Not applicable
I Created a polygon as the example.
The Geometry::ValidatePolygon2DData (&polygon) returns NoError;
The Geometry::CheckPolygon2DDataIntegrity (polygon) also returns NoError.
However when executing Geometry::StripPolygon2D(&cutline1,&cutline2, &polygon, &arPolygons, &wrcode), it crashed!

Why? And is there any example about to using these functions?

	HalfPlane2DData cutline1, cutline2;
	BNZeroMemory(&cutline1, sizeof(HalfPlane2DData));
	BNZeroMemory(&cutline2, sizeof(HalfPlane2DData)); = = 1;
	cutline2.cb = cutline1.cb = 0; = 1; = 2;
	cutline1.sizeOfInhEdgeInfo = cutline2.sizeOfInhEdgeInfo = sizeof(long);

	Geometry::Polygon2DData polygon;
	long defaultVertexInfo = 0;
	long defaultInhEdgeInfo = 0;
	long defaultUniqEdgeInfo = 0;
	long defaultContourInfo = 0;
	long defaultUniqPolygonInfo = 0;

	Geometry::InitPolygon2DData (&polygon,
		sizeof (long), reinterpret_cast<GSPtr> (&defaultVertexInfo),        // vertex informations
		sizeof (long), reinterpret_cast<GSPtr> (&defaultInhEdgeInfo),       // edge informations
		sizeof (long), reinterpret_cast<GSPtr> (&defaultUniqEdgeInfo),      // edge informations
		sizeof (long), reinterpret_cast<GSPtr> (&defaultContourInfo),       // contour informations
		sizeof (long),
		sizeof (long), reinterpret_cast<GSPtr> (&defaultUniqPolygonInfo));  // polyogn informations

	polygon.nContours = 1;
	polygon.contourEnds = reinterpret_cast<UIndex**> (BMhAll ((polygon.nContours+1) * sizeof (UIndex)));
	polygon.contourInfos = BMhAll ((polygon.nContours+1) * sizeof (long));
	(*polygon.contourEnds)[0] = 0; // not used, must be zero
	reinterpret_cast<long*>(*polygon.contourInfos)[0]   = 'C-uu';
	(*polygon.contourEnds)[1] = 5;  // index of the last vertex in the first (main) contour
	reinterpret_cast<long*>(*polygon.contourInfos)[1]   = 'C-01';

	polygon.nVertices = 5;  // first vertices of contours is duplicated in the last (but do not count the unused)
	polygon.vertices      = reinterpret_cast<Coord**> (BMhAll ((polygon.nVertices + 1) * sizeof (Coord)));
	polygon.vertexInfos   = BMhAll ((polygon.nVertices + 1) * sizeof (long));
	polygon.inhEdgeInfos  = BMhAll ((polygon.nVertices + 1) * sizeof (long));
	polygon.uniqEdgeInfos = BMhAll ((polygon.nVertices + 1) * sizeof (long));
	(*polygon.vertices)[0] = Geometry::SetCoord ( 0.0,  0.0); // not used, must be zero
	reinterpret_cast<long*>(*polygon.vertexInfos)[0]   = 'V-uu';
	reinterpret_cast<long*>(*polygon.inhEdgeInfos)[0]  = 'I-uu';
	reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[0] = 'U-uu';

	(*polygon.vertices)[1] = Geometry::SetCoord (0, 0);
	reinterpret_cast<long*>(*polygon.vertexInfos)[1]   = 'V-01';
	reinterpret_cast<long*>(*polygon.inhEdgeInfos)[1]  = 'I-01';
	reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[1] = 'U-01';

	(*polygon.vertices)[2] = Geometry::SetCoord (3, 0);
	reinterpret_cast<long*>(*polygon.vertexInfos)[2]   = 'V-02';
	reinterpret_cast<long*>(*polygon.inhEdgeInfos)[2]  = 'I-02';
	reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[2] = 'U-02';

	(*polygon.vertices)[3] = Geometry::SetCoord (3, 2);
	reinterpret_cast<long*>(*polygon.vertexInfos)[3]   = 'V-03';
	reinterpret_cast<long*>(*polygon.inhEdgeInfos)[3]  = 'I-03';
	reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[3] = 'U-03';

	(*polygon.vertices)[4] = Geometry::SetCoord (0, 2);
	reinterpret_cast<long*>(*polygon.vertexInfos)[4]   = 'V-04';
	reinterpret_cast<long*>(*polygon.inhEdgeInfos)[4]  = 'I-04';
	reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[4] = 'U-04';

	(*polygon.vertices)[5] = Geometry::SetCoord (0, 0);
	reinterpret_cast<long*>(*polygon.vertexInfos)[5]   = 'V-05';
	reinterpret_cast<long*>(*polygon.inhEdgeInfos)[5]  = 'I-05';
	reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[5] = 'U-05';

	polygon.nArcs = 0;

	GSErr gserr = Geometry::ValidatePolygon2DData (&polygon);

	// Check for safety
	gserr = Geometry::CheckPolygon2DDataIntegrity (polygon);

	GS::VAArray<Geometry::Polygon2DData> arPolygons;
	Int32 wrcode;
	bool bStat = Geometry::StripPolygon2D(&cutline1,&cutline2, &polygon, &arPolygons, &wrcode);

	// Clean-up
	gserr = Geometry::FreePolygon2DData (&polygon);


Action Log:
00	0x4C3FBFAC	0x7EF40001	0x34346D56	0x21965DF8

Exception code: C0000005 ACCESS_VIOLATION reading location: 00000000
Fault address:  78145478 01:00014478 MSVCR80.dll

SS:ESP:0023:0013DEB8  EBP:0013DEC0
DS:0023  ES:0023  FS:003B  GS:0000

Floating point Registers:

ST(0) = --------- EMPTY ---------- [0013FD30E1842010] [0]
ST(1) = --------- EMPTY ---------- [8FEEEEEEEEF14000] [1]
ST(2) = --------- EMPTY ---------- [8000000000000000] [2]
ST(3) = --------- EMPTY ---------- [8FEEEEEEEEF14000] [3]
ST(4) = --------- EMPTY ---------- [DFA978332BE29000] [4]
ST(5) = --------- EMPTY ---------- [0000000000000000] [5]
ST(6) = --------- EMPTY ---------- [9A15DD19337E7800] [6]
ST(7) = --------- EMPTY ---------- [FF83BC80661B2800] [7]

 (FAULT is at memmove + 344 bytes)

        78145450 8B448EE8         mov     eax,[esi+ecx*4-0x18]   ds:4E104CEC=E88F4489
        78145454 89448FE8         mov     [edi+ecx*4-0x18],eax   ds:4E104CEC=EC8E448B
        78145458 8B448EEC         mov     eax,[esi+ecx*4-0x14]   ds:4E104CEC=EC8F4489
        7814545C 89448FEC         mov     [edi+ecx*4-0x14],eax   ds:4E104CEC=F08E448B
        78145460 8B448EF0         mov     eax,[esi+ecx*4-0x10]   ds:4E104CEC=F08F4489
        78145464 89448FF0         mov     [edi+ecx*4-0x10],eax   ds:4E104CEC=F48E448B
        78145468 8B448EF4         mov     eax,[esi+ecx*4-0xC]    ds:4E104CEC=F48F4489
        7814546C 89448FF4         mov     [edi+ecx*4-0xC],eax    ds:4E104CEC=F88E448B
        78145470 8B448EF8         mov     eax,[esi+ecx*4-0x8]    ds:4E104CEC=F88F4489
        78145474 89448FF8         mov     [edi+ecx*4-0x8],eax    ds:4E104CEC=FC8E448B
FAULT ->78145478 8B448EFC         mov     eax,[esi+ecx*4-0x4]    ds:4E104CEC=FC8F4489
        7814547C 89448FFC         mov     [edi+ecx*4-0x4],eax    ds:4E104CEC=008D048D
        78145480 8D048D00000000   lea     eax,[00000000+ecx*4]   ds:00000001=????????
        78145487 03F0             add     esi,eax
        78145489 03F8             add     edi,eax
        7814548B FF249594541478                                  ds:00000000=????????
                                  jmp     dword ptr [memmove+0x174 (78145494)+edx*4]
        78145492 8BFF             mov     edi,edi
        78145494 A4               movsb                 ds:00000000=?? es:067FB0B0=B8
        78145495 54               push    esp
        78145496 1478             adc     al,0x78
        78145498 AC               lodsb                                ds:00000000=??
        78145499 54               push    esp

Call stack:
0x78145478!MSVCR80.dll + 87160 (memmove + 344 bytes)
0x4E05FDB3!GSRoot.dll + 64947 (BNCopyMemory + 24 bytes)
0x4ECE05FF!Geometry.dll + 132607 (Geometry::GetCurve2DDataEndDirection + 13429 bytes)
0x4ECE0FCE!Geometry.dll + 135118 (Geometry::GetCurve2DDataEndDirection + 15940 bytes)
0x4ECE1147!Geometry.dll + 135495 (Geometry::StripPolygon2D + 70 bytes)
Ralph Wessel
wcyoot wrote:
when executing Geometry::StripPolygon2D(&cutline1,&cutline2, &polygon, &arPolygons, &wrcode), it crashed! Why?
It's difficult to say from the crash report alone. Can you post the essentials of the code that created the polygon, leading up to the point where it crashes?

Also, I would try to eliminate the possibility that the real problem lies elsewhere in your code, i.e. that an earlier problem has corrupted data structures etc. Make a test case that does just this operation and nothing else. If that works, look for a problem elsewhere in your code.
Ralph Wessel BArch
Not applicable
I have post the code.

I just created a simple polygon as a box:(0,0),(3,0),(3,2),(0,2)
and the strips : x = 1, x = 2.

it crashed in Geometry::StripPolygon2D().
Not applicable
There is something wrong in these codes!
Ralph Wessel
wcyoot wrote:
I have post the code.

Edit: I see - you posted it in the original message.
Ralph Wessel BArch
Ralph Wessel
wcyoot wrote:
However when executing Geometry::StripPolygon2D(&cutline1,&cutline2, &polygon, &arPolygons, &wrcode), it crashed! Why?

	HalfPlane2DData cutline1, cutline2;
	cutline1.sizeOfInhEdgeInfo = cutline2.sizeOfInhEdgeInfo = sizeof(long);
I notice that you set sizeOfInhEdgeInfo for the HalfPlane2DData to a non-zero value, but don't populate inhEdgeInfo with anything? I can't say for certain, but that looks like a potential problem.
Ralph Wessel BArch
Not applicable
Oh,I have no idea about how to set the HalfPlane2DData. there is no example.

Can you tell me ?

Ralph Wessel
wcyoot wrote:
Oh,I have no idea about how to set the HalfPlane2DData. there is no example. Can you tell me ?
Unfortunately, no. I don't use any of these methods or classes because:
  • 1. They lack documentation and/or examples;

    2. I started developing add-ons before they were available, and was forced to write my own.
I will eventually shift to the API classes/methods when the documentation is complete. You may be able to work it out by trial and error. I suggest setting sizeOfInhEdgeInfo to zero first. I'm guessing this data is not strictly essential for the operation.
Ralph Wessel BArch
Not applicable
OK, I have solved it.

Just clear all settings about the infos.

Thanks a lot for Ralph Wessel.
Learn and get certified!

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!