Skip to content
Advertisement

Assimp aiString empty when compiling for Linux

I’m working on a simple OpenGL project and I’m new to C++. I’ve been slowly adding features to a very simple primitive 3D “engine” and I’ve worked to make sure it compiles cross-platform.

I have a make file that I run for OSX and Linux (Ubuntu) and for Windows I have a Visual Studio solution file modified to work with the directory structure of the project.

Each time I make changes I make sure to compile and test on each platform, and its been all great until I added support for load models using Assimp. More specifically, loading models was fine but loading textures is what caused the issue- or rather, reading the texture file name.

What’s peculiar is that this code actually runs and compiles properly on all the platforms I’m targeting: Linux (Ubuntu), OSX, and Windows 10- except that in Ubuntu (and only in Ubuntu) the aiString object from Assimp does not seem to be returning the name of the texture file.

This is the code snippet I’ve narrowed it down to that really displays my problem:

aiString path;
mat->GetTexture(aiTextureType_DIFFUSE, 0, &path);
fprintf(stderr, "Loading texture '%s'...n", path.data);   
std::string full_path = _model_load_path + std::string(path.C_Str());
fprintf(stderr, "Full path: '%s'n", full_path.c_str());   

This is the output on OSX and Windows 10:

Loading texture 'glass_dif.png'...
Full path: 'resources/meshes/nanosuit/glass_dif.png'

This is the output on Ubuntu:

Loading texture ''...
Full path: 'resources/meshes/nanosuit/'

Sure enough the textures are loaded and applied to the model correct in OSX and Windows 10, but not in Ubuntu. Everything else seems to work, including loading the model (it just shows up as black colored since the shader can’t sample the texture color).

The only think I can think of is the version I have installed of libassimp-dev, which is 4, versus 5 on OSX. But I’m a skeptical v4 and all before couldn’t load textures. Could it be how I’m compiling it?

What should I start looking into to troubleshoot this? I’m using gcc on Ubuntu and clang on OSX.

Advertisement

Answer

Alright, so trying to do due diligence I decided to rule out the libassimp-dev version first, since that’s really the only thing that’s different. I was skeptical this was this problem, because how else did the previous versions of libassimp-dev work on Linux?

Well, I don’t know but that was what the problem was. I was avoiding doing that because version 5 on Ubuntu was not available for my version of Linux: https://packages.ubuntu.com/search?keywords=libassimp-dev

With the help of a friend I was able to force install version 5 by temporarily adding the “focal” package repository, install the relevant packages from that new repository and then remove that repository so Ubuntu doesn’t upgrade every other package on the system.

Steps:

1.) Append the following config to /etc/apt/sources.list:

# FIXME: remove me after installing libassimp5 and libassimp-dev
deb http://mirrors.kernel.org/ubuntu focal main universe

2.) Update the package registry and install the relevant packages (and their dependencies):

sudo apt-get update
sudo apt-get install libassimp-dev libassimp5

(I also had an issue where I had to run the recommended fix install command or similar after running this)

3.) After that has installed successfully, then remove the lines added to /etc/apt/sources.list

Make sure you do not run sudo apt-get upgrade now, as it will try to upgrade all the packages on your system to that new version of Ubuntu, which may have unforeseen consequences.

4.) Update your package registry again (to remove traces of the new repository)

sudo apt-get update

Recompiling my project after that worked- the string correctly displayed the material file path and the application loaded textures and applied them to the model correctly.

Credit for those steps and instructions to Dominic Barnes: https://stackoverflow.com/users/188702/dominic-barnes

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement