worldDraw call getting crashed

worldDraw call getting crashed

Anonymous
Not applicable
2,578 Views
10 Replies
Message 1 of 11

worldDraw call getting crashed

Anonymous
Not applicable

Hi All,

I am experiencing a problem with AcDb3dSolid object with the latest ObjectArx for Autocad Rogue Release Candidate . 

While calling worldDraw with the object it is getting crashed . 

Thanks in advance ! 

 

0 Likes
Accepted solutions (1)
2,579 Views
10 Replies
Replies (10)
Message 2 of 11

moogalm
Autodesk Support
Autodesk Support

Hi,

 

Are you using customWorldDraw ?, if so you need to initialize them properly, you need to call ::rxInit of AcRxObject derived classes. And 

acrxBuildClassHierarchy();

 

vsavAcGiWorldDraw::rxInit(); vsavAcGiContext::rxInit(); vsavAcGiWorldGeometry::rxInit(); vsavAcGiSubEntityTraits::rxInit();

Test code

//--------------------------------//
//  [1/14/2020 moogalm]
class vsavAcGiContext : public AcGiContext
{
public:
	ACRX_DECLARE_MEMBERS(vsavAcGiContext);

	virtual Adesk::Boolean  isPsOut() const { return Adesk::kFalse; }
	virtual Adesk::Boolean  isPlotGeneration() const { return Adesk::kFalse; }
	virtual AcDbDatabase* database() const { return acdbHostApplicationServices()->workingDatabase(); }
	virtual bool            isBoundaryClipping() const { return false; }
	virtual void            disableFastMoveDrag() const {};
	virtual bool            isNesting() const { return false; }
	virtual AcCmEntityColor   effectiveColor() const { return AcCmEntityColor(); }
	virtual AcDb::LineWeight  byBlockLineWeight() const { return AcDb::LineWeight::kLnWt000; }
	virtual AcDbObjectId      byBlockPlotStyleNameId() const { return AcDbObjectId::kNull; }
	virtual bool              supportsTrueTypeText() { return false; }
};

class vsavAcGiSubEntityTraits : public AcGiSubEntityTraits
{
protected:
public:
	ACRX_DECLARE_MEMBERS(vsavAcGiSubEntityTraits);

	virtual void setColor(const Adesk::UInt16 color) {}
	virtual void setTrueColor(const AcCmEntityColor& color) {}
	virtual void setLayer(const AcDbObjectId layerId) {}
	virtual void setLineType(const AcDbObjectId linetypeId) {}
	virtual void setSelectionMarker(const Adesk::LongPtr markerId) {}
	virtual void setFillType(const AcGiFillType fillType) {}
	virtual void setLineWeight(const AcDb::LineWeight lw) {}
	virtual void setLineTypeScale(double dScale = 1.0) {}
	virtual void setMaterial(const AcDbObjectId materialId) {}
	virtual void setPlotStyleName(AcDb::PlotStyleNameType type, const AcDbObjectId& id = AcDbObjectId::kNull) {}
	virtual void setThickness(double dThickness) {}
	virtual Adesk::UInt16 color() const { return 0; }
	virtual AcCmEntityColor trueColor() const { return m_color; }
	virtual AcDbObjectId layerId() const { return AcDbObjectId::kNull; }
	virtual AcDbObjectId        lineTypeId() const { return AcDbObjectId::kNull; }
	virtual AcGiFillType        fillType() const { return AcGiFillType::kAcGiFillNever; }
	virtual AcDb::LineWeight       lineWeight() const { return AcDb::LineWeight::kLnWt000; }
	virtual double lineTypeScale() const { return 1.0; }
	virtual AcDbObjectId materialId() const { return AcDbObjectId::kNull; }
	double thickness() const { return 0.0; }
	virtual AcDb::PlotStyleNameType     getPlotStyleNameId(AcDbObjectId& idResult) const { return AcDb::kPlotStyleNameByLayer; }
	AcCmEntityColor m_color;
};


class vsavAcGiWorldGeometry : public AcGiWorldGeometry
{
public:
	ACRX_DECLARE_MEMBERS(vsavAcGiWorldGeometry);


	virtual void getModelToWorldTransform(AcGeMatrix3d& matrix) const {}
	virtual void getWorldToModelTransform(AcGeMatrix3d& matrix) const {}
	virtual Adesk::Boolean pushModelTransform(const AcGeVector3d& vNormal) { return Adesk::kTrue; }
	virtual Adesk::Boolean pushModelTransform(const AcGeMatrix3d& xMat) { return Adesk::kTrue; }
	virtual Adesk::Boolean popModelTransform() { return Adesk::kTrue; }
	AcGeMatrix3d pushPositionTransform(AcGiPositionTransformBehavior behavior, const AcGePoint3d& offset) { return AcGeMatrix3d::kIdentity; }
	AcGeMatrix3d pushPositionTransform(AcGiPositionTransformBehavior behavior, const AcGePoint2d& offset) { return AcGeMatrix3d::kIdentity; }
	AcGeMatrix3d pushScaleTransform(AcGiScaleTransformBehavior behavior, const AcGePoint3d& extents) { return AcGeMatrix3d::kIdentity; }
	AcGeMatrix3d pushScaleTransform(AcGiScaleTransformBehavior behavior, const AcGePoint2d& extents) { return AcGeMatrix3d::kIdentity; }
	AcGeMatrix3d pushOrientationTransform(AcGiOrientationTransformBehavior behavior) { return AcGeMatrix3d::kIdentity; }
	virtual Adesk::Boolean edge(const AcArray<AcGeCurve2d*>& edges) const { return Adesk::kFalse; }
	virtual Adesk::Boolean  circle(const AcGePoint3d& center, const double radius, const AcGeVector3d& normal) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  circle(const AcGePoint3d& p1, const AcGePoint3d& p2, const AcGePoint3d& p3) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  circularArc(const AcGePoint3d& center, const double radius, const AcGeVector3d& normal, const AcGeVector3d& startVector, const double sweepAngle, const AcGiArcType arcType = kAcGiArcSimple) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  circularArc(const AcGePoint3d& start, const AcGePoint3d& point, const AcGePoint3d& end, const AcGiArcType arcType = kAcGiArcSimple) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  polyline(const Adesk::UInt32 nbPoints, const AcGePoint3d* pVertexList, const AcGeVector3d* pNormal = NULL, Adesk::LongPtr lBaseSubEntMarker = -1) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  polyline(const AcGiPolyline& polylineObj) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  polyPolyline(Adesk::UInt32 nbPolylines, const AcGiPolyline* pPolylines) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  polygon(const Adesk::UInt32 nbPoints, const AcGePoint3d* pVertexList) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  polyPolygon(const Adesk::UInt32 numPolygonIndices, const Adesk::UInt32* numPolygonPositions, const AcGePoint3d* polygonPositions, const Adesk::UInt32* numPolygonPoints, const AcGePoint3d* polygonPoints, const AcCmEntityColor* outlineColors = NULL, const AcGiLineType* outlineTypes = NULL, const AcCmEntityColor* fillColors = NULL, const AcCmTransparency* fillOpacities = NULL) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  mesh(const Adesk::UInt32 rows, const Adesk::UInt32 columns, const AcGePoint3d* pVertexList, const AcGiEdgeData* pEdgeData = NULL, const AcGiFaceData* pFaceData = NULL, const AcGiVertexData* pVertexData = NULL, const bool bAutoGenerateNormals = true) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  shell(const Adesk::UInt32 nbVertex, const AcGePoint3d* pVertexList, const Adesk::UInt32 faceListSize, const Adesk::Int32* pFaceList, const AcGiEdgeData* pEdgeData = NULL, const AcGiFaceData* pFaceData = NULL, const AcGiVertexData* pVertexData = NULL, const struct resbuf* pResBuf = NULL, const bool bAutoGenerateNormals = true) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  text(const AcGePoint3d& position, const AcGeVector3d& normal, const AcGeVector3d& direction, const double height, const double width, const double oblique, const TCHAR* pMsg) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  text(const AcGePoint3d& position, const AcGeVector3d& normal, const AcGeVector3d& direction, const TCHAR* pMsg, const Adesk::Int32 length, const Adesk::Boolean raw, const AcGiTextStyle& pTextStyle) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  xline(const AcGePoint3d& p1, const AcGePoint3d& p2) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  ray(const AcGePoint3d& p1, const AcGePoint3d& p2) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  pline(const AcDbPolyline& lwBuf, Adesk::UInt32 fromIndex, Adesk::UInt32 numSegs) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  draw(AcGiDrawable* pDrawable) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  image(const AcGiImageBGRA32& imageSource, const AcGePoint3d& position, const AcGeVector3d& u, const AcGeVector3d& v, TransparencyMode transparencyMode = kTransparency8Bit) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  rowOfDots(int count, const AcGePoint3d& start, const AcGeVector3d& step) const { return Adesk::kTrue; }
	virtual Adesk::Boolean  ellipticalArc(const AcGePoint3d& center, const AcGeVector3d& normal, double majorAxisLength, double minorAxisLength, double startDegreeInRads, double endDegreeInRads, double tiltDegreeInRads, AcGiArcType arcType = kAcGiArcSimple) const { return Adesk::kTrue; }
	virtual Adesk::Boolean pushClipBoundary(AcGiClipBoundary* pBoundary) { return Adesk::kTrue; }
	virtual void popClipBoundary() {}
	virtual Adesk::Boolean worldLine(const AcGePoint3d pnts[2]) { return Adesk::kTrue; }
	virtual void setExtents(AcGePoint3d* pNewExtents) const {}
};

class vsavAcGiWorldDraw : public AcGiWorldDraw
{
public:
	ACRX_DECLARE_MEMBERS(vsavAcGiWorldDraw);
	vsavAcGiWorldDraw();
	virtual             ~vsavAcGiWorldDraw() {};

	// von AcGiCommonDraw
	virtual AcGiRegenType           regenType() const;
	virtual Adesk::Boolean          regenAbort() const;
	virtual AcGiSubEntityTraits& subEntityTraits() const;
	virtual AcGiGeometry* rawGeometry() const;
	virtual Adesk::Boolean          isDragging() const;

	// This function operates against the current active viewport
	//
	virtual double                deviation(const AcGiDeviationType,
		const AcGePoint3d&) const;
	virtual Adesk::UInt32           numberOfIsolines() const;

	virtual AcGiContext* context(); /*NEW*/


	// von AcGiWorldDraw
	virtual AcGiWorldGeometry& geometry() const;

	// 	linAcGiContext					m_context;
	// 	linAcGiWorldGeometry		m_geometry;
	// 
	// 	AcGiRegenType						m_regenType;
	// 	double									m_deviation;
};

ACRX_NO_CONS_DEFINE_MEMBERS(vsavAcGiContext, AcGiContext)
ACRX_NO_CONS_DEFINE_MEMBERS(vsavAcGiWorldGeometry, AcGiWorldGeometry)
ACRX_NO_CONS_DEFINE_MEMBERS(vsavAcGiSubEntityTraits, AcGiSubEntityTraits)
static vsavAcGiContext cntxt;
static vsavAcGiSubEntityTraits traits;
static vsavAcGiWorldGeometry geom;
ACRX_NO_CONS_DEFINE_MEMBERS(vsavAcGiWorldDraw, AcGiWorldDraw);

vsavAcGiWorldDraw::vsavAcGiWorldDraw() : AcGiWorldDraw() {}
AcGiRegenType vsavAcGiWorldDraw::regenType() const { return kAcGiStandardDisplay; }
Adesk::Boolean vsavAcGiWorldDraw::regenAbort() const { return Adesk::kFalse; }
AcGiSubEntityTraits& vsavAcGiWorldDraw::subEntityTraits() const { return traits; }
AcGiGeometry* vsavAcGiWorldDraw::rawGeometry() const { return &geom; }
Adesk::Boolean vsavAcGiWorldDraw::isDragging() const { return Adesk::kFalse; }
double vsavAcGiWorldDraw::deviation(const AcGiDeviationType, const AcGePoint3d&) const { return 1000.0; }
Adesk::UInt32 vsavAcGiWorldDraw::numberOfIsolines() const { return 3; }
AcGiContext* vsavAcGiWorldDraw::context() { return &cntxt; }
AcGiWorldGeometry& vsavAcGiWorldDraw::geometry() const { return geom; }

//--------------//


extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
{
        switch (msg) {
        case AcRx::kInitAppMsg:
		       acrxDynamicLinker->unlockApplication(appId);
				acrxDynamicLinker->registerAppMDIAware(appId);
				
				vsavAcGiWorldDraw::rxInit();
				vsavAcGiContext::rxInit();
				vsavAcGiWorldGeometry::rxInit();
				vsavAcGiSubEntityTraits::rxInit();
				
				acrxBuildClassHierarchy();

                initApp();
				
                break;
        case AcRx::kUnloadAppMsg:
                unloadApp();
        }
        return AcRx::kRetOK;
}

 

 

 

 

0 Likes
Message 3 of 11

Anonymous
Not applicable

No ! I am not using custom worldDraw , I am simply casting the AcDbEntity to AcDb3dSolid and then calling the worldDraw over AcDb3dSolid . 

 

Adesk::Boolean doViewport;
ExampleCustomWorldDraw *world = new ExampleCustomWorldDraw (&lpoints,regiontype);

doViewport = const_cast<AcDbEntity*>(pEnt)->worldDraw(world);
//The application gets crashed at this line.
// I even tried to call rxInit over ExampleCustomWorldDraw but still it crashes.
Exception thrown at 0x00007FFAC305EDD4 (ac1st24.dll) in acad.exe: 

 

Thanks in advance 

0 Likes
Message 4 of 11

moogalm
Autodesk Support
Autodesk Support

Yeah, you are using custom worldDraw, to recieve entity's worldDraw calls, passing solid's worldDraw call to your derived worldDraw.

 

You need to initialize these in your arx entry point as I shown above.

ExampleCustomWorldDraw ::rxInit();

acrxBuildClassHierachy()

Please share a code snippet which I can reproduce the behavior at my end.

0 Likes
Message 5 of 11

Anonymous
Not applicable
   AcGePoint3dArray lpoints(100,1000);
 const AcGiRegenType type = kAcGiHideOrShadeCommand ;
 //class  ExampleCustomWorldDraw : public AcGiWorldDraw 
 ExampleCustomWorldDraw *world = new ExampleCustomWorldDraw(&lpoints,type);
    if(world)
    {
        AcGeMatrix3d xform ; // some transform matrix calculated elswhere 
  world->geometry().pushModelTransform(xform);
  doViewport = const_cast<AcDbEntity*>(pEnt)->worldDraw(world); // here the application crashes .
  // I am working on the latest API provided for Autocad Release Candidate Rogue version 
  
 }

May be this helps . 

0 Likes
Message 6 of 11

moogalm
Autodesk Support
Autodesk Support

 

I am working on the latest API provided for Autocad Release Candidate Rogue version 

What is that latest API you are working on ? Can you please put your complete code which I can replicate ? you can use ents_dg sample from SDK.

 

 

0 Likes
Message 7 of 11

Anonymous
Not applicable

I have a function callDrawMethod() that takes const AcDbEntity and some other arguments such as AcGePoint3dArray, deviation , AcGiRegenType etc .

Also there is a customWorldDraw variable named as world of Class ExfTranCustomWorldDraw derived from AcGiWorldDraw class which is passed to the worldDraw .

Adesk::Boolean doViewport = const_cast<AcDbEntity*>(pEnt)->worldDraw(world);

Now if the pEnt which is actually AcDb3dSolid derived from AcDbEntity calls worldDraw ie above code it crashes . 

static bool callDrawMethod(const AcDbEntity *pEnt,AcGePoint3dArray &points,
                           bool isEaiObject,double mainDeviation = 1.0,
                           const AcGiRegenType type = kAcGiHideOrShadeCommand,
						   bool bBlkRef = false)
{   
    Adesk::Boolean doViewport;
	
    AcGePoint3dArray lpoints(100,1000);
    static double deviation = getDeviation();
    if(isEaiObject && !isTooling(pEnt))
    {
        deviation = mainDeviation; 
	}
	else
	{
		if(deviation < 1e-5)
		{
			deviation = getDeviation();
		}
		else
		{
			deviation = mainDeviation; 
		}
	}

	//ExampleTranCustomWorldDraw::rxInit();  

	ExampleTranCustomWorldDraw *world = new ExampleTranCustomWorldDraw(&lpoints,type);
    if(world)
    {
        world->setUseMatrix(true);
		if(!bBlkRef)
        {
			world->geometry().pushModelTransform(ExampleTranDataMgr.docData().BaseXform);
		}
        world->setDeviation(deviation);
		if (!pEnt->isKindOf(AcDb3dSolid::desc())) {
			doViewport = const_cast<AcDbEntity*>(pEnt)->worldDraw(world);// code crashes here 
		}
		else
		{
			//ExampleTranCustomWorldDraw::rxInit();
			//world->rxInit();
			doViewport = const_cast<AcDbEntity*>(pEnt)->worldDraw(world);
		}
0 Likes
Message 8 of 11

moogalm
Autodesk Support
Autodesk Support

Hi,

 

You need to call ExampleTranCustomWorldDraw::rxInit in arx entry point in your app initailization switch

See below

extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
{
        switch (msg) {
        case AcRx::kInitAppMsg:
		       acrxDynamicLinker->unlockApplication(appId);
				acrxDynamicLinker->registerAppMDIAware(appId);
				
				ExampleTranCustomWorldDraw ::rxInit();
				
				acrxBuildClassHierarchy();

                initApp();
				
                break;
        case AcRx::kUnloadAppMsg:
                unloadApp();
        }
        return AcRx::kRetOK;
}
0 Likes
Message 9 of 11

Anonymous
Not applicable
Thanks I will check and let you know.
0 Likes
Message 10 of 11

Anonymous
Not applicable

yes I have called the rxInit in the entrypoint , still the issue persist .

extern "C" __declspec(dllexport) AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pPkt)
{
	ExampleTranCustomWorldDraw::rxInit(); 
	acrxBuildClassHierarchy();
	return AcRx::kRetOK
}

so while calling this function:

doViewport = const_cast<AcDbEntity*>(pEnt)->worldDraw(world);

An exception is triggred as shown below :

Unhandled exception at 0x00007FFABF50EDD4 (ac1st24.dll) in acad.exe: 0xC0000005: Access violation reading location 0x0000000000000008. occurred

 

Also it uses the given library with the given version as mentioned below :

AcGeomentObj.dbx

24.0.46.0.101

 

 

0 Likes
Message 11 of 11

Anonymous
Not applicable
Accepted solution

Thanks, Madhukar for being so active on the thread and yes you have paved the way to the solution.

The answer was hiding behind rxInit() only .

Following are the changes done by me :

Custom class derived over AcGiContext was initialized in the following manner earlier :

ACRX_DEFINE_MEMBERS(CustomTranAcGiContext); 

which I changed now to ;

ACRX_NO_CONS_DEFINE_MEMBERS(CustomTranAcGiContext, AcGiContext);

And 

CustomTranAcGiContext::rxInit(); was called inside the InitApp and then acrxBuildClassHierarchy(); was called and we are done . 

Thanks again

0 Likes