Working with digits

Posted By: Aku_Aku

Working with digits - 03/22/19 10:50

On a PANEL i can create or modify digits with the pan_setdigits(...) function.
How can i delete such a digits?
If i delete (remove) a PANEL, will all its digits be deleted?
Posted By: Ayumi

Re: Working with digits - 03/22/19 12:32

You can not delete the digits, just delete the Panel and create new one.
All Panel-Elements are automatically removed.
Posted By: Aku_Aku

Re: Working with digits - 03/22/19 18:03

Thanks for the answer.
Does it mean, if a Panel is deleted, all the elements related with that will be removed?
digits, buttons and so on...?
Final question: all the allocated memory will be released?
For example, if a button has an image, the allocated memory of the image will be also released automatically?
Posted By: Ayumi

Re: Working with digits - 03/22/19 22:44

Quote:
Does it mean, if a Panel is deleted, all the elements related with that will be removed?


Sure

Quote:
Final question: all the allocated memory will be released?


I am not ...sure.

Quote:
For example, if a button has an image, the allocated memory of the image will be also released automatically?


No,..this depend on your Pointer.

Panel.bmap = bmap_create(...); -> This Image will be removed if the panel is deleted

----

BMAP* bmp = bmap_create(...);
Panel.bmap = bmp; -> This Image will not be removed if the panel is deleted (if global )
Posted By: txesmi

Re: Working with digits - 03/23/19 11:10

Originally Posted By: Ayumi
Quote:
For example, if a button has an image, the allocated memory of the image will be also released automatically?


No,..this depend on your Pointer.

Panel.bmap = bmap_create(...); -> This Image will be removed if the panel is deleted

----

BMAP* bmp = bmap_create(...);
Panel.bmap = bmp; -> This Image will not be removed if the panel is deleted (because BMAP Pointer is global)


I would bet that is wrong. I think the engine removes nothing but the globally declared stuff. You must remove everything you create by any of the '..._create' functions and, of course, all you allocate with 'sys_malloc'.

Code:
BMAP *gbBmp = "myImage.tga"; // This image is allocated and released by the engine automatically as far as ir is declared globally.
PANEL *gbPan =  {
   bmap = bgBmp; // This image will be removed as far as it is allocated in the program start by the engine, as happens with the PANEL struct.
   window(200,0,40,20,"compass.pcx",compass_pos.x,compass_pos.y); // 'compass.pcx' will also be released when the panel is removed.
};
function myFnc() {
   gbPan.bmap = bmap_create("myImage.tga"); // This image is not automatically released by the engine, does not matter where you save its reference. You must remove it when you are done.
}

Posted By: Ayumi

Re: Working with digits - 03/23/19 11:54

The manual said:
bmap_createblack(var width, var height, var format): BMAP*
Creates a bmap at runtime. bmap_create loads the content from an image file or from a cutout of an image , bmap_createblack creates a black bmap with given dimensions that can later be filled with a color. Objects created this way are automatically deleted on closing the engine, or by calling the ptr_remove function.

(and i already tryed this few month before)
If you delete the Panel by ptr_remove, the BMAP (crated by bmap_create(); also will be removed by engine)

Posted By: txesmi

Re: Working with digits - 03/23/19 13:15

Ok. It is true. The engine frees all its structs at closing time. But 'ptr_remove' does not remove the bitmaps pointed by its elements. Take a look at this:

Code:
#include <acknex.h>

void main () {
	wait(3);
	
	PANEL *_pan = pan_create("flags=SHOW", 1);
	_pan->bmap = bmap_createblack(128, 128, 24);
	bmap_fill(_pan->bmap, COLOR_RED, 100);
	
	while(!key_esc)
		wait(1);
	
	//bmap_remove(_pan->bmap);
	ptr_remove(_pan);
	
	while(key_esc){
		DEBUG_BMAP(_pan->bmap, 1, 1);
		wait(1);
	}
		
	sys_exit(NULL);
}



If you don't delete the bitmap before 'ptr_remove', it remains in the graphics card, so it is not deleted. Forgive the tricky thing of accesing hypothetically released memory wink
Posted By: Ayumi

Re: Working with digits - 03/23/19 13:36

Quote:
If you don't delete the bitmap before 'ptr_remove', it remains in the graphics card, so it is not deleted. Forgive the tricky thing of accesing hypothetically released memory


hehe yes,i know, because it s local created.
Try panel.bmap = ent_create()...
Posted By: Aku_Aku

Re: Working with digits - 03/23/19 14:38

Thanks guys for the answers. I hope i understood well all of them.
But one thing remained:
Quote:
hehe yes,i know, because it s local created.
Try panel.bmap = ent_create()...

What is it?
Posted By: Ayumi

Re: Working with digits - 03/23/19 15:05

@Aku_Aku

Code:
PANEL* Pan = 
{
   flags |= SHOW;
}


void Func()
{
   Pan.bmap = ent_create("this.tga",...);

   wait(1);
   ptr_remove(Pan); -> delete bmap + panel by engine
}

Posted By: Uhrwerk

Re: Working with digits - 03/23/19 16:10

Why do you think it would remove an externally created bmap as well? I really doubt that. If the bitmap would be defined in the panel by name, yes, then it would be removed as well, but a pointer that is created and assigned afterwards shouldn't be removed in my understanding.
Posted By: Ayumi

Re: Working with digits - 03/25/19 10:48

I "guess", because ptr_remove remove dynamically created as well as statically defined objects. If you havn t created any global /local BMAP Pointer, ptr_remove should remove the bmap Pointer with the Panel Pointer.

To accomplish the Question, i will try some memory Tests.


EDIT: Ok you are right. (I forgot, it s same as STRING* in TEXT Struct). You need to remove the bmap Pointer first, than Panel itself.
© 2024 lite-C Forums