enable_triple_buffer - segmentation error
OICW

I'm trying to have three different methods of updating screen - double buffer, page flipping and triple buffer. Basicly I went to allegro examples to get to know how to program them. After getting the ideas I wrote a code to initialize gfx_mode and to redraw the screen using theese three methods. There are two possible ways of initializing the mode. At first it will try to initialize triple buffer, then if gfx_card don't support it it will try to init page flip and at last double buffer. The second way is manualy typing a request as program parameter - this will override checking of gfx_capabilities & GFX_CAN_TRIPLE_BUFFER. When I manualy specify the mode everything goes perfectly. All three modes are working without problems (well under GFX_SAFE only double buffer works because page flip and triple buffer says that they don't have enough memory). But the problem begins when I let the program to set it automaticaly. In the beggining it uses this code to recognise if gfx card is capable of using triple buffer:

1if(update_mode < 0){ // pokud neni pouzit override prikazem
2 if(logging)
3 log << "> -Checking triple buffer support" << endl;
4 /* zjistime jestli je mozno pouzit tripple buffer */
5 if(!(gfx_capabilities & GFX_CAN_TRIPLE_BUFFER)){
6 if(logging)
7 log << "> -Trying to enable triple buffer" << endl;
8 enable_triple_buffer(); // pokud ne zkusime to manualne
9 if(!(gfx_capabilities & GFX_CAN_TRIPLE_BUFFER)){
10 if(logging)
11 log << "> -Triple buffer unsupported" << endl;
12 update_mode = PFLIP; // a pokud vse selze pouzijeme page flipping
13 }
14 }else{
15 if(logging)
16 log << "> -Triple buffer is supported" << endl;
17 update_mode = TBUF;
18 }
19}

It's very similar to ex3buf code from allegro examples, with one exception: this one crashes at calling enable_triple_buffer with "Your program has generated segmentation error: reading or writing to forbidden memory". And I'm curious why this should be when the ex3buf works perfectly and says that it's using real triple buffering.

Todd Cope

It might crash if you haven't done set_gfx_mode(...) yet.

OICW

Oh holy crap, that would be it. I didn't expected that I must set gfx mode prior to call enable_triple_buffer. Heh that would mean I have to rewrite the code a bit. Anyway thank you. Can anybody tell me why under GFX_SAFE it is unable to set three video pages? I'm just curious.

Kitty Cat
Quote:

Can anybody tell me why under GFX_SAFE it is unable to set three video pages?

Because that's the "safe", least featured/accelerated driver. In Windows, it's a windowed GDI mode, which is unable to use video bitmaps (and thus no page flipping or triple buffering).

What would probably work, would be:

1set_color_depth(bpp);
2set_gfx_mode(driver, w, h, vw, vh);
3 
4switch(detect_update_method())
5{
6 case TBUF:
7 blah;
8 break;
9 case PFLIP:
10 blah;
11 break;
12 case DBUF:
13 blah;
14 break;
15 default:
16 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
17 allegro_message("No suitable update method found!");
18 exit(1);
19}

OICW

Thank you for enlighten me. I changed it to something simillar yesterday and it works.

Thread #567954. Printed from Allegro.cc