Problem with char[] and memset

You must understand the Game Editor concepts, before post here.

Problem with char[] and memset

Postby skydereign » Mon Jun 15, 2009 6:45 am

This could be just a problem with my setup, though I was able to replicate it in a simple version. I want to clear an array, to be specific a char[]. To clear an array, you use memset, neh?
Code: Select all
memset(myarray, 0, sizeof(myarray));

This should reset myarray, no matter what dimensions. The problem does not seem to be oriented in dimension, and actually it does set the subs to 0, setting it to null. It seems gameEditor or just some part of my code keeps the chars within the array alive. I found this not using text and strcpy, but I used this to show the problem in a simple setup, meaning it is not due to the text. In this, the actor moves and shows text, which does not make sense knowing how I set it up. For some reason, the char[] maintains its text whilst being NULL, so it is NULL and has text... Is this an error on my part, or is something else happening?
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Problem with char[] and memset

Postby makslane » Mon Jun 15, 2009 12:21 pm

Is better use:
memset(myarray, 0, n1*n2*sizeof(arraytype));


Where n1, n2, ... are the dimentions of your array, and arraytype is the type of elements (int, double, ...)
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Re: Problem with char[] and memset

Postby skydereign » Mon Jun 15, 2009 7:01 pm

They end up being the same thing, as that is what sizeof shows. If I didn't know what the variable I was memseting, it may have had an effect, but since I know, it doesn't really matter, but I guess good habits are good to have. Though that does not change the outcome. It still seems to be caught in the dual state... Sorry, I forgot to attach the example.
Attachments
memset.zip
(17.38 KiB) Downloaded 134 times
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Problem with char[] and memset

Postby makslane » Mon Jun 15, 2009 11:18 pm

Ops! It is a ugly bug in the memset function used by Game Editor.
The menset with 0 value doesn't works :oops:
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Re: Problem with char[] and memset

Postby skydereign » Tue Jun 16, 2009 5:35 am

A bug in the actual function? How does that work, did you rewrite parts of the language for gE, or what? Well, I developed a substitute function that does work, though it is slightly limited, but easily adaptable. I am going to post it on another more easily found thread.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Problem with char[] and memset

Postby makslane » Tue Jun 16, 2009 12:09 pm

The current Game Editor uses the EiC library to parser and execute the C scripts.
To make the scripts safe and avoid crashs, the EiC rewrite the standard C functions, like memset!
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron