Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

danne89

SIGSEGV in Allegro's blit()

This topic is 5364 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello follows! I get a Segmentation fault when I'm trying to blit w/Allegro. I have a loop like this:
 void Back::draw()
{
                for (int x = 0; x <= 4; x++)
                {
                        for (int y = 0; y <= 9; y++)
                        {
                                if (map[x][y] == 0)
                                {
                                        win->draw(backTiles, 0, 0, x * 60, y * 60, 60, 60);
                                        continue;
                                }

                                if (map[x][y] == 1)
                                {
                                        win->draw(backTiles, 60, 0, x * 60, y * 60, 60, 60);
                                        continue;
                                }


                                if (map[x][y] == 2)
                                {
                                        win->draw(backTiles, 120, 0, x * 60, y * 60, 60, 60);
                                        continue;
                                }


                                if (map[x][y] == 3)
                                {

                                        win->draw(backTiles, 180, 0, x * 60, y * 60, 60, 60);
                                        continue;
                                }

                                break;
                        }

                }

        return;
}
  
The win::draw() looks like this:
void Win::draw(BITMAP *source, int source_x, int source_y,  int dest_x, int dest_y, int width, int height)
{
        blit(source, buffScreen, source_x, source_y, dest_x, dest_y, width, height);
}
  
That code works good when I use from a other place, so I think the error is in the loop.
(gdb) r
Starting program: /home/danne/projects/tiles/prog 
[New Thread 16384 (LWP 1842)]
[New Thread 32769 (LWP 1843)]
[New Thread 16386 (LWP 1844)]
[New Thread 32771 (LWP 1845)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 16384 (LWP 1842)]
0x0804d4f1 in Win::draw(BITMAP*, int, int, int, int, int, int) (
    this=0x1010101, source=0x8073500, source_x=60, source_y=0, dest_x=0, 
    dest_y=0, width=60, height=60) at win.cpp:85
85              blit(source, buffScreen, source_x, source_y, dest_x, dest_y, width, height);
Current language:  auto; currently c++
(gdb) print *source
$1 = {w = 673054760, h = 2629120, clip = 503326750, cl = 673054760, 
  cr = 2629120, ct = 503326750, cb = 673054760, vtable = 0x281e00, 
  write_bank = 0x1e00281e, read_bank = 0x281e0028, dat = 0x281e00, 
  id = 503326750, extra = 0x281e0028, x_ofs = 2629120, y_ofs = 503326750, 
  seg = 673054760, line = 0x8073740}
  
I hope someone can help me with this problem. I'm a beginner in programming with Allegro. I run Linux if that's imported. [edited by - danne89 on March 7, 2004 2:32:41 PM]

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by danne89

...
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 16384 (LWP 1842)]
0x0804d4f1 in Win::draw(BITMAP*, int, int, int, int, int, int) (
this=0x1010101, source=0x8073500, source_x=60, source_y=0, dest_x=0,
dest_y=0, width=60, height=60) at win.cpp:85


That doesn''t look like a valid this pointer to me. Make sure that win was correctly allocated.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
Is the variable backTiles an array of BITMAP''s instead of a single one? I see you''re passing it as ''backTiles'' when maybe you wanted to do ''backTiles[..][..]''. Not sure, just thought I''d throw that out there.

Share this post


Link to post
Share on other sites
Hello again!
I modify the code a bit and the this pointer looks better, but I still get a SIGSEGV. The code looks now like this.

int Back::init(Game* g)
{
game = g;

backTiles = 0;
backTiles = load_bmp("backtiles.bmp", 0);
if (backTiles == 0)
{
allegro_message("Kunde inte hitta backtiles.bmp\n");
return 1;
}

for (int x = 0; x <= 9; x++)
{
for (int y = 0; y <= 4; y++)
{
map[x][y] = rand() % 3;
}
}

}

void Back::draw()
{
for (int x = 0; x <= 4; x++)
{
for (int y = 0; y <= 9; y++)
{
if (map[x][y] == 0)
{
game->main->win.draw(backTiles, 0, 0, x * 60, y * 60, 60, 60);
continue;
}

if (map[x][y] == 1)
{
game->main->win.draw(backTiles, 60, 0, x * 60, y * 60, 60, 60);
continue;
}


if (map[x][y] == 2)
{
game->main->win.draw(backTiles, 120, 0, x * 60, y * 60, 60, 60);
continue;
}


if (map[x][y] == 3)
{

game->main->win.draw(backTiles, 180, 0, x * 60, y * 60, 60, 60);
continue;
}

break;
}

}

return;
}


(gdb) b Back::draw()
Breakpoint 1 at 0x804dab2: file back.cpp, line 31.
(gdb) r
Starting program: /home/danne/projects/tiles/prog
[New Thread 16384 (LWP 2217)]
[New Thread 32769 (LWP 2218)]
[New Thread 16386 (LWP 2219)]
[New Thread 32771 (LWP 2220)]
[Switching to Thread 16384 (LWP 2217)]

Breakpoint 1, Back::draw() (this=0xbffff93c) at back.cpp:31
31 for (int x = 0; x <= 4; x++)
Current language: auto; currently c++
(gdb) s
33 for (int y = 0; y <= 9; y++)
(gdb) s
35 if (map[x][y] == 0)
(gdb) s
41 if (map[x][y] == 1)
(gdb) s
43 game->main->win.draw(backTiles, 60, 0, x * 60, y * 60, 60, 60);
(gdb) s
Win::draw(BITMAP*, int, int, int, int, int, int) ([i]this=0xbffff8d8[/i],
source=0x1010101, source_x=60, source_y=0, dest_x=0, dest_y=0, width=60,
height=60) at win.cpp:85
85 blit(source, buffScreen, source_x, source_y, dest_x, dest_y, width, height);
(gdb) s

Program received signal SIGSEGV, Segmentation fault.
0x4003dcb2 in blit () from /usr/local/lib/liballeg.so.4.0


quote:
Is the variable backTiles an array of BITMAP's instead of a single one? I see you're passing it as 'backTiles' when maybe you wanted to do 'backTiles[..][..]'. Not sure, just thought I'd throw that out there.

It's bool array, thanks anyway.



[edited by - danne89 on March 7, 2004 3:10:38 PM]

[edited by - danne89 on March 7, 2004 3:11:55 PM]

Share this post


Link to post
Share on other sites
And now source looks like a bad pointer. Try initializing both of them.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
I think this is weird. It''s look like I have a working pointer in Back::init(Game*). I don''t understand this. I hope you can tell me what I do wrong.

(gdb) b Back::init(Game*)
Breakpoint 1 at 0x804d8e3: file back.cpp, line 8.
(gdb) r
Starting program: /home/danne/projects/tiles/prog
[New Thread 16384 (LWP 368)]
[New Thread 32769 (LWP 369)]
[New Thread 16386 (LWP 370)]
[New Thread 32771 (LWP 371)]
[Switching to Thread 16384 (LWP 368)]

Breakpoint 1, Back::init(Game*) (this=0xbffff93c, g=0xbffff938) at back.cpp:8
8 game = g;
Current language: auto; currently c++
(gdb) n
10 backTiles = load_bmp("backtiles.bmp", 0);
(gdb) n
11 if (backTiles == 0)
(gdb) print backTiles
$1 = (BITMAP *) 0x8073548
(gdb) b Back::draw()
Breakpoint 2 at 0x804d988: file back.cpp, line 30.
(gdb) c
Continuing.

Breakpoint 2, Back::draw() (this=0xbffff93c) at back.cpp:30
30 for (int x = 0; x <= 4; x++)
(gdb) print *this
$2 = {game = 0xbffff938, map = {{true, true, false, true}, {true, true, false,
false}, {true, true, true, true}, {true, false, false, true}, {true,
true, false, false}, {true, true, true, true}, {true, false, false,
false}, {false, true, true, true}, {false, false, false, true}},
backTiles = 0x1010101}
(gdb) q

Share this post


Link to post
Share on other sites
Huh, how odd.

Is it possible that you''re calling it on a different object? Put a breakpoint in your Back constructors and make sure only one of them fires, and only once.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
quote:
Original post by Sneftel
Huh, how odd.

Is it possible that you''re calling it on a different object? Put a breakpoint in your Back constructors and make sure only one of them fires, and only once.


"Sneftel is correct, if rather vulgar." --Flarelocke

Back''s constructor only called once, thanks for your time.

Share this post


Link to post
Share on other sites
Well, that is quite screwy. The only thing I can suggest is adding breakpoints and watchpoints all over the place, to pinpoint the place where backTiles changes to uninitialized data.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
What are the dimensions of map? If it''s 4x9, then the loops

for (int x = 0; x <= 4; x++)
for (int y = 0; y <= 9; y++)

are reading and writing outside of it. Depending on how things are ordered in your class, one of those things getting overwritten could be the backTiles pointer.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!