SDL_rect being unallocated

I have a class. This class has a method that returns an SDL_Rect. When I receive the SDL_Rect in another method (of another class), the attributes are all
different. For example, where the x should be 240, it’s 32767.

If you’re returning a literal instance it should work fine as long as your calling conventions of compilers are a match (which they should be).

Returning a pointer or reference to a variable you declare inside the inner function will not work though, so be sure you’re not doing that.

I.E. this should work:
SDL_Rect MyClass::MyMethodThatReturnsRect()
{
SDL_Rect r;
r.top = 0;
r.left = 0;
r.bottom = 0;
r.right = 0;
return r;
}

And called like:
SDL_Rect m;
m = myobject.MyMethodThatReturnsRect();

Keep in mind that behind the scenes, this performs a literal copy of the SDL_Rect struct, it is totally safe but not as fast as a reference or pointer.

It would be more common practice to pass by reference, like this:
void MyClass::MyMethodThatModifiesRect(SDL_Rect &r)
{
r.top = 0;
r.left = 0;
r.bottom = 0;
r.right = 0;
}

Called like this:
SDL_Rect m;
myobject.MyMethodThatModifiesRect(m);On 03/05/2014 05:55 PM, Plazmotech wrote:

I have a class. This class has a method that returns an SDL_Rect. When I receive the SDL_Rect in another method (of another class), the attributes are all? different. For example, where the x should
be 240, it’s 32767.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


LordHavoc
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier

And in case you wonder “why exactly 32767”. :slight_smile:
http://en.wikipedia.org/wiki/Integer_(computer_science)> Forest Hale hat am 6. M?rz 2014 um 03:00 geschrieben:

If you’re returning a literal instance it should work fine as long as your
calling conventions of compilers are a match (which they should be).

Returning a pointer or reference to a variable you declare inside the inner
function will not work though, so be sure you’re not doing that.

I.E. this should work:
SDL_Rect MyClass::MyMethodThatReturnsRect()
{
SDL_Rect r;
r.top = 0;
r.left = 0;
r.bottom = 0;
r.right = 0;
return r;
}

And called like:
SDL_Rect m;
m = myobject.MyMethodThatReturnsRect();

Keep in mind that behind the scenes, this performs a literal copy of the
SDL_Rect struct, it is totally safe but not as fast as a reference or pointer.

It would be more common practice to pass by reference, like this:
void MyClass::MyMethodThatModifiesRect(SDL_Rect &r)
{
r.top = 0;
r.left = 0;
r.bottom = 0;
r.right = 0;
}

Called like this:
SDL_Rect m;
myobject.MyMethodThatModifiesRect(m);

On 03/05/2014 05:55 PM, Plazmotech wrote:

I have a class. This class has a method that returns an SDL_Rect. When I
receive the SDL_Rect in another method (of another class), the attributes
are all? different. For example, where the x should
be 240, it’s 32767.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


LordHavoc
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged
demo." - James Klass
"A game is a series of interesting choices." - Sid Meier


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org