Gamestudio Links
Zorro Links
Newest Posts
blogherenowcenter
by 3s05bmmc. 06/05/24 06:08
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 853 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19057 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
checking a BMAP pointer if it's empty #182883
02/09/08 10:21
02/09/08 10:21
Joined: Aug 2005
Posts: 1,012
germany, dresden
ulf Offline OP
Serious User
ulf  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,012
germany, dresden
hey, the following situation...
i have a bitmap pointer like this

Code:

BMAP* b_dot = NULL;
char* b_dot_file = "dot.tga";

//then i fill it like this

BMAP* bmapCheck(BMAP* source, char* file)
{
if (source == NULL) {
source = bmap_create(file);
}

return(source);
}


it gets filled the first time, but also the second and so on... so i produce some sort of filling the memory forever.

so source is always == NULL but shouldn't it be filled the second time i run this function?
right now its not and a new bitmap is created in memory everytime i rerun the function.
it gets called like this from a particle function f.i.

p.bmap=bmapCheck(b_dot, b_dot_file);


thanks for any help.

Last edited by ulf; 02/09/08 10:32.
Re: checking a BMAP pointer if it's empty [Re: ulf] #182884
02/09/08 10:55
02/09/08 10:55
Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
T
TWO Offline

Serious User
TWO  Offline

Serious User
T

Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
Versuch mal

if( *source == 0 )

und

*source = bmap_create(file);

Re: checking a BMAP pointer if it's empty [Re: TWO] #182885
02/09/08 11:13
02/09/08 11:13
Joined: Aug 2005
Posts: 1,012
germany, dresden
ulf Offline OP
Serious User
ulf  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,012
germany, dresden
if i use

if( *source == 0 )

i get: machine code generator:can not translate EQ:STRUCT@8:LONG:LONG.

and with

*source = bmap_create(file);

i get: Can not convert 'POINTER' to 'struct BMAP'

):

Re: checking a BMAP pointer if it's empty [Re: ulf] #182886
02/09/08 12:54
02/09/08 12:54
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
Yes, ofcourse. *source is a BMAP, and you can't compare BMAP to int. And the second attempt: again *source is a BMAP, so you can't assign it a BMAP*.

The problem is you never assign anything to b_dot. Either make source a BMAP** and use *source in the function and call it with &b_dot, or make it b_dot=bmapCheck(b_dot, b_dot_file);. I would opt for the first option since it will guarantee that the pointer is not empty after you call that function (so you don't have to remember to assign it).

Remember that in your code, source is only a temporary copy of the contents of b_dot (which is a memory address). source is deallocated (not the thing it points to! only the 4 bytes that store the memory address) when the function ends, so assigning to it makes no sense.

Re: checking a BMAP pointer if it's empty [Re: Excessus] #182887
02/09/08 14:01
02/09/08 14:01
Joined: Aug 2005
Posts: 1,012
germany, dresden
ulf Offline OP
Serious User
ulf  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,012
germany, dresden
thanks! but as for assigning b_dot i did already use the function exactely as you said:

p.bmap=bmapCheck(b_dot, b_dot_file);

but this does not work. using the BMAP** and *source idea did only lead to engine crashes and doesnt really work. (i did call it with b_dot=bmapCheck(&b_dot, b_dot_file); in this case)

Last edited by ulf; 02/09/08 14:09.
Re: checking a BMAP pointer if it's empty [Re: ulf] #182888
02/09/08 14:14
02/09/08 14:14
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
Quote:

as for assigning b_dot i did use exactely as you said:

p.bmap=bmapCheck(b_dot, b_dot_file);



No you assign to p.bmap. I don't know what it is, but you should at least assign to b_dot too, since that is what you will pass as input the next time you call it: b_dot=bmapCheck(b_dot, b_dot_file);

Here is the (untested) code using a BMAP**. Does this crash?
Code:

BMAP* b_dot = NULL;
char* b_dot_file = "dot.tga";

//then i fill it like this

BMAP* bmapCheck(BMAP** source, char* file)
{
if (*source == NULL) {
*source = bmap_create(file);
}

return(*source);
}
bmapCheck(&b_dot, b_dot_file); // now b_dot should point to the new bitmap



Re: checking a BMAP pointer if it's empty [Re: Excessus] #182889
02/09/08 14:56
02/09/08 14:56
Joined: Aug 2005
Posts: 1,012
germany, dresden
ulf Offline OP
Serious User
ulf  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,012
germany, dresden
thank you very much Excessus now the problem seems to have solved and i think i understand it now. thanks very much again it works perfect.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1