I have a problem with my X setup (that I'm still tracking down) such
that SDL::SetVideoMode fails, returning 0 (NULL). The logic in
SDL/App.pm looks like this:
my $self = \SDL::SetVideoMode($w,$h,$d,$f)
or die SDL::GetError();
The second part of this or expression never gets evaluated, because even
though SDL::SetVideoMode is failing and returning 0, the \ creates a
reference to the zero value, which is obviously stored somewhere in
memory, and thus not logically false.
I changed this to:
my $selfo = SDL::SetVideoMode($w,$h,$d,$f)
or die SDL::GetError();
my $self = \$selfo;
And it dies as expected with:
No available video device at
/usr/lib/perl5/site_perl/5.8.3/i586-linux-thread-multi/SDL/App.pm line
80
I think there might be a similar problem with App::resize, in which the
return value isn't checked at all.
It took me a while to track this down, as my code was segfaulting.
valgrind reported that it was in SurfaceW in SDL_perl.so, trying to read
address 0x8. From this, since the width value of the surface struct
starts at byte 8 (from looking at SDL source), and so (surface->w -
surface) would equal 8, that meant surface was NULL. In this particular
case, the surface I was trying to get the width of was my SDL::App
object.
I notice that the way the code is structured in Surface::new and
Color::new this problem is avoided. Rect::new doesn't check the return
value of SDL::NewRect -- are we not expecting it to fail?
Andy.