Segmentation fault in xfoilrun API example #8
-
|
Hello, I am very new to C++, but after a lot of trial and errors, I finally managed to compile flow5. However, after compiling and running the API examples, I get a segmentation fault in the xfoilrun, line 20 (Foil *pFoil = foil::makeNacaFoil(2410, nacaname);). Debugger says: Thread 1 "XFoilRun" received signal SIGSEGV, Segmentation fault. I find this very strange because planerun works fine despite also calling foil::makeNacaFoil. Did I do something wrong in my libraries installs and compilation, and if so, what could the problem be? Or is it an issue with the code of the example? Thank you very much for your help :) |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
|
Can't think of a reason why PlaneRun would run and not XFoilRun. Both work fine on my linux distro. |
Beta Was this translation helpful? Give feedback.
-
|
Hello, thanks for the answer. Replacing the content of the main function in PlaneRun by the one of XFoilRun still results in a segmentation fault (I did not re-run CMake, nor change the imports in planerun.cpp). Running in debug mode, gdb outputs this: while ValGrind outputs this: I tried to run ValGrind on the apparently working original PlaneRun (and a reduced version of it with just the first call to Surprisingly, commenting out the lines after the call to #include <iostream>
#include <api.h>
#include <constants.h>
#include <foil.h>
#include <objects2d.h>
#include <objects3d.h>
#include <oppoint.h>
#include <planeopp.h>
#include <planepolar.h>
#include <planetask.h>
#include <planexfl.h>
#include <polar.h>
#include <xfoiltask.h>
int main()
{
printf("flow5 XFoil run\n");
std::string nacaname = "theNaca2410";
std::cout << "Making foil " << nacaname << std::endl;
Foil *pFoil = foil::makeNacaFoil(2410, nacaname); // "high level" function which also inserts the foil object in the database
if(pFoil)
std::cout <<"The foil "<< pFoil-> name() <<" has been created and added to the database" << std::endl<< std::endl;
else
{
std::cout <<"Error creating the foil ...aborting" << std::endl;
return 0;
}
// std::string coords = pFoil->listCoords();
// std::cout << coords << std::endl;
std::cout << "Foil properties:" << std::endl;
std::cout << pFoil->name() << std::endl;
std::string props = pFoil->properties(true);
std::cout << props << std::endl << std::endl;
Polar *pPolar = Objects2d::createPolar(pFoil, xfl::T1POLAR, 100000.0, 0.0, 9.0, 1.0, 1.0); // "low level" function
pPolar->setName("T1 test polar");
Objects2d::insertPolar(pPolar); // so that it won't get lost and will be neatly deleted on exit
std::cout << "polar properties:" << std::endl;
std::cout << pPolar->name() << std::endl;
std::cout << pPolar->properties() << std::endl << std::endl;
bool bKeepOpps=true; // otherwise will still store the results in the polar but will discard (and delete) the operating point objects
// XFoilTask task;
// [...]
globals::deleteObjects(); // Must call! will delete the foil and the polar objects
return 0;
}but uncommenting the This leads me to believe there is a subtle bug somewhere despite which the code works by accident in most cases, but not all the time, and fails for me in this case (perhaps the compiler does memory allocations in a weird order when adding the Finally, I think CMake makes me compile with GCC (C++) GNU 13.3.0 I hope this helps. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the detailed feedback. Let me know how it goes on your side. |
Beta Was this translation helpful? Give feedback.
-
|
It worked, thank you very much! |
Beta Was this translation helpful? Give feedback.
Thanks for the detailed feedback.
Problem reproduced and solved by allocating the task on the heap: