FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

sdlsem.d Access Violation (win)

 
Post new topic   Reply to topic     Forum Index -> Derelict
View previous topic :: View next topic  
Author Message
toaster



Joined: 03 Sep 2004
Posts: 7
Location: Lisbon

PostPosted: Fri Sep 03, 2004 9:34 am    Post subject: sdlsem.d Access Violation (win) Reply with quote

I just came across D for the first time and right now i am browsing thru the documentation and playing with available stuff (like derelict).

I found that the sdlsem.d sample gives an Access Violation when executed without args:

C:\dmd\derelict-0.1>bin\sdlsem.exe
Usage: Error: Access Violation

C:\dmd\derelict-0.1>

It was easy to find the error (thanks to "Usage"):

Code:

int main(char[][] args)
{
   if(args.length < 2)
   {
      fprintf(stderr, "Usage: ?s init_value\n", args[0]);
      exit(1);
   }
[...]


This works fine (found by trial and error):

Code:

   if(args.length < 2)
   {
      //fprintf(stderr, "Usage: ?s init_value\n", args[0]);
      fprintf(stderr, "Usage: ?s init_value\n", cast(char*) args[0]);
      exit(1);
   }



C:\dmd\derelict-0.1>bin\sdlsem.exe
Usage: C:\dmd\derelict-0.1\bin\sdlsem.exe init_value

C:\dmd\derelict-0.1>

However, I just "arrived" here so my question: is it a bug in sdlsem or in D?

I got the latest available dmd (dl'ed yesterday) and your ZIP from http://svn.dsource.org/svn/projects/derelict/downloads/derelict-0.1.zip

BTW: all the other tests run perfectly and sdlsem runs too (with at least 1 arg), and derelict is great. And D is great, yesterday i looked at it for the first time and I think I will use it. I hope D grows and derelict grows along.
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Fri Sep 03, 2004 8:16 pm    Post subject: Re: sdlsem.d Access Violation (win) Reply with quote

toaster wrote:


Code:

   if(args.length < 2)
   {
      //fprintf(stderr, "Usage: ?s init_value\n", args[0]);
      fprintf(stderr, "Usage: ?s init_value\n", cast(char*) args[0]);
      exit(1);
   }



However, I just "arrived" here so my question: is it a bug in sdlsem or in D?



It's a bug in the code, not D. I'll have that fixed for the next release. It has to do with the fact that D strings are stored internally in Pascal style (length followed by the string). Casting to char * allows you to pass the string itself without the length. But it still doesn't zero-terminate it (unless things have changed in the last few versions). So it would be more appropriate to use toStringz(arg[0]) (which can also be written as arg[0].toStringz()) rather than casting to char*.

Thanks for bringing this to my attention.

Quote:

I got the latest available dmd (dl'ed yesterday) and your ZIP from http://svn.dsource.org/svn/projects/derelict/downloads/derelict-0.1.zip


There have been several changes and additions to Derelict since 0.1 was released. I recommend that you checkout the latest trunk from SVN and use that instead. There have been a few bugfixes, SDL_image and SDL_audio have been added along with OpenAL, and the load functions have been renamed. I won't be changing the function names again, so if you use the current trunk you won't have to go back later and change your code. Furthermore, I won't be releasing 0.2 until I've completed the Python bindings and run everything through some tests. This is going to be a while yet as I've gotten my hands into too many pies for the time being.

Quote:

BTW: all the other tests run perfectly and sdlsem runs too (with at least 1 arg), and derelict is great. And D is great, yesterday i looked at it for the first time and I think I will use it. I hope D grows and derelict grows along.


Glad you're enjoying it. Welcome aboard!
Back to top
View user's profile Send private message Send e-mail
toaster



Joined: 03 Sep 2004
Posts: 7
Location: Lisbon

PostPosted: Sat Sep 04, 2004 7:51 am    Post subject: Reply with quote

Thank you for your attention and the insight about chars - one can do subtile bugs in a new language. So now i know it's a bad thing to cast strings into char pointers. Im gonna get your newest packages too.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Derelict All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group