Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / dbGetEntry() error

Author
Message
zao420
20
Years of Service
User Offline
Joined: 5th Aug 2003
Location: Canada
Posted: 6th Feb 2006 15:26
Hi i am using dbGetEntry() to get typed info for my item editor. not sure if i am doing this the best way. what do you guys think of this.

i am not at home so the code ia m usingmay differ a little bit.

if i use std::string buffer = dbGetEntry();
crash with an error unable to read memory at 0x00000000
so i use


Acolyte
18
Years of Service
User Offline
Joined: 3rd Feb 2006
Location:
Posted: 6th Feb 2006 20:03
i notice that in one of your lines the entry is as follows:
MyText =+ buffer;
I think that the operand is backwards. It should be '+=' not '=+'. I don't know if this is the source of your problems, but it could have something to do with it. Sorry if i wasn't more help.

The scarecrow has no mind, but serves its function well.
Barnski
18
Years of Service
User Offline
Joined: 26th Jan 2006
Location: Switzerland, Zurich
Posted: 6th Feb 2006 23:30
hi zao420,

I assume that if dbGetEntry() hasn't read anything, it returns a NULL pointer (0x0) (although I dont know when this could be possible, maybe when hitting escape key? since return key will return the empty string... ).
so you have to check after the call if its not NULL, as you did, but you can use the in stdlib.h defined constant:


greets,
Barnski.

-- I just started with DarkSDK, by translating DBP Projects. --
zao420
20
Years of Service
User Offline
Joined: 5th Aug 2003
Location: Canada
Posted: 7th Feb 2006 19:05
@Acolyte

i just retyped it all well i am at work don't have the net at home.
that part of it works fine.

@ barnski
It seams to return the null pointer when no keys have been pressed.
then after the key has been pressed it seams to work fine but when you clear the buffer and loops again even when there is no key pressed seams to pass and empty string but buffer != "" seams to no stop it.

Barnski
18
Years of Service
User Offline
Joined: 26th Jan 2006
Location: Switzerland, Zurich
Posted: 7th Feb 2006 20:39
There is a difference between an "empty string" and a str-pointer that is NULL.

Obviously dbEntry() works as follows:
When there hasn't been any key hits, it returns a NULL pointer (that is 0x0 = 0). In other words, there has not been created a "string"... or in more other words, there has not been done a memory allocation. since dynamic sized strings do need dynamic memory allocation, it would make no sence to reserver 1 byte of memory just to represent an empty string. Instead you have to check if your str pointer is not NULL.
if a key has been hit, it wont be NULL (address will be > 0x0).

altough I cannot confirm this, since I haven't tested it, I hope that the theory just helped abit.

greets,
Barnski.

-- I just started with DarkSDK, by translating DBP Projects. --
zao420
20
Years of Service
User Offline
Joined: 5th Aug 2003
Location: Canada
Posted: 8th Feb 2006 14:25
so i rewrote the code just a bit with some of your suggestions.



as long as nothing is typed every thing works fine now problem.

as soon as you type something. it keeps going though the if statement. well steping though the code it says buffer = "".
i will post the whole class later when i get a chance to.

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th Feb 2006 14:57
This bit:

buffer != ""

... will never be true. You can't compare string contents like that - it will compare the string pointers instead. Try changing the 'if' to this:

if (buffer != NULL && buffer[0] != 0)

For free Plug-ins and source code http://www.matrix1.demon.co.uk
zao420
20
Years of Service
User Offline
Joined: 5th Aug 2003
Location: Canada
Posted: 8th Feb 2006 15:59
thanks will try that out when i get home

Barnski
18
Years of Service
User Offline
Joined: 26th Jan 2006
Location: Switzerland, Zurich
Posted: 8th Feb 2006 19:36
Right, if you want to compare strings you can for example use

int strcmp(char*, char*)

as defined in string.h (a c-lib).
http://www.cplusplus.com/ref/cstring/

to check whether the first char of your buffer is = 0 is the same as checking if its an empty string, because in C the char-strings are terminated by a 0 byte.

greets,
Barnski.

-- I just started with DarkSDK, by translating DBP Projects. --
zao420
20
Years of Service
User Offline
Joined: 5th Aug 2003
Location: Canada
Posted: 13th Feb 2006 16:51
i did what IanM suggested still have a memory leak somewhere will have to figuare that out. or i may just make my item edit in just c++

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Feb 2006 19:24
According to an entry Lee made in a bug post, there is a memory leak hidden in the DirectInput library. There's nothing you can do about it, except maybe implement your own key input routines.

For free Plug-ins and source code http://www.matrix1.demon.co.uk
Barnski
18
Years of Service
User Offline
Joined: 26th Jan 2006
Location: Switzerland, Zurich
Posted: 15th Feb 2006 16:40
Apart from that DirectInput Memory "Caching" or memory leak IanM spoke of, there is another thing you need to take care of.

(bear in mind; I have not tested this. I could be wrong )

You need to free the memory that has been allocated by the dbEntry() function. so, always after calling dbEntry and storing the result in your char pointer, you need to call free (my_ptr).
Of course only after you dont need the information anymore. AND of course only if it is NOT NULL.

so your code should look something like this (with a loop):


hope this is correct and that it was helpful.

greets,
Barnski.

-- I just started with DarkSDK, by translating DBP Projects. --

Login to post a reply

Server time is: 2024-05-06 04:30:28
Your offset time is: 2024-05-06 04:30:28