Перейти к публикации

"unhandled exception encountered in callback automation code" что за зверь?


ETEMA

Рекомендованные сообщения

Пишу программу на C++ для создания сплайна по точкам, полученным с другой кривой. Точки получаю все нормально. Даже сплайн выстраивает. но вылетает вот такая ошибка "unhandled exception encountered in callback automation code" и отменяет построение сплайна и периодически убивает UG.

Вот листинг:

#include "Razvertka.hpp"

#include "uf_modl.h"

#include <uf_ui_ugopen.h>

#include <NXOpen/Curve.hxx>

#include <NXOpen/NXObjectManager.hxx>

#include <uf.h>

#include <uf_curve.h>

#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))

static FILE* prterr;

static int errorCode;

static tag_t part;

static int report( char *file, int line, char *call, int irc)

{

if (irc)

{

char messg[133];

printf("%s, line %d: %s\n", file, line, call);

(UF_get_fail_message(irc, messg)) ?

printf(" returned a %d\n", irc) :

printf(" returned error %d: %s\n", irc, messg);

}

return(irc);

}

using namespace NXOpen;

using namespace NXOpen::BlockStyler;

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

// Initialize static variables

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

Session *(Razvertka::theSession) = NULL;

UI *(Razvertka::theUI) = NULL;

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

// Declaration of global variables

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

Razvertka *theRazvertka;

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

// Constructor for NX Styler class

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

Razvertka::Razvertka()

{

try

{

// Initialize the NX Open C++ API environment

Razvertka::theSession = NXOpen::Session::GetSession();

Razvertka::theUI = UI::GetUI();

theDialogName = "Razvertka.dlx";

theDialog = Razvertka::theUI->CreateDialog(theDialogName.c_str());

// Registration of callback functions

theDialog->AddApplyHandler(make_callback(this, &Razvertka::apply_cb));

theDialog->AddOkHandler(make_callback(this, &Razvertka::ok_cb));

theDialog->AddUpdateHandler(make_callback(this, &Razvertka::update_cb));

theDialog->AddInitializeHandler(make_callback(this, &Razvertka::initialize_cb));

theDialog->AddDialogShownHandler(make_callback(this, &Razvertka::dialogShown_cb));

}

catch(exception& ex)

{

//---- Enter your exception handling code here -----

throw;

}

}

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

// Destructor for NX Styler class

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

Razvertka::~Razvertka()

{

if (theDialog != NULL)

{

delete theDialog;

theDialog = NULL;

}

}

//------------------------------- DIALOG LAUNCHING ---------------------------------

//

// Before invoking this application one needs to open any part/empty part in NX

// because of the behavior of the blocks.

//

// Make sure the dlx file is in one of the following locations:

// 1.) From where NX session is launched

// 2.) $UGII_USER_DIR/application

// 3.) For released applications, using UGII_CUSTOM_DIRECTORY_FILE is highly

// recommended. This variable is set to a full directory path to a file

// containing a list of root directories for all custom applications.

// e.g., UGII_CUSTOM_DIRECTORY_FILE=$UGII_ROOT_DIR\menus\custom_dirs.dat

//

// You can create the dialog using one of the following way:

//

// 1. USER EXIT

//

// 1) Create the Shared Library -- Refer "Block UI Styler programmer's guide"

// 2) Invoke the Shared Library through File->Execute->NX Open menu.

//

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

extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)

{

try

{

theRazvertka = new Razvertka();

// The following method shows the dialog immediately

theRazvertka->Show();

}

catch(exception& ex)

{

char S[127];

sprintf(S,"ufsr error\n");

UF_UI_write_listing_window(S);

//---- Enter your exception handling code here -----

Razvertka::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());

}

if(theRazvertka != NULL)

{

delete theRazvertka;

}

}

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

// This method specifies how a shared image is unloaded from memory

// within NX. This method gives you the capability to unload an

// internal NX Open application or user exit from NX. Specify any

// one of the three constants as a return value to determine the type

// of unload to perform:

//

//

// Immediately : unload the library as soon as the automation program has completed

// Explicitly : unload the library from the "Unload Shared Image" dialog

// AtTermination : unload the library when the NX session terminates

//

//

// NOTE: A program which associates NX Open applications with the menubar

// MUST NOT use this option since it will UNLOAD your NX Open application image

// from the menubar.

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

extern "C" DllExport int ufusr_ask_unload()

{

//return (int)Session::LibraryUnloadOptionExplicitly;

return (int)Session::LibraryUnloadOptionImmediately;

//return (int)Session::LibraryUnloadOptionAtTermination;

}

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

// Following method cleanup any housekeeping chores that may be needed.

// This method is automatically called by NX.

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

extern "C" DllExport void ufusr_cleanup(void)

{

try

{

//---- Enter your callback code here -----

}

catch(exception& ex)

{

}

}

int Razvertka::Show()

{

try

{

theDialog->Show();

}

catch(exception& ex)

{

//---- Enter your exception handling code here -----

Razvertka::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());

}

return 0;

}

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

//---------------------Block UI Styler Callback Functions--------------------------

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

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

//Callback Name: initialize_cb

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

void Razvertka::initialize_cb()

{

try

{

group01 = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("group01"));

edge_select01 = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("edge_select01"));

group0 = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("group0"));

edge_select0 = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("edge_select0"));

}

catch(exception& ex)

{

//---- Enter your exception handling code here -----

Razvertka::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());

}

}

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

//Callback Name: dialogShown_cb

//This callback is executed just before the dialog launch. Thus any value set

//here will take precedence and dialog will be launched showing that value.

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

void Razvertka::dialogShown_cb()

{

try

{

//---- Enter your callback code here -----

}

catch(exception& ex)

{

//---- Enter your exception handling code here -----

Razvertka::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());

}

}

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

//Callback Name: apply_cb

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

tag_t x;

//tag_t y;

int Razvertka::apply_cb()

{

int errorCode = 0;

try

{

UF_CALL(UF_initialize());

// Подготовка данных для UF_MODL_ask_curve_points

double ctol = 0.5;

double atol = 0.0;

double stol = 0.5;

double *pts;

int numpts;

int i;

double p = NULL;

char S[127];

UF_UI_open_listing_window();

//Расчет координат и количества точек

UF_CALL(UF_MODL_ask_curve_points(x,ctol,atol,stol,&numpts, &pts));

int num = numpts;

// Вывод полученных точек

for(i = 0; i < numpts; i++)

{

sprintf(S,"%f %f %f\n",pts[3*i], pts[3*i+1], pts[3*i+2]);

UF_UI_write_listing_window(S);

}

///////////////////////////////////////////////////////

//Ввод данных для UF_CURVE_create_spline_thru_pts

UF_CURVE_pt_slope_crvatr_t *point_data;

point_data = new UF_CURVE_pt_slope_crvatr_t[numpts/3];

// double* parameters;

// parameters = new double[numpts/3];

int degree = 3;

int periodicity = 0;

int save_def_data = 1;

tag_t splin;

for (int i= 0; i<num; i++)

{

point_data.point[0] = pts[3*i];

point_data.point[1] = pts[3*i+1];

point_data.point[2] = pts[3*i+2];

point_data.slope_type = UF_CURVE_SLOPE_NONE;

point_data.slope[0] = 0;

point_data.slope[1] = 0;

point_data.slope[2] = 0;

point_data.crvatr_type = UF_CURVE_CRVATR_NONE;

point_data.crvatr[0] = 0;

point_data.crvatr[1] = 0;

point_data.crvatr[2] = 0;

}

point_data[0].slope_type = UF_CURVE_SLOPE_AUTO;

point_data[num-1].slope_type = UF_CURVE_SLOPE_AUTO;

point_data[0].crvatr_type = UF_CURVE_CRVATR_NONE;

point_data[num-1].crvatr_type = UF_CURVE_CRVATR_NONE;

// Вывод наклонов и кривизн

sprintf(S,"Slope_Types Crvatr_Types \n");

UF_UI_write_listing_window(S);

for (int i= 0; i<num; i++)

{

sprintf(S," %d %d ",point_data.slope_type,point_data.crvatr_type );

UF_UI_write_listing_window(S);

}

//Построение сплайна по точкам

UF_CALL(UF_CURVE_create_spline_thru_pts(degree,

periodicity,

num,

point_data,

NULL,

save_def_data,

&splin ));

delete(point_data);

//delete(parameters);

UF_free(pts);

UF_CALL(UF_terminate());

}

catch(exception& ex)

{

//---- Enter your exception handling code here -----

errorCode = 1;

Razvertka::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());

}

return errorCode;

}

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

//Callback Name: update_cb

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

int Razvertka::update_cb(NXOpen::BlockStyler::UIBlock* block)

{

try

{

if(block == edge_select01)

{

Curve *curva(dynamic_cast<Curve *>(NXOpen::NXObjectManager::Get(edge_select01->GetProperties()->GetTaggedObjectVector("SelectedObjects").at(0)->GetTag())));

x = curva->GetTag();

}

else if(block == edge_select0)

{

//Curve *curva(dynamic_cast<Curve *>(NXOpen::NXObjectManager::Get(edge_select0->GetProperties()->GetTaggedObjectVector("SelectedObjects").at(0)->GetTag())));

//y = curva->GetTag();

}

}

catch(exception& ex)

{

//---- Enter your exception handling code here -----

Razvertka::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());

}

return 0;

}

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

//Callback Name: ok_cb

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

int Razvertka::ok_cb()

{

int errorCode = 0;

try

{

errorCode = apply_cb();

}

catch(exception& ex)

{

errorCode = 1;

Razvertka::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());

}

return errorCode;

}

Ссылка на сообщение
Поделиться на других сайтах


Может быть убрать пару UF_CALL(UF_initialize()); UF_CALL(UF_terminate()); ?

хуже, думаю, не будет, а там посмотрим дальше...

Ссылка на сообщение
Поделиться на других сайтах

Спасибо за совет.

Вообще я нашел в чем дело было : переполнение массива char S[127].

А теперь что-то с памятью. но хоть строить стал. Ладно буду разбираться

Ссылка на сообщение
Поделиться на других сайтах

Оказалось я неправильно выделил память для data_point. Заменил на :

UF_CURVE_pt_slope_crvatr_t *point_data;

point_data=(UF_CURVE_pt_slope_crvatr_t*)malloc(numpts*sizeof(UF_CURVE_pt_slope_crvatr_t));

Все заработало!

Ссылка на сообщение
Поделиться на других сайтах

Присоединяйтесь к обсуждению

Вы можете опубликовать сообщение сейчас, а зарегистрироваться позже. Если у вас есть аккаунт, войдите в него для написания от своего имени.
Примечание: вашему сообщению потребуется утверждение модератора, прежде чем оно станет доступным.

Гость
Ответить в тему...

×   Вставлено в виде отформатированного текста.   Вставить в виде обычного текста

  Разрешено не более 75 эмодзи.

×   Ваша ссылка была автоматически встроена.   Отобразить как ссылку

×   Ваш предыдущий контент был восстановлен.   Очистить редактор

×   Вы не можете вставить изображения напрямую. Загрузите или вставьте изображения по ссылке.

  • Сейчас на странице   0 пользователей

    Нет пользователей, просматривающих эту страницу.




×
×
  • Создать...