Re: Help passing D strings to C libs

2011-03-14 Thread Gene P. Cross
-Daniel
I tried what you said:

char* ptr = toStringz(path);
SDL_LoadBMP(ptr);

and made a check to see if the pointer is null, which it isn't, but I'm unable 
to
inspect is value, I haven't a debugger at the moment, could you recommend one ?

I also made the string a char[] and tested to see if that made a difference.

I think it may be something to do with SDL itself. I tried calling another
function, SDL_GetTicks(), and that's causing problems as well.


-Jonathan
I read the docs earlier and found the same thing about literals being null
terminated but not regular strings,
which explains why they work.
Double check after double check, I am also certain that no other code is messing
with it and changing values.


Re: Help passing D strings to C libs

2011-03-14 Thread Gene P. Cross
I found the problem.

I've set up my 'main' file to act on various game states and because my load 
state
is physically below the running state (where the problems were occuring), even
though they were getting called first, the program starts in the loading state,
dmd wasn't having it. I tried moving the load state above the rest, and it works
fine. So sorry to have wasted everybody's time with such a simple and stupid
mistake. Thankyou for all your help.


Re: Help passing D strings to C libs

2011-03-14 Thread Gene P. Cross
Thanks for your help, and from here on in I'll be sure to initialise first 
thing.
I'll look into GDB, thanks again.


Help passing D strings to C libs

2011-03-13 Thread Gene P. Cross
Hi, I'm fairly new to D and I'm writing a Space Invaders clone to get myself
acquainted with the language.

I'm having trouble passing D strings (char[]) to SDL, in particular
SDL_LoadBMP(), I keep receiving a segfault.

Heres the code:

void setImg(string path) {
// concat null terminating char to string and cast to c type string when
// passing to SDL_LoadBMP()
path ~= \0;
image = SDL_LoadBMP( cast(char*)path );
}

and the value of path is ./resources/cannon.bmp

I'm using SDL 1.2.14 and DMD 1.067 on Ubuntu 10.10

If someone could tell me what I'm doing wrong it would be greatly appreciated.



Re: Help passing D strings to C libs

2011-03-13 Thread Gene P. Cross
toStringz is in D1 but still no luck, I still get the same error

Thanks for the suggestion though


Re: Help passing D strings to C libs

2011-03-13 Thread Gene P. Cross
I've amended the source to pass the strings pointer (path.ptr) after adding a 
null
but the problem still persists.

I lost for what it could be and I'm certain this is where the problem is, 
because
if I remove the method call, the program runs fine.

I've noticed that calling SDL_LoadBMP and passing a string literal seems to 
work,
instead of a string variable. I might load all the images independently into an
array and have each object reference that array, instead of every object loading
its own.