Hi guys,
I'm totally new to C++ and trying to program something using the Marmalade API (www.madewithmarmalade.com. The problem I'm facing is de-allocating the memory I've used at the end of the code doesn't seem to work... and no matter what I read/try I can't get it to work sadly :(
// Marmalade headers
#include "s3e.h"
#include "Iw2D.h"
#include "IwGx.h"
#include "vector"
int main()
{
// Initialise Marmalade graphics system and Iw2D module
Iw2DInit();
//create array
std::vector<CIw2DImage*> images;
// Create an image for the app to use
//CIw2DImage* image1 = Iw2DCreateImage("lol1.png");
//CIw2DImage* image2 = Iw2DCreateImage("lol2.png");
//CIw2DImage* image3 = Iw2DCreateImage("lol3.png");
//Add actual images to the array 'images'
images.push_back(Iw2DCreateImage("lol1.png"));
images.push_back(Iw2DCreateImage("lol2.png"));
images.push_back(Iw2DCreateImage("lol3.png"));
// Main Game Loop
while (!s3eDeviceCheckQuitRequest())
{
//Clear the Screen
Iw2DSurfaceClear(0xff000000);
//Draw an image
Iw2DDrawImage(images[IwRandMinMax(0, images.size())], CIwSVec2(10,10));
// Show the surface
Iw2DSurfaceShow();
//yield to the system
s3eDeviceYield(1);
}
//de-allocate pointers from vector array
for(int i = 0; i < images.size(); ++i)
delete images[i];
// Shut down Marmalade graphics system and the Iw2D module
Iw2DTerminate();
return 0;
}
The Iw2D and s3e calls are in ref to the marmalade system.
Problem I'm facing is I'm getting this error:
1 2 3 4 5 6 7 8
IwAssert failure (MEMORY, 2356).
Message: Bucket 0(System) is still in use (first allocation ID=185); deleting it is dangerous
Callstack:
IwUtilTerminate
IwGxTerminate
Iw2DTerminate
_IwGxInitPipeline
From what I read this is a 'still in use' memory error and I haven't de-allocated properly so I suspect this is a general c++ coding error rather than a marmalade specific error.
So my question is... how am I supposed to properly remove the points from a vector array if not how I've done above? Any help would be greatly appreciated as I am absolutely a complete c++ noob... but I would like to learn more!
actually, no... pointers to images are put into the array...and pointers take 4 bytes;)... But you don't have to worry about that...
The iwd2createimage allocated the space for you... Maybe there is a iwd2deleteimage or something...
Hmm.. this does not bode well.
delete does work when it's just a regular display image command but not with the array it seems.
Thanks for the replies guys...
Any suggestions as to what I could use otherwise?
My end result is to create something that will display a random image from a list of images.
I thought a vector array would be the best way to do this but perhaps not....
Unless the documentation specifically mentions that Iw2DDrawImage keeps pointers to the images that you pass and that you may not delete them before calling Iw2DTerminate(), this looks like a bug in that library. You probably should file a bug report.
@Chevril
That's awesome! Ok so I use CIwArray instead of vector, no problem. However I can no longer use Iw2DCreateImage with this it seems... how do I put images into the CIwArray?
This was from my experience, I was getting errors until I changed to
CIwArray<void> images;
and now IW2D works, however I still get this error:
1 2 3 4 5 6 7 8
IwAssert failure (MEMORY, 2356).
Message: Bucket 0(System) is still in use (first allocation ID=185); deleting it is dangerous
Callstack:
IwUtilTerminate
IwGxTerminate
Iw2DTerminate
_IwGxInitPipeline
This is what my code looks like now that I've changed to CIwArray:
// Marmalade headers
#include "s3e.h"
#include "Iw2D.h"
#include "IwGx.h"
#include "vector"
int main()
{
// Initialise Marmalade graphics system and Iw2D module
Iw2DInit();
//create array
CIwArray<void> images;
// Create an image for the app to use
//CIw2DImage* image1 = Iw2DCreateImage("lol1.png");
//CIw2DImage* image2 = Iw2DCreateImage("lol2.png");
//CIw2DImage* image3 = Iw2DCreateImage("lol3.png");
//Add actual images to the array 'images'
images.push_back(Iw2DCreateImage("lol1.png"));
images.push_back(Iw2DCreateImage("lol2.png"));
images.push_back(Iw2DCreateImage("lol3.png"));
// Main Game Loop
while (!s3eDeviceCheckQuitRequest())
{
//Clear the Screen
Iw2DSurfaceClear(0xff000000);
//Draw an image
Iw2DDrawImage(images[IwRandMinMax(0, images.size())], CIwSVec2(10,10));
// Show the surface
Iw2DSurfaceShow();
//yield to the system
s3eDeviceYield(1);
}
images.clear();
// Shut down Marmalade graphics system and the Iw2D module
Iw2DTerminate();
return 0;
}