Author Topic: Alien Error!  (Read 3051 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
Alien Error!
« on: June 24, 2012, 12:48:41 PM »
Deleted.
« Last Edit: May 05, 2015, 11:52:24 AM by Peter »

Charles Pegge

  • Guest
Re: Alien Error!
« Reply #1 on: June 24, 2012, 04:36:02 PM »
Of course.

Assuming the function returns a pointer to the image surface, I think it should be:


dim image* as SDL_Surface
@image = SDL_LoadBMP "bmp/devil.bmp"


Then you have access to all the members of image, which should be easy to test.



« Last Edit: June 24, 2012, 04:44:03 PM by Charles Pegge »

Charles Pegge

  • Guest
Re: Alien Error!
« Reply #2 on: June 25, 2012, 11:12:12 AM »
Not a precise match. Have you tried accessing the pixels directly, Peter?

Code: C
  1. typedef struct SDL_Surface {
  2.         Uint32 flags;                           /**< Read-only */
  3.         SDL_PixelFormat *format;                /**< Read-only */
  4.         int w, h;                               /**< Read-only */
  5.         Uint16 pitch;                           /**< Read-only */
  6.         void *pixels;                           /**< Read-write */
  7.         int offset;                             /**< Private */
  8.  
  9.         /** Hardware-specific surface info */
  10.         struct private_hwdata *hwdata;
  11.  
  12.         /** clipping information */
  13.         SDL_Rect clip_rect;                     /**< Read-only */
  14.         Uint32 unused1;                         /**< for binary compatibility */
  15.  
  16.         /** Allow recursive locks */
  17.         Uint32 locked;                          /**< Private */
  18.  
  19.         /** info for fast blit mapping to other surfaces */
  20.         struct SDL_BlitMap *map;                /**< Private */
  21.  
  22.         /** format version, bumped at every change to invalidate blit maps */
  23.         unsigned int format_version;            /**< Private */
  24.  
  25.         /** Reference count -- used when freeing surface */
  26.         int refcount;                           /**< Read-mostly */
  27. } SDL_Surface;
  28.  

Charles Pegge

  • Guest
Re: Alien Error!
« Reply #3 on: June 25, 2012, 10:02:59 PM »

Here is a bare-bones SDL Header and test progs. Just add SDL.DLL to the folder.

I hope it resolves the pointer/address issues for you, Peter

Charles


Charles Pegge

  • Guest
Re: Alien Error!
« Reply #4 on: June 26, 2012, 02:50:15 AM »
Similar code after beauty-treatment. :)

The let syntax is a cleaner alternative for creating objects and it can be used with all those  SDL functions that return a pointered structure.

These three lines all do the same: (the return type of SDL_LoadBMP is SDL_Surface*)

let loadedImage = SDL_LoadBMP filename

SDL_Surface* loadedImage : @loadedImage =  SDL_LoadBMP filename

SDL_Surface loadedImage at ( SDL_LoadBMP filename )


Code: OxygenBasic
  1.  
  2.  
  3.   'tutorials
  4.  'http://www.lazyfoo.net/SDL_tutorials/lesson02/index.php
  5.  
  6.  
  7.   extern cdecl lib "sdl.dll"
  8.   include "MinSdl.inc"
  9.   end extern
  10.  
  11.   function load_image( string filename ) as SDL_Surface*
  12.   '=====================================================
  13.  '
  14.  let loadedImage = SDL_LoadBMP filename
  15.   if @loadedImage
  16.     let optimizedImage = SDL_DisplayFormat loadedImage
  17.     SDL_FreeSurface loadedImage
  18.     return optimizedImage
  19.   end if
  20.   end function
  21.  
  22.  
  23.   function main() as int
  24.   '=====================
  25.  '
  26.  SDL_Rect DestRect
  27.   sys er
  28.   er=SDL_Init SDL_INIT_EVERYTHING
  29.   if er=-1
  30.     return 1
  31.   end if
  32.   let screen = SDL_SetVideoMode 640,480,32, SDL_SWSURFACE
  33.   if not @screen
  34.       return 2  
  35.   end if
  36.   SDL_WM_SetCaption "Hello World", NULL
  37.   '
  38.  let angel = load_image "angel.bmp"
  39.   DestRect<=100,100
  40.   SDL_BlitSurface Angel, NULL, screen, DestRect
  41.   '
  42.  let bat = load_image "bat.bmp"
  43.   DestRect<=280,240
  44.   SDL_BlitSurface bat, NULL, screen, DestRect
  45.   '
  46.  if SDL_Flip( screen ) = -1
  47.       return 3;    
  48.   end if
  49.   SDL_Delay 3000 'ms
  50.  SDL_FreeSurface angel
  51.   SDL_FreeSurface bat
  52.   SDL_Quit
  53.   return 0
  54.   end function
  55.  
  56.  
  57.   er=main
  58.  
  59.   if er then print er
  60.  
« Last Edit: June 26, 2012, 03:06:05 AM by Charles Pegge »

Charles Pegge

  • Guest
Re: Alien Error!
« Reply #5 on: June 26, 2012, 03:51:46 AM »
What code are you using Peter? This error occurs when you try to direct-access a type like sdl_surface. As I try to explain: you must use "@" to access the pointer value.

Charles

Charles Pegge

  • Guest
Re: Alien Error!
« Reply #6 on: June 26, 2012, 06:38:04 AM »
Not sure which version you have.

This one is up to the minute

[attachment deleted by admin]

Charles Pegge

  • Guest
Re: Alien Error!
« Reply #7 on: June 27, 2012, 02:13:32 AM »

I have a consolidated header for SDL. It is very large because most of it seems to be equates for OpenGl. If this is excluded then including SDL headers in the standard package is quite feasible, and, for the sake of maintenance, I would try to keep as close to the original C headers as possible.

Users will have to download their own SDL.DLL however.

Charles