question using custom image with a texture

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
User avatar
eugen
OGRE Expert User
OGRE Expert User
Posts: 1422
Joined: Sat May 22, 2004 5:28 am
Location: Bucharest
x 8

question using custom image with a texture

Post by eugen »

i have this code (here are a few lines)

Code: Select all

video->img.loadDynamicImage((unsigned char*)video->videoBuffer, videoX, videoY, format);
			
			video->texture = TextureManager::getSingleton().loadImage("MovieTexture##" + StringConverter::toString(video->source), video->img, TEX_TYPE_2D);
						
			TextureUnitState* t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("MovieTexture##" + StringConverter::toString(video->source));
			
where video->videoBuffer is a pointer allocated with new by me!
as i saw in the code, the image i'm creating is setting the autoDelete to false so i have to delete this pointer at the end. But when i try to do that, i get an assertion that says that this pointer wasnt allocated this way and it cannot be deleted by this mem manager... (the memory appears in the leaks file)
how can i delete this pointer?
(i tried to delete the material, then the texture, then delete the pointer but it doesnt work - the same assert)
User avatar
DWORD
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 1365
Joined: Tue Sep 07, 2004 12:43 pm
Location: Aalborg, Denmark

Post by DWORD »

Did you use the same version of new and delete? I.e. new/delete and new[]/delete[].
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

BTW, you should use the HardwarePixelBuffer API for uploading textures that change in realtime for optimal performance. See the Azathoth release notes on the Wiki and the DynTex demo.
User avatar
eugen
OGRE Expert User
OGRE Expert User
Posts: 1422
Joined: Sat May 22, 2004 5:28 am
Location: Bucharest
x 8

Post by eugen »

i'm using ogre 0.15 and i think the Dyntex demo is comming only with ver 1.00 ... what about the support for dynamic textures in this version ?! are there in 0.15?
to dword : i'm using the same new/delete version...
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

No, never mind then :)
User avatar
pjcast
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 2543
Joined: Fri Oct 24, 2003 2:53 am
Location: San Diego, Ca
x 2

Post by pjcast »

well, from the code you posted, no errors are immediately obvious... I believe the ffmpegplugin in cvs still uses (ie. hasn't been updated to v1) the same process which you are trying to do.

You can use that as a reference. You have to show where you create the buffer, and when you delete the buffer... Does sound like a mismatch between new[] and delete.
Have a question about Input? Video? WGE? Come on over... http://www.wreckedgames.com/forum/
User avatar
eugen
OGRE Expert User
OGRE Expert User
Posts: 1422
Joined: Sat May 22, 2004 5:28 am
Location: Bucharest
x 8

Post by eugen »

u're right...i needed to use delete[]...
i dont really understand why!:(
i used a var = new unsigned char[size] and needed to use delete []var;
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 7

Post by haffax »

That's the reason, eugen. when you use new Bla[blub] you need to use delete[]. :)
team-pantheon programmer
creators of Rastullahs Lockenpracht
User avatar
DWORD
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 1365
Joined: Tue Sep 07, 2004 12:43 pm
Location: Aalborg, Denmark

Post by DWORD »

Code: Select all

char* array = new char[x];
allocates an array consisting of x chars, and to free the allocated memory you must specify that you want to delete the whole array, and not just the first element pointed to by the variable 'array'. Otherwise you'd get a memory leak, and therefore Ogre's memory manager catches this.
User avatar
eugen
OGRE Expert User
OGRE Expert User
Posts: 1422
Joined: Sat May 22, 2004 5:28 am
Location: Bucharest
x 8

Post by eugen »

really!?
i used all the time new char[x] and then use delete ... and not having any memory leaks... i think!
i know the delete[] bla; is used when u want to specify that u need to call the destructor for each deleted element in the array... (but now i dont know if this is true)
anyway, i did a quick search in the visual c++'s documentation and it says loud and clear - use delete[] when the pointer u erase is an array :)
Whitebear
Greenskin
Posts: 147
Joined: Mon Oct 25, 2004 5:22 am
Location: RF
x 1

Post by Whitebear »

The excerpt from the book 'Wrox Press C++ Tutorial'
Allocating Memory Dynamically for Arrays
Allocating memory for an array dynamically is very straightforward. If we wanted to allocate an array of type char, assuming pstr is a pointer to char, we could write the following statement:

pstr = new char[20]; // Allocate a string of twenty characters

This allocates space for a char array of 20 characters and stores its address in pstr.

To remove the array that we have just created in the free store, we must use the delete operator. The statement would look like this:

delete [] pstr; // Delete array pointed to by pstr

Note the use of square brackets to indicate that what we are deleting is an array. When removing arrays from the free store, you should always include the square brackets or the results will be unpredictable. Note also that you do not specify any dimensions here, simply [].
\_ :roll:_/
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Post by jacmoe »

A C-style string is an array - if you initialize something with brackets, you must delete it with brackets.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.