View Full Version : Access Violation in Surreal UI (EInvalidPointer --> EAccessViolation) (resolved)
Sirber
4th January 2004, 05:01
Hi
I've got a bug that I can't correct myself. In UResizeCrop.pas, the function VCrop causes an access violation once it returns to UMain.pas. I did "step by step" debugging whitout success :(. Could some Delphi guru help me please? :)
source (http://sirber.no-ip.com/Surreal UI.rar)
Thanks a lot!!! :D
[edit]
Delphi 7 with no strange compoment :)
Latexxx
4th January 2004, 11:15
I compiled it using Delphi 6 and I found another access violation. When I add a .d2v file as source, I get also an access violation.
It seems that you haven't paid attention to the mod-16 issues when resizing/cropping. More info: http://forum.doom9.org/showthread.php?s=&threadid=33355
BTW. English word info/information doesn't have a plural form. (Your program suggests something else.)
Sirber
4th January 2004, 15:11
D2V hasn't been tested yet. I'm working on AVI for crop. Resize don't consider crop also :)
Sirber
7th January 2004, 03:18
for k := 0 to height - 1 do row[k] := 0;
for k := 0 to width - 1 do col[k] := 0;
those lines in UResizeCrop.pas gives me "bad pointer operation" on the first loop. If I comment them (while the rest is commented) everything goes fine.
Non-workong:
function VCrop(frame0, frame1, frame2, frame3: TBitMap) :cropinfo;
var
cropi :array of cropinfo;
cropr :cropinfo;
nbf, height, width, i, j, k: integer;
col, row: array of integer;
inf_row: pRGBTripleArray;
frame: TBitMap;
begin
{ Auto-Crop (AVI/DShow) }
width := frame0.Width;
height := frame0.Height;
SetLength (cropi, 3);
SetLength (row, height - 1);
SetLength (col, width - 1);
// For each frame
//frame := TBitMap.Create;
for i := 0 to 3 do
begin
{
if (i = 0) then frame.Assign(frame0);
if (i = 1) then frame.Assign(frame1);
if (i = 2) then frame.Assign(frame2);
if (i = 3) then frame.Assign(frame3);
// Calculating luma
}
showMessage(IntToStr(i));
for k := 0 to height - 1 do row[k] := 0;
for k := 0 to width - 1 do col[k] := 0;
{
for j := 0 to height - 1 do
begin
inf_row := frame.Scanline[j];
for k := 0 to width - 1 do
begin
row[j] := row[j] + inf_row[k].rgbtBlue + inf_row[k].rgbtGreen + inf_row[k].rgbtRed;
col[k] := col[k] + inf_row[k].rgbtBlue + inf_row[k].rgbtGreen + inf_row[k].rgbtRed;
end
end;
}
// Calculating crop
// TOP
{
cropi[i].top := 0;
for j := 0 to height - 1 do
begin
if ((row[j] div width) < 60) then // Black bar
inc(cropi[i].top)
else
break;
end;
// BOTTOM
cropi[i].bottom := 0;
for j := height - 1 downto 0 do
begin
if ((row[j] div width) < 60) then // Black bar
inc(cropi[i].bottom)
else
break;
end;
// LEFT
cropi[i].left := 0;
for j := 0 to width - 1 do
begin
if ((col[j] div height) < 60) then // Black bar
inc(cropi[i].left)
else
break;
end;
// RIGHT
cropi[i].right := 0;
for j := width - 1 downto 0 do
begin
if ((col[j] div height) < 60) then // Black bar
inc(cropi[i].right)
else
break;
end;
frame.FreeImage; }
end;
//VCrop := cropi[0];
{
// Find correct (smallest) crop values
// *** TOP ***
// Frame 1 vs Frame 2
if (cropi[0].top < cropi[1].top) then cropr.top := cropi[0].top else cropr.top := cropi[1].top;
// Frame 3 vs (1vs2)
if (cropi[2].top < cropr.top) then cropr.top := cropi[2].top;
// Frame 4 vs (3vs(1vs2))
if (cropi[3].top < cropr.top) then cropr.top := cropi[3].top;
// *** BOTTOM ***
// Frame 1 vs Frame 2
if (cropi[0].bottom < cropi[1].bottom) then cropr.bottom := cropi[0].bottom else cropr.bottom := cropi[1].bottom;
// Frame 3 vs (1vs2)
if (cropi[2].bottom < cropr.bottom) then cropr.bottom := cropi[2].bottom;
// Frame 4 vs (3vs(1vs2))
if (cropi[3].bottom < cropr.bottom) then cropr.bottom := cropi[3].bottom;
// *** LEFT ***
// Frame 1 vs Frame 2
if (cropi[0].left < cropi[1].left) then cropr.left := cropi[0].left else cropr.left := cropi[1].left;
// Frame 3 vs (1vs2)
if (cropi[2].left < cropr.left) then cropr.left := cropi[2].left;
// Frame 4 vs (3vs(1vs2))
if (cropi[3].left < cropr.left) then cropr.left := cropi[3].left;
// *** RIGHT ***
// Frame 1 vs Frame 2
if (cropi[0].right < cropi[1].right) then cropr.right := cropi[0].right else cropr.right := cropi[1].right;
// Frame 3 vs (1vs2)
if (cropi[2].right < cropr.right) then cropr.right := cropi[2].right;
// Frame 4 vs (3vs(1vs2))
if (cropi[3].right < cropr.right) then cropr.right := cropi[3].right;
// Set Crop values
VCrop := cropr; }
end;Working:function VCrop(frame0, frame1, frame2, frame3: TBitMap) :cropinfo;
var
cropi :array of cropinfo;
cropr :cropinfo;
nbf, height, width, i, j, k: integer;
col, row: array of integer;
inf_row: pRGBTripleArray;
frame: TBitMap;
begin
{ Auto-Crop (AVI/DShow) }
width := frame0.Width;
height := frame0.Height;
SetLength (cropi, 3);
SetLength (row, height - 1);
SetLength (col, width - 1);
// For each frame
//frame := TBitMap.Create;
for i := 0 to 3 do
begin
{
if (i = 0) then frame.Assign(frame0);
if (i = 1) then frame.Assign(frame1);
if (i = 2) then frame.Assign(frame2);
if (i = 3) then frame.Assign(frame3);
// Calculating luma
}
showMessage(IntToStr(i));
{for k := 0 to height - 1 do row[k] := 0;
for k := 0 to width - 1 do col[k] := 0;}
{
for j := 0 to height - 1 do
begin
inf_row := frame.Scanline[j];
for k := 0 to width - 1 do
begin
row[j] := row[j] + inf_row[k].rgbtBlue + inf_row[k].rgbtGreen + inf_row[k].rgbtRed;
col[k] := col[k] + inf_row[k].rgbtBlue + inf_row[k].rgbtGreen + inf_row[k].rgbtRed;
end
end;
}
// Calculating crop
// TOP
{
cropi[i].top := 0;
for j := 0 to height - 1 do
begin
if ((row[j] div width) < 60) then // Black bar
inc(cropi[i].top)
else
break;
end;
// BOTTOM
cropi[i].bottom := 0;
for j := height - 1 downto 0 do
begin
if ((row[j] div width) < 60) then // Black bar
inc(cropi[i].bottom)
else
break;
end;
// LEFT
cropi[i].left := 0;
for j := 0 to width - 1 do
begin
if ((col[j] div height) < 60) then // Black bar
inc(cropi[i].left)
else
break;
end;
// RIGHT
cropi[i].right := 0;
for j := width - 1 downto 0 do
begin
if ((col[j] div height) < 60) then // Black bar
inc(cropi[i].right)
else
break;
end;
frame.FreeImage; }
end;
//VCrop := cropi[0];
{
// Find correct (smallest) crop values
// *** TOP ***
// Frame 1 vs Frame 2
if (cropi[0].top < cropi[1].top) then cropr.top := cropi[0].top else cropr.top := cropi[1].top;
// Frame 3 vs (1vs2)
if (cropi[2].top < cropr.top) then cropr.top := cropi[2].top;
// Frame 4 vs (3vs(1vs2))
if (cropi[3].top < cropr.top) then cropr.top := cropi[3].top;
// *** BOTTOM ***
// Frame 1 vs Frame 2
if (cropi[0].bottom < cropi[1].bottom) then cropr.bottom := cropi[0].bottom else cropr.bottom := cropi[1].bottom;
// Frame 3 vs (1vs2)
if (cropi[2].bottom < cropr.bottom) then cropr.bottom := cropi[2].bottom;
// Frame 4 vs (3vs(1vs2))
if (cropi[3].bottom < cropr.bottom) then cropr.bottom := cropi[3].bottom;
// *** LEFT ***
// Frame 1 vs Frame 2
if (cropi[0].left < cropi[1].left) then cropr.left := cropi[0].left else cropr.left := cropi[1].left;
// Frame 3 vs (1vs2)
if (cropi[2].left < cropr.left) then cropr.left := cropi[2].left;
// Frame 4 vs (3vs(1vs2))
if (cropi[3].left < cropr.left) then cropr.left := cropi[3].left;
// *** RIGHT ***
// Frame 1 vs Frame 2
if (cropi[0].right < cropi[1].right) then cropr.right := cropi[0].right else cropr.right := cropi[1].right;
// Frame 3 vs (1vs2)
if (cropi[2].right < cropr.right) then cropr.right := cropi[2].right;
// Frame 4 vs (3vs(1vs2))
if (cropi[3].right < cropr.right) then cropr.right := cropi[3].right;
// Set Crop values
VCrop := cropr; }
end;Invalid pointer... but those aren't pointers!!! :scared:
[edit]
This code is licenced!!!!!! ;) :D lol
DaveEL
7th January 2004, 15:42
Originally posted by Sirber
SetLength (row, height - 1);
SetLength (col, width - 1);
Should be i believe.
SetLength (row, height);
SetLength (col, width);
Invalid pointer... but those aren't pointers!!! :scared:
Arrays and pointers are the same thing.
DaveEL
Nic
7th January 2004, 16:14
My colleague at work, wrote this to me when I asked him about it:
Ok, i dont have delphi installed anymore, havent for years, but I think what this guy is doing wrong is...
he is setting the array size of 'row' and 'col' to be "height - 1" and "width - 1".
looking at only the height for example, if it was 25, he is setting the dynamic array to have a lenght of 24,
dynamic arrays are always 0 based in Delphi, so his array runs for 0..23 (24 elemants as we asked for)
then he has the
for k := 0 to height - 1 do row[k] := 0;
line, but here he is saying set elements 0..24 of the row array to be zero. oops, row only has 0..23 elements.
there's your bug.
to fix if, all he has to be is change the
SetLength (row, height - 1);
SetLength (col, width - 1);
lines, to
SetLength (row, height);
SetLength (col, width);
well, it all sounds plausable to me anyway.
T
Sirber
7th January 2004, 17:12
Thanks guys!!!!! :D
I'm gonna try as soon as I get home!!!
:D :D :D
Sirber
8th January 2004, 00:23
Partially worked! :(
SetLength (cropi, 3);was producing also an EInvalidPointer. I load 4 images, so to fully resolve the thing, I had to set:SetLength (cropi, 4);Thanks for helpimg me guys!!! :D
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.