BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: AV loading graphic in component

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development)
View previous topic :: View next topic  
Author Message
Remy Lebeau (TeamB)
Guest





PostPosted: Sat Feb 07, 2004 1:38 am    Post subject: Re: AV loading graphic in component Reply with quote




"Asger Jørgensen" <Asger.Pnotthis (AT) AJ-World (DOT) dk> wrote


Quote:
BmpLight->LoadFromResourceID((int)HInstance,ID_BMP_LIGHT);
----->>>>>>>ERROR AV read of address

You should not be using the global HInstance variable when working with
component packages. You must use then FindClassHInstance() function
instead:


BmpLight->LoadFromResourceID(FindClassHInstance(__classid(TWhateverYourClass
Is)), ID_BMP_LIGHT);

The global HInstance refers to the application's module, whereas you stored
the bitmaps in your own package's module instead.


Gambit



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sat Feb 07, 2004 2:55 am    Post subject: Re: AV loading graphic in component Reply with quote




"Asger Jørgensen" <Asger.Pnotthis (AT) AJ-World (DOT) dk> wrote


Quote:
BmpLight = new Graphics::TBitmap;
BmpLight->LoadFromResourceID(
FindClassHInstance(__classid(TAJInput7053)),ID_BMP_LIGHT);

Still gets the AV unless i add the res file to the App project

There is nothing in that code you have shown that can through an AV to begin
with. An EResNotFound exception maybe, but not an AV.


Gambit



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sun Feb 08, 2004 12:27 am    Post subject: Re: AV loading graphic in component Reply with quote




"Asger Jørgensen" <Asger.Pnotthis (AT) AJ-World (DOT) dk> wrote


Quote:
i have done a trace into on the load resource call and this is
where it went:

I cannot comment on that. Nothing you have described is making any sense.
Please show your actual code, I'll bet you the AV is actually occuring
somewhere completely different then you expect it to be.


Gambit



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon Feb 09, 2004 3:22 am    Post subject: Re: AV loading graphic in component Reply with quote

"Asger Jørgensen" <Asger.Pnotthis (AT) AJ-World (DOT) dk> wrote


Quote:
static Graphics::TBitmap* BmpLight;
static Graphics::TBitmap* BmpDark;

Why are you using static instances instead of local members? If you change
your code to not use static instances, I'll bet you the AV goes away.


Gambit



Back to top
OBones
Guest





PostPosted: Mon Feb 09, 2004 7:33 am    Post subject: Re: AV loading graphic in component Reply with quote

Asger Jørgensen wrote:
Quote:

No, that don't help either the av is still there, that is
if the image.res isn't added to the app project. And why
shouldn't it bee, it is just the pointer there is static,
not the load from resources stuff, and isn't it so that
static members are created before any instances ?
So they should be valid before i use them, which i
also think they are, after all the av doesn't happen in
the first line where i use the pointer with new, it happen
when i try to load the bitmap from the resource.

I haven't read the whole thread so I may say something that has already

been said.
The fact that the AV occurs when you try to load the bitmap from the
resources leads me to believe that the resource is not linked into the
executable and that the loading code cannot find it, thus indirectly
leading to the AV.
There might be a solution in this area...


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon Feb 09, 2004 7:37 pm    Post subject: Re: AV loading graphic in component Reply with quote

"OBones" <obones_fff_ (AT) meloo_fdf_ (DOT) com> wrote


Quote:
The fact that the AV occurs when you try to load the bitmap from
the resources leads me to believe that the resource is not linked
into the executable and that the loading code cannot find it, thus
indirectly leading to the AV.

If that were the case, he would be getting an EResNotFound exception, not an
Access Violation. The fact that he is getting an Access Violation means
that either 1) his TBitmap pointers are messed up to begin with, thus he
wold be accessing invalid pointers, or 2) the image data is found in the
resources correctly but the resource data itself is corrupted, thus TBitmap
would crash on trying to parse invalid bitmap data.


Gambit



Back to top
OBones
Guest





PostPosted: Mon Feb 09, 2004 11:12 pm    Post subject: Re: AV loading graphic in component Reply with quote

Remy Lebeau (TeamB) wrote:
Quote:
If that were the case, he would be getting an EResNotFound exception, not an
Access Violation. The fact that he is getting an Access Violation means
that either 1) his TBitmap pointers are messed up to begin with, thus he
wold be accessing invalid pointers, or 2) the image data is found in the
resources correctly but the resource data itself is corrupted, thus TBitmap
would crash on trying to parse invalid bitmap data.

I'm no expert here, but I quite agree with your analysis and would go
for the second option.
As Asger said, the component is working in design mode, but not in run
mode. This makes me think that he is not using runtime packages for his
project.
That means that in design time the bpi file is used, thus having the
correct resources. But in run time, only the complete lib file is used,
thus not having any of the component's resources linked. But by an
incredible misfortune, it seems he has a resource in his exe that has
the same ID, but is not a bitmap, thus leading to the AV.
That's where I would have a look anyway, at the way resources are
loaded: by numerical or string ID. If it's string, then he should get
the EResNotFound, but if it's numerical, there is a chance that a
resouce by that number already exists...


Back to top
OBones
Guest





PostPosted: Tue Feb 10, 2004 12:17 am    Post subject: Re: AV loading graphic in component Reply with quote

Asger Jørgensen wrote:

Quote:
There is a checkmark in Designtime and Runtime,
isn't that where it should be ?
Uh... In the package properties ?

Then this is already a problem.

Packages should be either runtime or design time, but not both, and it
has been like that since version 5 at least (maybe even 4).

For instance:

MyPackageR.bpk (a runtime only package) contains the source files for
your component (cpp or pas, inc, res), but nothing related to design
time (no editors, no registration...)
MyPackageD.bpk (a designtime only package) contains the registration
unit and maybe the editors unit. It requires MyPackageR.bpi

Then you only install MyPackageD.bpl in the IDE and you can use your
component.

Try having something like that and tell us if the problem is still there.


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Feb 10, 2004 1:08 am    Post subject: Re: AV loading graphic in component Reply with quote


"OBones" <obones_fff_ (AT) meloo_fdf_ (DOT) com> wrote


Quote:
But by an incredible misfortune, it seems he has a resource in his
exe that has the same ID, but is not a bitmap, thus leading to the AV.
snip
if it's numerical, there is a chance that a resouce by that number already
exists...


Since he did not actually show what his numeric values are, or how he is
creating the resource in the first place, then I agree that it is a distinct
possibility.


Gambit



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.