ASSIMP exporting an imported scene without any changes throws exception - c++

I am working on a project where I import a 3D mesh of an avatar using ASSIMP library, update it and export the updated scene again using the same ASSIMP library. To achieve this, as the first step, I have written a code to import a scene and without making any changes I am passing the reference to the export function. But, the export function throws me an error. The main function is as follows (you can verify that I am not making any changes to the imported scene):
int main(int argc, char** argv)
{
string filename = "../Content/PinocchioMesh/Model1.obj";
Assimp::Importer Importer;
//Importer.
cout << "\tReading file using ASSIMP" << endl;
const aiScene* aiscene = Importer.ReadFile(filename.c_str(), aiProcess_JoinIdenticalVertices | \
aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_SortByPType | aiProcess_Triangulate);
string str = Importer.GetErrorString();
if (!aiscene) {
printf("Error parsing '%s': '%s'\n", filename.c_str(), Importer.GetErrorString());
return false;
}
Assimp::Exporter exporter;
const aiExportFormatDesc* format = exporter.GetExportFormatDescription(0);
int lIndex = filename.find_last_of('/');
//const string path = Filename.substr(0,lIndex+1);
string path = "../Content/PinocchioMesh/";
cout << "\tExport path: " << path << endl;
aiReturn ret = exporter.Export(aiscene, format->id, path, aiscene->mFlags);
cout << exporter.GetErrorString() << endl;
return 0;
}
The error is in the Export() function ans says:
First-chance exception at 0x1052591B (Assimp32.dll) in ImportRigExport.exe: 0xC0000005: Access violation reading location 0x00000000.
If anyone has used assimp to export scenes, please help me.

It seems path doesn't include a file name, only the directory part, so that for export() is unlikely to be able to create an output file. Nevertheless, I agree, Assimp should manage this error case.

Related

assimp fail to find the obj. file

I try to use Assimp::Importer.ReadFile() to load my obj.file but it turns out that assimp fail to find the file correctly.
Here is a simple test
#include<string>
#include<assimp/scene.h>
#include <assimp/Importer.hpp>
#include <assimp/postprocess.h>
using namespace std;
int main(){
Assimp::Importer importer;
string modelPath = "D:\\素材\\nanosuit\\nanosuit.obj";
const aiScene* scene = importer.ReadFile(modelPath, aiProcess_Triangulate | aiProcess_FlipUVs );
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) {
cout << "ERROR::ASSIMP::" << importer.GetErrorString() << endl;
}
else cout << scene;
and the output is following text
ERROR::ASSIMP::Unable to open file "D:\素材\nanosuit\nanosuit.obj".
I haved tried to load different obj.file and it doesn't work too
This is a problem with the unicode name. You need to use a workaround to fix this. Use the Wi32-API-Call
SetCurrentDirectory(L"D:\\素材\\nanosuit\\");
to open the folder and import the asset afterwards:
const aiScene* scene = importer.ReadFile(L"nanosuit.obj", aiProcess_Triangulate | aiProcess_FlipUVs );
There is a design error in the Asset-Importer-Lib. The imported name will be used to name the asset and the asset-name is using ASCII. So unicode names will interpreted as ASCII-names and this will cause your error.

"Access violation reading location 0x0000000000000000", OpenCV with C++ trying to opening an image

#include <iostream>
#include <opencv2/highgui.hpp>
using namespace cv;
using namespace std;
// Driver code
int main(int argc, char** argv)
{
//----- COMMAND LINE -----
const String& filename = argv[1];
Mat image = imread(argv[1]);
//----- EXPLICIT WAY -----
//const String& filename = "C:/Users/letto/OneDrive/Things/sonoio.jpg";
//Mat image = imread(filename);
// Error Handling
if (image.empty()) {
cout << "Image File "
<< "Not Found" << endl;
// wait for any key press
cin.get();
return -1;
}
// Show Image inside a window with
// the name provided
imshow("Window Name", image);
// Wait for any keystroke
waitKey(0);
return 0;
}
With the code above I'm trying to open an image.
There are two ways I'm trying to do it:
COMMAND LINE: I pass the image url as a command;
EXPLICIT WAY: I write explicitly the image url.
The second method works perfectly.
With the first method I get this exception:
Exception thrown at 0x00007FFAC1FFF551 (ucrtbased.dll) in OpenImg.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
I'm using Visual Studio Code 2022 so this is the way I'm passing the url through the command line:
Where is the error? Help me find out please, thanks!
You have set - according to the image attached - additional command line arguments to the compiler and not to the app you run.
To add command lines to the app, right click on the project (OpenImg) and choose Debugging -> Command Arguments.
(And, as mentioned by #user4581301, verifying that the argument exists by checking args would've showed that accessing argv[1] would've been out of bounds. Its a good habit to learn.)

How do I delete a file in Qt when the file is already in the file system?

I have a problem when I try to delete a file with Qt.
If I delete it with my Qt application in the same run as the file is created there is no issues, if I try to delete it when it already exists before the application has been launched, I receive an "access denied" issue.
Looking to this code:
int main(int argc, char *argv[])
{
QString path = "MyPath";
QFile file(path+"/test.txt");
if (file.open(QFile::ReadWrite)){
if(!file.setPermissions(QFileDevice::WriteUser | QFileDevice::ReadUser|
QFileDevice::ExeUser)){
std::cout << "Error in permissions" << std::endl;
}
file.close();
if(!QDir().remove(path+"/test.txt"))
std::cout << "Can't delete" << std::endl;
}
}
If I lanch the application, the file is created and then delete without any problem. If I try to access the file in Qt when it has already been created (by the application in a previous run, skipping the remove part of code) the file can't be delete or accessed.
I have tried to set the permissions but nothing has changed

GPKG not recognized as a supported file format

I try to read in a gpkg file to extract geo informations like streets and buildings.
Therefor I started with this code:
#include "gdal_priv.h"
#include <iostream>
int main() {
GDALDataset* poDataset;
GDALAllRegister();
std::cout << "driver# " << GetGDALDriverManager()->GetDriverCount()
<< std::endl;
for (int i = 0; i < GetGDALDriverManager()->GetDriverCount(); i++) {
auto driver = GetGDALDriverManager()->GetDriver(i);
auto info = driver->GetDescription();
std::cout << "driver " << i << ": " << info << std::endl;
}
auto driver = GetGDALDriverManager()->GetDriverByName("GPKG");
poDataset = (GDALDataset*)GDALOpen("Building_LoD1.gpkg", GA_ReadOnly);
if (poDataset == NULL) {
// ...;
}
return 0;
}
The driver list contains GPKG, but the reading fails with an error that the file is not recognized as supported file format.
Doing a gdalinfo Building_LoD1.gpkg leads to the same error in the console. But I can open the file in QGIS.
And a gdalsrsinfo Building_LoD1.gpk reports:
PROJ.4 : +proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs
OGC WKT :
PROJCS["CH1903+ / LV95",
GEOGCS["CH1903+",
DATUM["CH1903+",
SPHEROID["Bessel 1841",6377397.155,299.1528128,
AUTHORITY["EPSG","7004"]],
TOWGS84[674.374,15.056,405.346,0,0,0,0],
AUTHORITY["EPSG","6150"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4150"]],
PROJECTION["Hotine_Oblique_Mercator_Azimuth_Center"],
PARAMETER["latitude_of_center",46.95240555555556],
PARAMETER["longitude_of_center",7.439583333333333],
PARAMETER["azimuth",90],
PARAMETER["rectified_grid_angle",90],
PARAMETER["scale_factor",1],
PARAMETER["false_easting",2600000],
PARAMETER["false_northing",1200000],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AXIS["Easting",EAST],
AXIS["Northing",NORTH],
AUTHORITY["EPSG","2056"]]
Does anyone know why a gpkg file might be reported as not supported?
The gdal version is 2.3.2.
I figured out the problem. The reason for the message is not that the file format is not support by gdal, but that I used the wrong function to open the file.
If I want to read in a file that has vector information then I need to use:
GDALDataset* poDS;
poDS = (GDALDataset*)GDALOpenEx( "Building_LoD1.gpkg", GDAL_OF_VECTOR, NULL, NULL, NULL);

Assimp md5 scene with animations "has no animations"

I've been following the tutorials at OGLdev and LearnOpenGL to load assimp files. I can load static objects like the crysis nanosuit and the animated doom3 format model "boblampclean". The problem is that I cant get the animations from the md5 file. When I query whether the file has animations it returns 0 and other calls to get animation related things from it crash. I've tried different versions of assimp - 3.0, 3.1.1, and 3.3.3 built from vcpkg.
For example, if I run this it will return 0 although there is for sure an animation in the file. If I use the 32bit visual studio project from OGLdev it returns 1.
int main(int argc, char *argv[])
{
Assimp::Importer myImporter;
const aiScene *m_scene = NULL;
m_scene = myImporter.ReadFile("C:/users/bergj/desktop/obj/boblampclean.md5mesh", aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenSmoothNormals | aiProcess_JoinIdenticalVertices | aiProcess_CalcTangentSpace);
if (m_scene)
{
cout << "has anim = " << m_scene->HasAnimations() << endl;
}
else
{
cout << "no scene" << endl;
}
return 0;
}
I had to copy the md5anim file into the same folder. Damn.