Segmentation Fault

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

Segmentation Fault

singmajesty
Hey everyone,

I'm experiencing a Segmentation Fault. Is there something more I need to  
do to trigger garbage collection or something similar?

Basically I can play my game 7 or 8 times. Then the last time it crashes  
with a segmentation fault. I've tried using clearing my arrays, removed my  
display objects, nullifying unneeded values and even checking  
System.totalMemory to keep from stressing the game with a new level until  
the amount of memory its using from the last level has died down.

Regardless, it crashes. Whether I play slowly or quickly, or whatever I do.

I'm probably being a bit wasteful. I'm not using a tile sheet ... I'm  
loading separate bitmaps. All in all, one level might be as many as 290  
objects on-screen. The performance is fine, and the memory use seems fine,  
so I'm not sure what the problem is? Once it reaches 2200-2600 objects it  
seems to crash, no matter what. I've also tried using cpp.vm.Gc to try and  
trigger the internal garbage collection when I'm dumping old data. I'm not  
sure what to do.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

slenkar
'segmentation fault' can mean that the graphics card cant handle what is going on,
e.g. trying to use an unsupported opengl extension

In your case you may be running out of video memory?
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

singmajesty
I knew the problem was related to memory, but I had not thought of running  
out of video memory.

I'm concerned, because I'm doing what I can to dump the old instances and  
wipe them from memory, but nevertheless I receive a crash after the eighth  
or ninth level. I know that I could optimize more, but if I don't figure  
out this problem, I'm still going to have this problem down the road. If  
it isn't eight times, maybe it's twenty times. That still isn't good  
enough for me. I could reuse all of the assets, and maybe stretch the  
lifetime even more, but still ... if I have enough levels with enough  
variety, at this rate I'm always going to have a crash.

What can I do to "clean things up" so I can restart with a blank slate,  
rather than overloading the memory eventually?

I'm removing my instances from the display list, removing event listeners,  
setting null values, trying to trigger garbage collection and waiting for  
memory usage to die down before generating a new level. What else can I do?

Thanks



On Sun, 05 Sep 2010 20:32:16 -0700, slenkar <[hidden email]> wrote:

>
> 'segmentation fault' can mean that the graphics card cant handle what is
> going on,
> e.g. trying to use an unsupported opengl extension
>
> In your case you may be running out of video memory?

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

Cauê W.
I've had some segfault trouble in the past version of hxcpp, and it was directly related to handles alloc'ed by gc_alloc(or something like that), and used by alloc_abstract, if I remember correctly.
THe problem is that those handles trigger a bug with hxcpp's gc, which I think doesn't count the handle reference, so the gc collects it. This was a pain to isolate the bug, specially because it only appeared when the debug flag was off.

I was having this problem specially with the File class, so I've made a simple patch by replacing gc_alloc by standard c malloc. This meant that no pointer would ever be gc'ed, but in my case that was fine.

I haven't reported it because I've tested with 2.06 and it seemed that it was gone. But maybe you will want to check it out? Maybe you could try just recompiling the ndll's with hxcpp 2.06 ?

2010/9/6 Joshua Granick <[hidden email]>
I knew the problem was related to memory, but I had not thought of running out of video memory.

I'm concerned, because I'm doing what I can to dump the old instances and wipe them from memory, but nevertheless I receive a crash after the eighth or ninth level. I know that I could optimize more, but if I don't figure out this problem, I'm still going to have this problem down the road. If it isn't eight times, maybe it's twenty times. That still isn't good enough for me. I could reuse all of the assets, and maybe stretch the lifetime even more, but still ... if I have enough levels with enough variety, at this rate I'm always going to have a crash.

What can I do to "clean things up" so I can restart with a blank slate, rather than overloading the memory eventually?

I'm removing my instances from the display list, removing event listeners, setting null values, trying to trigger garbage collection and waiting for memory usage to die down before generating a new level. What else can I do?

Thanks




On Sun, 05 Sep 2010 20:32:16 -0700, slenkar <[hidden email]> wrote:


'segmentation fault' can mean that the graphics card cant handle what is
going on,
e.g. trying to use an unsupported opengl extension

In your case you may be running out of video memory?

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

Gamehaxe
In reply to this post by singmajesty
Hi,
To clean up, you need to remove all references to your objects -
one tricky place to look is event handlers - you must remove these too.
I have added some special code to help finding all these references.

First compile with -debug.
You need a unique class name - If you already have an object of type
say, "Level2" that should not exist at a certain point in time, you
can use that.  Otherwise make a dummy class, say "MyTrace" and
create an instance of it inside your level.

Then, after you go to the next level, you can use:

cpp.vp.Gc.trace(MyTrace)

to dump what references are actually keeping this object alive.

Hope this helps.

Hugh

> I knew the problem was related to memory, but I had not thought of  
> running out of video memory.
>
> I'm concerned, because I'm doing what I can to dump the old instances  
> and wipe them from memory, but nevertheless I receive a crash after the  
> eighth or ninth level. I know that I could optimize more, but if I don't  
> figure out this problem, I'm still going to have this problem down the  
> road. If it isn't eight times, maybe it's twenty times. That still isn't  
> good enough for me. I could reuse all of the assets, and maybe stretch  
> the lifetime even more, but still ... if I have enough levels with  
> enough variety, at this rate I'm always going to have a crash.
>
> What can I do to "clean things up" so I can restart with a blank slate,  
> rather than overloading the memory eventually?
>
> I'm removing my instances from the display list, removing event  
> listeners, setting null values, trying to trigger garbage collection and  
> waiting for memory usage to die down before generating a new level. What  
> else can I do?
>
> Thanks
>
>
>
> On Sun, 05 Sep 2010 20:32:16 -0700, slenkar <[hidden email]> wrote:
>
>>
>> 'segmentation fault' can mean that the graphics card cant handle what is
>> going on,
>> e.g. trying to use an unsupported opengl extension
>>
>> In your case you may be running out of video memory?

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

singmajesty
This did help a bit.

I was using a for each style loop to remove the event listeners. I changed  
it to a for loop and now it appears to be correctly discarding those  
Objects. I told Gc to look for "Sprite", and the now the instance count is  
way down, and consistent.

However, I'm still getting a segmentation fault after 8 to 9 rounds. I  
tried using BOEHM_GC, to see if that would help, but it didn't compile  
correctly. When I started looking into it it was hard to tell what was  
going wrong. I know that you had a blog post where you said that this was  
the default for all platforms other than iPhone ... I'm not sure if this  
is still the case.

The game is simple ... it's basically one class. I made of developing it  
quickly. I'm sending it to you ... just in case you are interested in  
running it on your end




On Sun, 05 Sep 2010 23:39:23 -0700, Hugh Sanderson <[hidden email]>  
wrote:

> Hi,
> To clean up, you need to remove all references to your objects -
> one tricky place to look is event handlers - you must remove these too.
> I have added some special code to help finding all these references.
>
> First compile with -debug.
> You need a unique class name - If you already have an object of type
> say, "Level2" that should not exist at a certain point in time, you
> can use that.  Otherwise make a dummy class, say "MyTrace" and
> create an instance of it inside your level.
>
> Then, after you go to the next level, you can use:
>
> cpp.vp.Gc.trace(MyTrace)
>
> to dump what references are actually keeping this object alive.
>
> Hope this helps.
>
> Hugh
>
>> I knew the problem was related to memory, but I had not thought of  
>> running out of video memory.
>>
>> I'm concerned, because I'm doing what I can to dump the old instances  
>> and wipe them from memory, but nevertheless I receive a crash after the  
>> eighth or ninth level. I know that I could optimize more, but if I  
>> don't figure out this problem, I'm still going to have this problem  
>> down the road. If it isn't eight times, maybe it's twenty times. That  
>> still isn't good enough for me. I could reuse all of the assets, and  
>> maybe stretch the lifetime even more, but still ... if I have enough  
>> levels with enough variety, at this rate I'm always going to have a  
>> crash.
>>
>> What can I do to "clean things up" so I can restart with a blank slate,  
>> rather than overloading the memory eventually?
>>
>> I'm removing my instances from the display list, removing event  
>> listeners, setting null values, trying to trigger garbage collection  
>> and waiting for memory usage to die down before generating a new level.  
>> What else can I do?
>>
>> Thanks
>>
>>
>>
>> On Sun, 05 Sep 2010 20:32:16 -0700, slenkar <[hidden email]> wrote:
>>
>>>
>>> 'segmentation fault' can mean that the graphics card cant handle what  
>>> is
>>> going on,
>>> e.g. trying to use an unsupported opengl extension
>>>
>>> In your case you may be running out of video memory?

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

Cauê W.
Joshua, are you sure it's a problem with too much memory being used? It seems that it's quite the opposite - you are trying to reference a pointer that was already gc'ed.
THis was what happened in my case. Do you have a stack trace when you run in debug mode? I've found out that linux isn't throwing the pretty errors. Try to run the same code on windows, and as a bonus, you'll be able to debug it with vs! : )

2010/9/6 Joshua Granick <[hidden email]>
This did help a bit.

I was using a for each style loop to remove the event listeners. I changed it to a for loop and now it appears to be correctly discarding those Objects. I told Gc to look for "Sprite", and the now the instance count is way down, and consistent.

However, I'm still getting a segmentation fault after 8 to 9 rounds. I tried using BOEHM_GC, to see if that would help, but it didn't compile correctly. When I started looking into it it was hard to tell what was going wrong. I know that you had a blog post where you said that this was the default for all platforms other than iPhone ... I'm not sure if this is still the case.

The game is simple ... it's basically one class. I made of developing it quickly. I'm sending it to you ... just in case you are interested in running it on your end





On Sun, 05 Sep 2010 23:39:23 -0700, Hugh Sanderson <[hidden email]> wrote:

Hi,
To clean up, you need to remove all references to your objects -
one tricky place to look is event handlers - you must remove these too.
I have added some special code to help finding all these references.

First compile with -debug.
You need a unique class name - If you already have an object of type
say, "Level2" that should not exist at a certain point in time, you
can use that.  Otherwise make a dummy class, say "MyTrace" and
create an instance of it inside your level.

Then, after you go to the next level, you can use:

cpp.vp.Gc.trace(MyTrace)

to dump what references are actually keeping this object alive.

Hope this helps.

Hugh

I knew the problem was related to memory, but I had not thought of running out of video memory.

I'm concerned, because I'm doing what I can to dump the old instances and wipe them from memory, but nevertheless I receive a crash after the eighth or ninth level. I know that I could optimize more, but if I don't figure out this problem, I'm still going to have this problem down the road. If it isn't eight times, maybe it's twenty times. That still isn't good enough for me. I could reuse all of the assets, and maybe stretch the lifetime even more, but still ... if I have enough levels with enough variety, at this rate I'm always going to have a crash.

What can I do to "clean things up" so I can restart with a blank slate, rather than overloading the memory eventually?

I'm removing my instances from the display list, removing event listeners, setting null values, trying to trigger garbage collection and waiting for memory usage to die down before generating a new level. What else can I do?

Thanks



On Sun, 05 Sep 2010 20:32:16 -0700, slenkar <[hidden email]> wrote:


'segmentation fault' can mean that the graphics card cant handle what is
going on,
e.g. trying to use an unsupported opengl extension

In your case you may be running out of video memory?

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

m5no1
In reply to this post by singmajesty
hi~
i meet same issue on iphone,I use "cpp.vm.enable(false);" to turn of gc,but it still crash because of out of memory.I 'm trying to use BOEHM_GC,but get a compile error too.have you found any idea for this now?
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

singmajesty
m5no1,

Fixing this problem (for now, at least) has come from two different places:


1.) A new version of NME, with an alpha table fix


There was a bug in how alpha blending values were stored internally. When  
using a lot of alpha (particularly using an alpha tween), this eventually  
created problems. Hugh figured this out and uploaded the change to SVN


2.) Problem loading too many bitmaps?


I'm not sure of the exact "real" cause for this, but loading too many  
bitmaps from file was also to blame. Each time I created a new level, I  
loaded each graphic from file. Since many graphics were the same, this  
could cause many repetitive file load calls. I implemented a caching  
system in my graphic utility class instead, so it would only load graphics  
which were necessary.



Here's what the file loading part of my utility class looks like. It's a  
quick fix but its working. The Flash code hasn't been optimized for online  
use ... it's mainly for me while I'm doing local development, so the Flash  
portion has no caching or preloading. I also have a "forceSprite" value in  
this method, because mouse events in CPP appear to only work for sprites  
and not bitmaps. I set it to true when I need to listen to a click event  
for my graphic.



private static var loadGraphicCache:Hash <BitmapData> = new Hash  
<BitmapData> ();


public static function loadGraphic (path:String, forceSprite:Bool = false,  
cache:Bool = true):DisplayObject {
       
        #if cpp
       
        var bitmap:Bitmap;
       
        if (cache) {
               
                if (!loadGraphicCache.exists (path)) {
                       
                        loadGraphicCache.set (path, BitmapData.loadFromBytes  
(ByteArray.readFile (path)));
                       
                }
               
                bitmap = new Bitmap (loadGraphicCache.get (path));
               
        } else {
               
                bitmap = new Bitmap (BitmapData.loadFromBytes (ByteArray.readFile  
(path)));
               
        }
       
        if (forceSprite) {
               
                var sprite:Sprite = new Sprite ();
                sprite.addChild (bitmap);
               
                return sprite;
               
        } else {
               
                return bitmap;
               
        }
       
        #else
       
        var loader:Loader = new Loader ();
        loader.load (new URLRequest (path));
       
        return loader;
       
        #end
       
}





On Tue, 07 Sep 2010 06:07:16 -0700, m5no1 <[hidden email]> wrote:

>
> hi~
> i meet same issue on iphone,I use "cpp.vm.enable(false);" to turn of  
> gc,but
> it still crash because of out of memory.I 'm trying to use BOEHM_GC,but  
> get
> a compile error too.have you found any idea for this now?

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

m5no1
hi Joshua!
i use BitmapData.loadFromBytes to load image in my game,and i a caching system too.but it still crash and crash.

I finally found the problem. it's about ByteArray.readFile;

I have change ExternalInerface.cpp and rebuilded ndll:

static void release_object2(value inValue)
{
   //make this empty ,so byte array would not be gc.
}

value ObjectToAbstract2(Object *inObject)
{
   inObject->IncRef();
   value result = alloc_abstract(gObjectKind,inObject);
   val_gc(result,release_object2);
   return result;
}

value nme_byte_array_read_file(value inFilename)
{
   FILE *file = OpenRead(val_os_string(inFilename));
   if (!file)
      return alloc_null();

   fseek(file,0,SEEK_END);
   int len = ftell(file);
   fseek(file,0,SEEK_SET);

   ByteArray *result = new ByteArray;
        result->mBytes.resize(len);
   fread(&result->mBytes[0],len,1,file);
   fclose(file);

        return ObjectToAbstract2(result);
}


I make release_object2(value inValue) empty ,so byte array would not be gc.and never crash!
everything run well now.
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

Gamehaxe
Hi,
I have found the source of the crash - it follows on from your conclusion.
On iphone (only) reading the image from the byte array actually
freed the byte array.  Then, when it got normally collected, it freed it  
again.
The fix was a simple one - a slight change in parameter to the iphone
image reading code.  I mistook the parameter to mean if would just hold
a pointer to my data, but it actually freed to too.
The fix is in nme SVN.

Hugh

>
> hi Joshua!
> i use BitmapData.loadFromBytes to load image in my game,and i a caching
> system too.but it still crash and crash.
>
> I finally found the problem. it's about ByteArray.readFile;
>
> I have change ExternalInerface.cpp and rebuilded ndll:
>
> static void release_object2(value inValue)
> {
>    //make this empty ,so byte array would not be gc.
> }
>
> value ObjectToAbstract2(Object *inObject)
> {
>    inObject->IncRef();
>    value result = alloc_abstract(gObjectKind,inObject);
>    val_gc(result,release_object2);
>    return result;
> }
>
> value nme_byte_array_read_file(value inFilename)
> {
>    FILE *file = OpenRead(val_os_string(inFilename));
>    if (!file)
>       return alloc_null();
>
>    fseek(file,0,SEEK_END);
>    int len = ftell(file);
>    fseek(file,0,SEEK_SET);
>
>    ByteArray *result = new ByteArray;
>         result->mBytes.resize(len);
>    fread(&result->mBytes[0],len,1,file);
>    fclose(file);
>
>         return ObjectToAbstract2(result);
> }
>
>
> I make release_object2(value inValue) empty ,so byte array would not be
> gc.and never crash!
> everything run well now.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

m5no1
great work  THANKs!
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

Franco Ponticelli
In reply to this post by Gamehaxe
I guess my issue is a different one since I don't use NME. I will tell you more in the next few days when I will have the time to go further with the development.

Franco

On Wed, Sep 8, 2010 at 5:00 PM, Hugh Sanderson <[hidden email]> wrote:
Hi,
I have found the source of the crash - it follows on from your conclusion.
On iphone (only) reading the image from the byte array actually
freed the byte array.  Then, when it got normally collected, it freed it again.
The fix was a simple one - a slight change in parameter to the iphone
image reading code.  I mistook the parameter to mean if would just hold
a pointer to my data, but it actually freed to too.
The fix is in nme SVN.

Hugh



hi Joshua!
i use BitmapData.loadFromBytes to load image in my game,and i a caching
system too.but it still crash and crash.

I finally found the problem. it's about ByteArray.readFile;

I have change ExternalInerface.cpp and rebuilded ndll:

static void release_object2(value inValue)
{
  //make this empty ,so byte array would not be gc.
}

value ObjectToAbstract2(Object *inObject)
{
  inObject->IncRef();
  value result = alloc_abstract(gObjectKind,inObject);
  val_gc(result,release_object2);
  return result;
}

value nme_byte_array_read_file(value inFilename)
{
  FILE *file = OpenRead(val_os_string(inFilename));
  if (!file)
     return alloc_null();

  fseek(file,0,SEEK_END);
  int len = ftell(file);
  fseek(file,0,SEEK_SET);

  ByteArray *result = new ByteArray;
       result->mBytes.resize(len);
  fread(&result->mBytes[0],len,1,file);
  fclose(file);

       return ObjectToAbstract2(result);
}


I make release_object2(value inValue) empty ,so byte array would not be
gc.and never crash!
everything run well now.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

Cauê W.
Franco, what external libs are you using? Maybe we can narrow it down to find what's up?

Cheers!
Cauê

2010/9/8 Franco Ponticelli <[hidden email]>
I guess my issue is a different one since I don't use NME. I will tell you more in the next few days when I will have the time to go further with the development.

Franco


On Wed, Sep 8, 2010 at 5:00 PM, Hugh Sanderson <[hidden email]> wrote:
Hi,
I have found the source of the crash - it follows on from your conclusion.
On iphone (only) reading the image from the byte array actually
freed the byte array.  Then, when it got normally collected, it freed it again.
The fix was a simple one - a slight change in parameter to the iphone
image reading code.  I mistook the parameter to mean if would just hold
a pointer to my data, but it actually freed to too.
The fix is in nme SVN.

Hugh



hi Joshua!
i use BitmapData.loadFromBytes to load image in my game,and i a caching
system too.but it still crash and crash.

I finally found the problem. it's about ByteArray.readFile;

I have change ExternalInerface.cpp and rebuilded ndll:

static void release_object2(value inValue)
{
  //make this empty ,so byte array would not be gc.
}

value ObjectToAbstract2(Object *inObject)
{
  inObject->IncRef();
  value result = alloc_abstract(gObjectKind,inObject);
  val_gc(result,release_object2);
  return result;
}

value nme_byte_array_read_file(value inFilename)
{
  FILE *file = OpenRead(val_os_string(inFilename));
  if (!file)
     return alloc_null();

  fseek(file,0,SEEK_END);
  int len = ftell(file);
  fseek(file,0,SEEK_SET);

  ByteArray *result = new ByteArray;
       result->mBytes.resize(len);
  fread(&result->mBytes[0],len,1,file);
  fclose(file);

       return ObjectToAbstract2(result);
}


I make release_object2(value inValue) empty ,so byte array would not be
gc.and never crash!
everything run well now.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

Franco Ponticelli
Custom made to wrap some of the frameworks used in IPhone (portions of UIKit and QuartzCore). They use a mix of ObjC and C++ with CFFI to make the binding work. Of course the error can be there :)

Franco

On Wed, Sep 8, 2010 at 6:51 PM, Cauê Waneck <[hidden email]> wrote:
Franco, what external libs are you using? Maybe we can narrow it down to find what's up?

Cheers!
Cauê

2010/9/8 Franco Ponticelli <[hidden email]>
I guess my issue is a different one since I don't use NME. I will tell you more in the next few days when I will have the time to go further with the development.

Franco


On Wed, Sep 8, 2010 at 5:00 PM, Hugh Sanderson <[hidden email]> wrote:
Hi,
I have found the source of the crash - it follows on from your conclusion.
On iphone (only) reading the image from the byte array actually
freed the byte array.  Then, when it got normally collected, it freed it again.
The fix was a simple one - a slight change in parameter to the iphone
image reading code.  I mistook the parameter to mean if would just hold
a pointer to my data, but it actually freed to too.
The fix is in nme SVN.

Hugh



hi Joshua!
i use BitmapData.loadFromBytes to load image in my game,and i a caching
system too.but it still crash and crash.

I finally found the problem. it's about ByteArray.readFile;

I have change ExternalInerface.cpp and rebuilded ndll:

static void release_object2(value inValue)
{
  //make this empty ,so byte array would not be gc.
}

value ObjectToAbstract2(Object *inObject)
{
  inObject->IncRef();
  value result = alloc_abstract(gObjectKind,inObject);
  val_gc(result,release_object2);
  return result;
}

value nme_byte_array_read_file(value inFilename)
{
  FILE *file = OpenRead(val_os_string(inFilename));
  if (!file)
     return alloc_null();

  fseek(file,0,SEEK_END);
  int len = ftell(file);
  fseek(file,0,SEEK_SET);

  ByteArray *result = new ByteArray;
       result->mBytes.resize(len);
  fread(&result->mBytes[0],len,1,file);
  fclose(file);

       return ObjectToAbstract2(result);
}


I make release_object2(value inValue) empty ,so byte array would not be
gc.and never crash!
everything run well now.

--
haXe - an open source web programming language
http://haxe.org


--

haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

Cauê W.
oh well, maybe it's something up with objective c having already a gc of its own, then?

2010/9/8 Franco Ponticelli <[hidden email]>
Custom made to wrap some of the frameworks used in IPhone (portions of UIKit and QuartzCore). They use a mix of ObjC and C++ with CFFI to make the binding work. Of course the error can be there :)

Franco

On Wed, Sep 8, 2010 at 6:51 PM, Cauê Waneck <[hidden email]> wrote:
Franco, what external libs are you using? Maybe we can narrow it down to find what's up?

Cheers!
Cauê

2010/9/8 Franco Ponticelli <[hidden email]>
I guess my issue is a different one since I don't use NME. I will tell you more in the next few days when I will have the time to go further with the development.

Franco


On Wed, Sep 8, 2010 at 5:00 PM, Hugh Sanderson <[hidden email]> wrote:
Hi,
I have found the source of the crash - it follows on from your conclusion.
On iphone (only) reading the image from the byte array actually
freed the byte array.  Then, when it got normally collected, it freed it again.
The fix was a simple one - a slight change in parameter to the iphone
image reading code.  I mistook the parameter to mean if would just hold
a pointer to my data, but it actually freed to too.
The fix is in nme SVN.

Hugh



hi Joshua!
i use BitmapData.loadFromBytes to load image in my game,and i a caching
system too.but it still crash and crash.

I finally found the problem. it's about ByteArray.readFile;

I have change ExternalInerface.cpp and rebuilded ndll:

static void release_object2(value inValue)
{
  //make this empty ,so byte array would not be gc.
}

value ObjectToAbstract2(Object *inObject)
{
  inObject->IncRef();
  value result = alloc_abstract(gObjectKind,inObject);
  val_gc(result,release_object2);
  return result;
}

value nme_byte_array_read_file(value inFilename)
{
  FILE *file = OpenRead(val_os_string(inFilename));
  if (!file)
     return alloc_null();

  fseek(file,0,SEEK_END);
  int len = ftell(file);
  fseek(file,0,SEEK_SET);

  ByteArray *result = new ByteArray;
       result->mBytes.resize(len);
  fread(&result->mBytes[0],len,1,file);
  fclose(file);

       return ObjectToAbstract2(result);
}


I make release_object2(value inValue) empty ,so byte array would not be
gc.and never crash!
everything run well now.

--
haXe - an open source web programming language
http://haxe.org


--

haXe - an open source web programming language
http://haxe.org


--

haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

Cauê W.
oops, just saw that gc isn't available for iphone apps :S
sorry!

2010/9/8 Cauê Waneck <[hidden email]>
oh well, maybe it's something up with objective c having already a gc of its own, then?

2010/9/8 Franco Ponticelli <[hidden email]>
Custom made to wrap some of the frameworks used in IPhone (portions of UIKit and QuartzCore). They use a mix of ObjC and C++ with CFFI to make the binding work. Of course the error can be there :)

Franco

On Wed, Sep 8, 2010 at 6:51 PM, Cauê Waneck <[hidden email]> wrote:
Franco, what external libs are you using? Maybe we can narrow it down to find what's up?

Cheers!
Cauê

2010/9/8 Franco Ponticelli <[hidden email]>
I guess my issue is a different one since I don't use NME. I will tell you more in the next few days when I will have the time to go further with the development.

Franco


On Wed, Sep 8, 2010 at 5:00 PM, Hugh Sanderson <[hidden email]> wrote:
Hi,
I have found the source of the crash - it follows on from your conclusion.
On iphone (only) reading the image from the byte array actually
freed the byte array.  Then, when it got normally collected, it freed it again.
The fix was a simple one - a slight change in parameter to the iphone
image reading code.  I mistook the parameter to mean if would just hold
a pointer to my data, but it actually freed to too.
The fix is in nme SVN.

Hugh



hi Joshua!
i use BitmapData.loadFromBytes to load image in my game,and i a caching
system too.but it still crash and crash.

I finally found the problem. it's about ByteArray.readFile;

I have change ExternalInerface.cpp and rebuilded ndll:

static void release_object2(value inValue)
{
  //make this empty ,so byte array would not be gc.
}

value ObjectToAbstract2(Object *inObject)
{
  inObject->IncRef();
  value result = alloc_abstract(gObjectKind,inObject);
  val_gc(result,release_object2);
  return result;
}

value nme_byte_array_read_file(value inFilename)
{
  FILE *file = OpenRead(val_os_string(inFilename));
  if (!file)
     return alloc_null();

  fseek(file,0,SEEK_END);
  int len = ftell(file);
  fseek(file,0,SEEK_SET);

  ByteArray *result = new ByteArray;
       result->mBytes.resize(len);
  fread(&result->mBytes[0],len,1,file);
  fclose(file);

       return ObjectToAbstract2(result);
}


I make release_object2(value inValue) empty ,so byte array would not be
gc.and never crash!
everything run well now.

--
haXe - an open source web programming language
http://haxe.org


--

haXe - an open source web programming language
http://haxe.org


--

haXe - an open source web programming language
http://haxe.org


--

haXe - an open source web programming language
http://haxe.org



--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Fault

Franco Ponticelli
No it is not :) 

On Wed, Sep 8, 2010 at 7:49 PM, Cauê Waneck <[hidden email]> wrote:
oops, just saw that gc isn't available for iphone apps :S
sorry!

2010/9/8 Cauê Waneck <[hidden email]>

oh well, maybe it's something up with objective c having already a gc of its own, then?

2010/9/8 Franco Ponticelli <[hidden email]>
Custom made to wrap some of the frameworks used in IPhone (portions of UIKit and QuartzCore). They use a mix of ObjC and C++ with CFFI to make the binding work. Of course the error can be there :)

Franco

On Wed, Sep 8, 2010 at 6:51 PM, Cauê Waneck <[hidden email]> wrote:
Franco, what external libs are you using? Maybe we can narrow it down to find what's up?

Cheers!
Cauê

2010/9/8 Franco Ponticelli <[hidden email]>
I guess my issue is a different one since I don't use NME. I will tell you more in the next few days when I will have the time to go further with the development.

Franco


On Wed, Sep 8, 2010 at 5:00 PM, Hugh Sanderson <[hidden email]> wrote:
Hi,
I have found the source of the crash - it follows on from your conclusion.
On iphone (only) reading the image from the byte array actually
freed the byte array.  Then, when it got normally collected, it freed it again.
The fix was a simple one - a slight change in parameter to the iphone
image reading code.  I mistook the parameter to mean if would just hold
a pointer to my data, but it actually freed to too.
The fix is in nme SVN.

Hugh



hi Joshua!
i use BitmapData.loadFromBytes to load image in my game,and i a caching
system too.but it still crash and crash.

I finally found the problem. it's about ByteArray.readFile;

I have change ExternalInerface.cpp and rebuilded ndll:

static void release_object2(value inValue)
{
  //make this empty ,so byte array would not be gc.
}

value ObjectToAbstract2(Object *inObject)
{
  inObject->IncRef();
  value result = alloc_abstract(gObjectKind,inObject);
  val_gc(result,release_object2);
  return result;
}

value nme_byte_array_read_file(value inFilename)
{
  FILE *file = OpenRead(val_os_string(inFilename));
  if (!file)
     return alloc_null();

  fseek(file,0,SEEK_END);
  int len = ftell(file);
  fseek(file,0,SEEK_SET);

  ByteArray *result = new ByteArray;
       result->mBytes.resize(len);
  fread(&result->mBytes[0],len,1,file);
  fclose(file);

       return ObjectToAbstract2(result);
}


I make release_object2(value inValue) empty ,so byte array would not be
gc.and never crash!
everything run well now.

--
haXe - an open source web programming language
http://haxe.org


--

haXe - an open source web programming language
http://haxe.org


--

haXe - an open source web programming language
http://haxe.org


--

haXe - an open source web programming language
http://haxe.org



--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org