March 14, 2011
On 3/14/2011 2:55 AM, Gene P. Cross wrote:
> I haven't a debugger at the moment, could you recommend one ?
Sorry, I use GDB with GDC.  I don't know about DMD, it may work with GDB on linux.  You could try installing GDC and see if the results are the same.  That may help to rule out the compiler itself.

> I also made the string a char[] and tested to see if that made a difference.
That also requires using some of the previous examples to append '\0' first.

> 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.
Can you install a program that uses SDL and are you running 64-bit? Could be possible you're trying to call a 64-bit function from 32-bit code.

> I read the docs earlier and found the same thing about literals being null
> terminated but not regular strings,
Every suggestion so far should take care of that issue.

March 14, 2011
On 3/14/2011 3:07 AM, Gene P. Cross wrote:
> 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.
That sounds like an issue, I've ran into on occasion.  When using runtime bindings for shared libraries.  If you forget to initialize them in every module first thing.  The program will segfault.
March 14, 2011
Thanks for your help, and from here on in I'll be sure to initialise first thing. I'll look into GDB, thanks again.
March 14, 2011
On Monday 14 March 2011 00:07:05 Gene P. Cross wrote:
> 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.

It happens to us all from time to time. At least you found the problem.

- Jonathan M Davis
March 14, 2011
> 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

Well strings are put into read-only space on Linux and I guess this is also the case for D1.
Since you are doing a ~= it probably tries to alter that value and crashes.

You should use something like SDL_LoadBMP(cast(char*)(path ~ "\0")) if you really wanted to convert it manually.
But the proper way to convert a string to a C char* is to use toStringz.
March 14, 2011
On Monday, March 14, 2011 10:54:57 Trass3r wrote:
> > 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
> 
> Well strings are put into read-only space on Linux and I guess this is
> also the case for D1.
> Since you are doing a ~= it probably tries to alter that value and crashes.

No. If it can't concatenate in place, then it will reallocate the array. The fact that it was in read-only memory is irrelevant. It just means that reallocation is guaranteed instead of being only possible.

- Jonathan M Davis
1 2
Next ›   Last »