Loading assimp

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Mar 26 14:52:42 PDT 2017


On 03/26/2017 11:31 PM, Dlearner wrote:
> SDL_Surface* surface = IMG_Load(filename.ptr);
>     if (surface is null) {
>         writeln("surface is null: ", to!string(IMG_GetError()));
>     } else {
>         writeln(filename);
>     }
>
> From console:
> surface is null: Couldn't open Models/Nanosuit/helmet_diff.pngÇ2ÿ
>
> I'm assuming the previous textures didn't experience this, but I have no
> idea what could be the problem here, especially as the filename seems
> fine when I writeln it.
> :(

How do you construct `filename`? Looks like it's not properly 
null-terminated.

If you followed my (short-sighted) `dup` advice, that doesn't do 
null-termination. Since the original strings are null-terminated, just 
slicing one more character should do the trick. I'd put an assert that 
verifies that the last character is '\0'.

I.e.:
----
string z = x.data[0 .. x.length + 1].idup;
assert(z[$ - 1] == '\0');
----

Generally, don't pass just the pointer of a string unless you know for 
sure that it's properly null-terminated.

If you're using a slice directly, without `dup`-ing, then the original 
aiString would seem to be broken already.


More information about the Digitalmars-d-learn mailing list