glSDL compiling problem

hi!

i tried to compile glSDL with MSVC++ 6, but i get these two errors:

in line 1702 and 1727: (datasurf->pixels + bpp * fromx); )
void * unknown size

could someone help me?

also: the author should mention to include #define inline __inline, when using MSVC++…

thanks in advance, florian hufsky

The ‘pixels’ value in the SDL_Surface struct is of type void*, which is
what it’s complaining about. When you have something of type void*, it
means that you want it to point to some piece of data, only you don’t
know in advance what kind of data that is. C/C++ need to know the size
of the data it’s pointing to, so when you do operations like addition on
the pointer (such as what you have in your code), the program can add
the correct amount of bytes to the pointer. The reason it is used in
SDL here is because your surfaces can have many formats, for example
RGB, RGBA, or indexed, etc. All of these are different data of
different sizes.

Generally what you want is when you add 1 to the pixels pointer, you
would be at the next pixel (as opposed to a different color component in
the same pixel). So if you have 8bpp indexed data, you would typecast it
to Uint8*. Or if you had 8bpp RGBA data (32 bits total), you would
typecast it to Uint32*. Though you can just add up the bytes yourself,
which is what it looks like you’re trying to do. One way you could do
this is convert ‘pixels’ to type Uint8* (single byte pointer), and then
add in your x coordinate times the BytesPerPixel (not BitsPerPixel,
which bpp usually means). For example:

((Uint8 *)datasurf->pixels + datasurf->format->BytesPerPixel * fromx);

I’m not sure if this would get what you want, since it’s tough to tell
what you’re trying to do exactly from your code snippet. However, (I
think) it would get rid of your compilation error, so you could mess
with it to get what you want from there. Note also that you should lock
the surface (SDL_LockSurface) before accessing the ‘pixels’ data. (Or is
that only for writing operations? Anyone know?) And one last thing, if
you decide to add a ‘y’ coordinate to access your pixels, make sure you
take into account the pitch value in the Surface struct.

Well, I hope you were able to make some sense of this and hopefully fix
your program. If anyone notices any errors, please correct me!

-MikeOn Thu, 2003-06-26 at 13:08, Florian Hufsky wrote:

hi!

i tried to compile glSDL with MSVC++ 6, but i get these two errors:

in line 1702 and 1727: (datasurf->pixels + bpp * fromx); )
void * unknown size

could someone help me?

also: the author should mention to include #define inline __inline, when using MSVC++…

thanks in advance, florian hufsky

hi!

i tried to compile glSDL with MSVC++ 6, but i get these two errors:

in line 1702 and 1727: (datasurf->pixels + bpp * fromx); )
void * unknown size

could someone help me?

That’s a bug in glSDL. It’s not safe to do pointer arithmetics on void
pointers as they don’t point to objects of any specific size.

I thought gcc’s -Wall -Werror would trap this, but obviously it
doesn’t, at least not in this particular case.

also: the author should mention to include #define inline __inline,
when using MSVC++…

You shouldn’t have to. (A C99 compiler should accept “inline”, BTW.)
glSDL should use “inline” from SDL’s begin_code.h. I keep
forgetting to fix that, since I have my own projects make sure
"inline" is defined.

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Thursday 26 June 2003 19.08, Florian Hufsky wrote:

ok. but how can i solve this bug?
i tried to convert to int, but glSDL crashes this way.

earlier this day, you send a mail about a bugfixed msvc++ version, is it
online already?

thanks, florian hufsky> ----- Original Message -----

From: david@olofson.net (David Olofson)
To:
Sent: Thursday, June 26, 2003 10:36 PM
Subject: Re: [SDL] glSDL compiling problem

On Thursday 26 June 2003 19.08, Florian Hufsky wrote:

hi!

i tried to compile glSDL with MSVC++ 6, but i get these two errors:

in line 1702 and 1727: (datasurf->pixels + bpp * fromx); )
void * unknown size

could someone help me?

That’s a bug in glSDL. It’s not safe to do pointer arithmetics on void
pointers as they don’t point to objects of any specific size.

I thought gcc’s -Wall -Werror would trap this, but obviously it
doesn’t, at least not in this particular case.

also: the author should mention to include #define inline __inline,
when using MSVC++…

You shouldn’t have to. (A C99 compiler should accept “inline”, BTW.)
glSDL should use “inline” from SDL’s begin_code.h. I keep
forgetting to fix that, since I have my own projects make sure
"inline" is defined.

file://David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

ok. but how can i solve this bug?
i tried to convert to int, but glSDL crashes this way.

Well, that’s to be expected, as you end up thrashing a memory area 4
times the size of the surface. :slight_smile:

You should cast the pointer to (char *). Some compilers assume that
the element size is 1 byte if you index void pointers. This cast is
just a way to explicitly specify that behavior.

earlier this day, you send a mail about a bugfixed msvc++ version,
is it online already?

No, but unless I find or get reports about other critical and/or silly
bugs, I’ll have 0.5 on-line in a few hours or so.

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Friday 27 June 2003 16.55, Florian Hufsky wrote:

ok. but how can i solve this bug?
i tried to convert to int, but glSDL crashes this way.

Well, that’s to be expected, as you end up thrashing a memory area 4
times the size of the surface. :slight_smile:

You should cast the pointer to (char *). Some compilers assume that
the element size is 1 byte if you index void pointers. This cast is
just a way to explicitly specify that behavior.

thanks!
i thought i have to convert it depending on the bpp i choosed when
initializing sdl video.

earlier this day, you send a mail about a bugfixed msvc++ version,
is it online already?

No, but unless I find or get reports about other critical and/or silly
bugs, I’ll have 0.5 on-line in a few hours or so.

great!
i’ll be one of the first persons to download it!
if you could use it, i’d send you msvc++ projekt files for compiling glSDL
and the examples (just like VisualC.zip, which comes with the sdl release).

please excuse my english, i haven’t written in english for a long time.> On Friday 27 June 2003 16.55, Florian Hufsky wrote:

[…]

if you could use it, i’d send you msvc++ projekt files for
compiling glSDL and the examples (just like VisualC.zip, which
comes with the sdl release).

I can’t use them myself, but I’d like to include them in the package
for those who can.

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Friday 27 June 2003 19.38, Florian Hufsky wrote:

ok!
i send them as soon as possible!> On Friday 27 June 2003 19.38, Florian Hufsky wrote:

[…]

if you could use it, i’d send you msvc++ projekt files for
compiling glSDL and the examples (just like VisualC.zip, which
comes with the sdl release).

I can’t use them myself, but I’d like to include them in the package
for those who can.