Forum > Games

Allegro.pas

<< < (12/12)

Ñuño_Martínez:
Sorry for the time without answering, but I had a bad month.

That wasn't the problem.  The problem is that my graphics card stores the textures upside-down, so pitch is negative, so results in a negative index witch is out of range (all indexes must be positive).  Fix is to use a pointer instead of array, since the Lock.data points to the top-left corner of the bitmap (doesn't matter if it stored upside-up or -down).

I've commit the fix, including credits to your work (if you want to change it, let me know).

x2nie:
Hi Nuno,
Your modification doesn't work.  >:D  (I have checkout the svn trunk repository).
at least didn't properly work on my machine.
** But, thanks for including my name in credit.  8-) Thats great, perhaps someday my son read it. :-X
--------------------------


However, after tried several scenario, the solution is quite simple....

The error was runtime "SIGSENV" without Lazarus prefer into which line of code the problem is being executed.
Well, years ago I have had bad day experience when porting C code into pascal, especially in copying array of bytes with pointer addressing.
-
I wonder how the code is working well in your side:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---move (        ScreenData,        BitmapData[i * FormatSize * iw],        FormatSize * iw      )

but the only working code in my Lazarus Win10 32bit is by make the first array explicitly as the pointer address. like this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---move (        ScreenData[0],        BitmapData[i * FormatSize * iw],        FormatSize * iw      )


Now, the complete code (partially) is :

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{ Test 4. }    Print ('Screen -> Locked -> Screen (%.1f fps)', [GetFPS(3)]);    GetXY (x, y);    al_draw_bitmap (Pattern, x, y, 0);      StartTimer (3);      ix := Round (x); iy := Round (y);    Lock := al_lock_bitmap_region (      Screen,      ix, iy, iw, ih,      ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY    );    FormatLock := ALLEGRO_PIXEL_FORMAT (Lock.format);    FormatSize := Lock.pixel_size;    BitmapData := AllocMem (FormatSize * iw * ih);    FOR i := 0 TO ih - 1 DO    BEGIN    { Lock.pitch may be negative (i.e. graphics card stores textures upside down)      so indexes can't be used here as only positive values can be used.      So use pointers.    }      ScreenData := Lock.Data + (i * Lock.pitch);      move (        ScreenData[0],        BitmapData[i * FormatSize * iw],        FormatSize * iw      )    END;    al_unlock_bitmap (Screen);      Lock := al_lock_bitmap_region (      Screen,      ix + 8 + iw, iy, iw, ih,      FormatLock, ALLEGRO_LOCK_WRITEONLY    );    FOR i := 0 TO ih - 1 DO    BEGIN      ScreenData := Lock.Data + (i * Lock.pitch);      move (        BitmapData[i * FormatSize * iw],        ScreenData[0],        FormatSize * iw      )    END;    al_unlock_bitmap (Screen);    FreeMem (BitmapData);      StopTimer (3);    

It works fine with all valgrind,I/O, Range Check,Stack & Overflow assertions set on.
---------


Anyway, now I knew the reason of why the copying bitmap data is done in a loop (like the ex_blit.c does too), since we can also to copy the whole data at glance. That it because in some graphic card the data is upside down.
Thanks you

Ñuño_Martínez:
Your new fix works for me as well. :) Now I have to test it on Delphi (first I have to upgrade my license %))

I'm curious what's your system.  Mine is Xubuntu/Linux 20.04.1, fpc 3.2.0.

Navigation

[0] Message Index

[*] Previous page

Go to full version