C++/Tkで、coordsの取得時にエラーとなる †今回は以下のように、アイテムの持つ座標を取得しようとした時のバグに対応したい。 Box coords( ".c" << coords( active ) ); コンパイルは通るが実行時エラーとなる。 //int cx = ( ".c" << canvasx( vd_x, GRID_H ) ); // グリッド付加と座標の取得 *実行時エラー* // //int cy = ( ".c" << canvasy( vd_y, GRID_V ) ); // グリッド付加と座標の取得 *実行時エラー* // double cx = ( ".c" << canvasx( vd_x, GRID_H ) ); // グリッド付加と座標の取得 *実行OK* // double cy = ( ".c" << canvasy( vd_y, GRID_V ) ); // グリッド付加と座標の取得 *実行OK* // これらのTclコマンドは実数型を戻し、APIの方で整数型に対応していないのではないかと考えている。 制約事項 †cpptk-1.0.2およびboost_1_34を使用。 /* This is OK for me ******************************************//* Boxを使ったcoords取得時バグ対応 */ details::Expr::operator Tk::Box() const { string ret(cmd_->invoke()); if (ret.empty()) { return Tk::Box(0, 0, 0, 0); } int len = getResultLen(); if (len < 4) { throw TkError("Cannot convert the result list to Box\n"); } // int x1 = getResultElem<int>(0); // Tcl_GetIntFromObj()でエラーとなるため変更 // // int y1 = getResultElem<int>(1); // Tcl_GetIntFromObj()でエラーとなるため変更 // // int x2 = getResultElem<int>(2); // Tcl_GetIntFromObj()でエラーとなるため変更 // // int y2 = getResultElem<int>(3); // Tcl_GetIntFromObj()でエラーとなるため変更 // // // // // return Box(x1, y1, x2, y2); // Tcl_GetIntFromObj()でエラーとなるため変更 // int x1 = (int)(getResultElem<double>(0) + 0.5); // Tcl_GetDoubleFromObj()の戻り値四捨五入で対応 // int y1 = (int)(getResultElem<double>(1) + 0.5); // Tcl_GetDoubleFromObj()の戻り値四捨五入で対応 // int x2 = (int)(getResultElem<double>(2) + 0.5); // Tcl_GetDoubleFromObj()の戻り値四捨五入で対応 // int y2 = (int)(getResultElem<double>(3) + 0.5); // Tcl_GetDoubleFromObj()の戻り値四捨五入で対応 // // // return Box(x1, y1, x2, y2); // Tcl_GetDoubleFromObj()の戻り値四捨五入で対応 // } //*This is OK for me ******************************************//* Boxを使ったcoords取得時バグ対応 */ 修正履歴 †課題 †参考ページ † |