This works on linux...but why not windows?

This is a discussion on This works on linux...but why not windows? within the C Programming forums, part of the General Programming Boards category; I am trying to get a game I've been working on for linux to run on windows. It is all ...

  1. #1
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222

    This works on linux...but why not windows?

    I am trying to get a game I've been working on for linux to run on windows. It is all compiling ok but when I try and read in the quake to models, fseek is failing to read all the data on the windows build.

    using the following code

    Code:
    	if ( fseek( fp, model_header->offset_triangles, SEEK_SET ) == 0 ) {
    		if (( model->nr_triangles = fread( model->triangle,
    		    sizeof(*model->triangle), model_header->nr_triangles, fp ))
    			!= model_header->nr_triangles ) {
    			 fprintf( stderr,"Error reading triangles from model file (%d).\n", model->nr_triangles );
    				return NULL;
    		}
    	}
    the value for model_header->nr_triangles is correct but the value that fread returns is not it and the app is failing with the error message.

    This works fine on the linux build... is windows different or is my code bad?
    Last edited by Kinasz; 12-27-2005 at 03:24 AM.
    "Assumptions are the mother of all **** ups!"

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,334
    Perhaps you failed to open the file in binary mode on windows.

    Perhaps the structures are padded differently between the two machines - simply copying a binary file containing structures written with fwrite() from one machine to another is full of fun for all the family.

    > stderr,"Error reading triangles from model file (%d).\n"
    You could have at least printed the value you expected as well.
    In addition, the fseek() call itself needs an "else error message" bit of code.

    > is windows different or is my code bad?
    Yes and Yes
    Or more specifically, your assumptions of portability are probably wrong.

  3. #3
    ex-DECcie
    Join Date
    Dec 2005
    Posts
    125
    Quote Originally Posted by Salem

    Perhaps the structures are padded differently between the two machines - simply copying a binary file containing structures written with fwrite() from one machine to another is full of fun for all the family.

    If agree with Salem -- structure padding and alignment will often bite you in the nether regions when transitioning code between Linux and Windows.

    I'd start there first......

  4. #4
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222
    The files I am reading in are quake 2 models. They come from windows machines.

    I am not sure what you guys mean by structure padding and alignment, a google search hasn't helped me to understand either.

    I never assumed portability, but I was expecting the errors at compile time and this one has me stumped. Can you please elaborate on padding/alignment for me?

    ps: This was the full code block, I removed what i thought was irrelevant to make it more readable:
    Code:
    print_model_info( model_header );
    
    	/* Load triangles. */
    	if ( fseek( fp, model_header->offset_triangles, SEEK_SET ) == 0 ) {
    		
    		if (( model->nr_triangles = fread( model->triangle,
    		    sizeof(*model->triangle), model_header->nr_triangles, fp ))
    			!= model_header->nr_triangles ) {
    			 fprintf( stderr, "Error reading triangles from model file (%d).\n", model->nr_triangles );
    				return NULL;
    		}
    	} else {
    		fprintf( stderr, "Error reading triangles from model file. 2\n" );
    		return NULL;
    	}
    The print_model_info() call does give print the value I was expecting as well as all of the other file header info.
    Last edited by Kinasz; 12-28-2005 at 03:22 AM.
    "Assumptions are the mother of all **** ups!"

  5. #5
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222
    Solved problem, it was binary mode. Something I had never heard of until now nor read in the man page.

    Thankyou for you help salem, but I am still interested if you could elaborate on padding please
    "Assumptions are the mother of all **** ups!"

  6. #6
    Registered User TactX's Avatar
    Join Date
    Oct 2005
    Location
    Germany.Stuttgart
    Posts
    65
    Quote Originally Posted by Kinasz
    Thankyou for you help salem, but I am still interested if you could elaborate on padding please
    This link should make things clear.

  7. #7
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222
    Thankyou that link has been very helpful
    "Assumptions are the mother of all **** ups!"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux vs Windows
    By manav in forum A Brief History of Cprogramming.com
    Replies: 114
    Last Post: 04-08-2008, 08:32 AM
  2. GUI library that works on windows and linux?
    By Logan in forum C++ Programming
    Replies: 2
    Last Post: 04-28-2006, 08:40 PM
  3. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  4. Linux / Windows
    By MethodMan in forum Linux Programming
    Replies: 19
    Last Post: 07-09-2002, 02:58 PM
  5. Linux Under Windows
    By Strut in forum Linux Programming
    Replies: 3
    Last Post: 05-27-2002, 08:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21