Access violation using TsAlphaImageList

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #37376
    Whookie
    Participant

    Hi,

    in a new project I'm just using TsAlphaImageList and I quite often get an exception in class $C0000005 with message c0000005 ACCESS_VIOLATION as soon as an image should be drawn.

    The debugger stops in sGraphUtils.CreateContributors at the following code:

    Code:
    with Data[Count] do begin
    if B < 0 then
    Pixel := -B
    else
    if B >= MaxSize then
    Pixel := 2 * MaxSize – B – 1 <-----Exception
    else
    Pixel := B;

    Pixel := Pixel * Delta;
    Weight := Round(W * Scale2 * 65536);
    end;

    This might be due to suspicious code in sGraphUtils.CreateContributors:

    1.

    Code:

    CSize := Trunc(AWidth * 2 + 1) * SizeOf(TContributor);
    GetMem(Contrib, Size * (SizeOf(TCList) + CSize));

    This might or might not allocate enough memory because of the 'AWidth * 2 + 1' term.

    2.

    Code:

    Contrib[A].Data := Data;
    Data := PContributorList(DWord(Data) + DWord(CSize));
    =====

    This is definitly a bug and will (or will not) lead to an error depending on where the current memory-block is physically mapped.

    I haven't used AlphaControls for quite some time, so I hope you are focused on the project and the 64bit migration (don't know if the code is full of bugs like this, because I just dropped in the image list)!

    In general:

    Stay away from hard-casts as much as possible, use NativeInt/NativeUInt with pointer arithmentics (or PByte+Inc()).

    Stay away from PAnsiChar (for anything except AnsiChars).

    Use FastMM4 while testing and define AlwaysAllocateTopDown this will raise errors for most of such bugs.

    Also look through message-handling code and make sure you use THandle/LPARAM/WPARAM.

    #56315
    Support
    Keymaster

    Thank you for the message. I will check and I will try to improve it.

    If you have a test-application with error and you can share it, this would be great.

    #56319
    Whookie
    Participant
    'Support' wrote:

    Thank you for the message. I will check and I will try to improve it.

    If you have a test-application with error and you can share it, this would be great.

    It is a rather big project and I'm on a tight schedule so maybe next month.

    To fix my problem do at least the following:

    Code:

    Contrib[A].Data := Data;
    Data := PContributorList(NativeUInt(Data) + DWord(CSize));
    ==========
    #56320
    Support
    Keymaster

    I have changed it to this:

    Code:

    Contrib[A].Data := Data;
    Data := PContributorList(PAnsiChar(Data) + CSize);

    What you think about the “PAnsiChar” in this case?

    #56328
    Whookie
    Participant
    'Support' wrote:

    What you think about the “PAnsiChar” in this case?

    This will work since you are using a pointer type now.

    I think you have some backward compatibility issues to take into account (D2007 and lower?) so it's sort of a good compromise (otherwise I would use

    Code:
    Data := PContributorList(PByte(Data) + CSize);

    instead).

    BTW it would be really great to have a selectable background color in the Imagelist window (as I'm working with styles I always have lists with pure white icons and they are invisible)!

    #56340
    Support
    Keymaster
    'Whookie' wrote:
    BTW it would be really great to have a selectable background color in the Imagelist window (as I'm working with styles I always have lists with pure white icons and they are invisible)!

    I will try to do it in the v12.03

    #56917
    Whookie
    Participant
    'Support' wrote:

    I will try to do it in the v12.03

    Hi, I went to the current version (12.12) and found that you have

    * Added support of the BkColor property in the TsAlphaImageList component

    in 12.03 but it seems as it isn't what I was after.

    So I thought a show you a screenshot of what I'm struggling with:

    [attachment=8388:imagelist_win.jpg]

    The mouse hovers over image 5 (cursor not shown) so this is the only way to see what image is stored there.

    What I meant was something like this:

    [attachment=8392:imglst_bk.JPG]

    I hacked that into your dialog and attached that project too (you need to remove “.pas” though and unpack it).

    #56918
    Stephane Senecal
    Participant

    I think it was a typo. I'm quite sure he meant 12.13 since that's the number of the next version.

    Stephane Senecal
    CIS Group
    Delphi programmer since 2001

    #56928
    Support
    Keymaster

    Hello, Whookie

    I think, you need a possibility to change a color of icons background in this dialog. Right?

    I can add such ColorSelector there.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.