views:

2629

answers:

4

I have a .mbm file that I copy to my device using this line in the .pkg file

"$(EPOCROOT)epoc32\data\z\resource\apps\MyApp.mbm" -"!:\resource\apps\MyApp.mbm"

Then in the draw function of my container I do this..

_LIT(KMBMFile , "\\resource\\apps\\MyApp.mbm" );
CFbsBitmap* iBitmap;

iBitmap->Load(KMBMFile, 0);
gc.BitBlt(Rect().iTl, iBitmap);

However the line iBitmap->Load(KMBMFile, 0); raises a KERN-EXEC:0 PANIC

"This panic is raised when the Kernel cannot find an object in the object index for the current process or current thread using the specified object index number (the raw handle number)."

Can anyone spot where I am going wrong?

Thanks!

+1  A: 

I have solved this problem so will post answer here for future lookers..

Create an MBM file in your MMP file using a snippet like this

START BITMAP    MyApp.mbm
HEADER
TARGETPATH   \resource\apps
SOURCEPATH   ..\gfx
SOURCE          c24 background.bmp
END

ensure your .bmp images are saved in 32 bit from photoshop or similar

Then sure your MBM file is copied to your device in your PKG file

"$(EPOCROOT)epoc32\data\z\resource\apps\MyApp.mbm" -"!:\resource\apps\MyApp.mbm"

Then in the draw function of your container use code such as this..

_LIT(KMBMFile , "C:\\RESOURCE\\APPS\\MyApp.mbm" );
CFbsBitmap* iBitmap = new (ELeave) CFbsBitmap;
TInt retval = iBitmap->Load(KMBMFile, 0);
gc.BitBlt(Rect().iTl, iBitmap);

This will draw your bitmap at the top left point of the screen (useful for background image)

adam
+2  A: 

You were dereferencing an uninitialized pointer, you could also use this:

// remember to include the EIK environemnt include file
#include <eikenv.h>

_LIT(KMBMFile , "\\resource\\apps\\MyApp.mbm" );
CFbsBitmap* iBitmap;

iBitmap = iEikonEnv->CreateBitmapL( KMBMFile, 0 );
gc.BitBlt( Rect().iTl, iBitmap );
Manuel
+1  A: 

CCoeControl::Draw() code should not fail, and should certainly not leave (it has no trailing ..L). In the code snippet above there are two potentially error-generating calls - iBitmap constructor and iBitmap->Load(). The bitmap should be pre-allocated, not allocated in Draw() - if there is a leave bad things will happen.

Also, by convention only class member variables start with 'i', which iBitmap above is not.

See Symbian Coding Standards for more details

KevinD
A: 

You should definitely not create iBitmap in the ::Draw function as it could leave. Best to do that in the ConstructL of the CoeControl. Theoretically the ::Load call could be handled in ::Draw as it might fail for a number of reasons, not all of which may be fatal. You could just as easily do this when creating the Control though, so maybe it's best to think about it a little. I would say that if the control is basically just there to contain the bitmap then you should do it in the ConstructL. If there are a number of things that the control does, then you might want to handle it in ::Draw.