Loading assimp
Dlearner via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Mar 27 10:32:32 PDT 2017
On Sunday, 26 March 2017 at 21:52:42 UTC, ag0aep6g wrote:
> 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.
Ahh you were absolutely right. I concatenated a '\0' and it
worked. Silly me!
Most of the textures loaded and a really broken model appears,
but I'm guessing that's a result of trying to follow along with a
tutorial written for C++ in D.
Thank you for your help. I really appreciate it. :)
More information about the Digitalmars-d-learn
mailing list