haxenme / nme

A cross-platform native backend for Haxe projects
MIT License
479 stars 122 forks source link

Crash caused by preemptive mode #683

Closed nulld closed 3 years ago

nulld commented 3 years ago

Get used preemptive gc mode stage.setPreemtiveGcFrequency(180);

And sometimes getting this crash:

Crashed: com.apple.main-thread
0  CharmFarmTest                  0x102c0f478 (anonymous namespace)::DebuggerTrap() (.cold.1) + 74 (Immix.cpp:74)
1  CharmFarmTest                  0x101ffdee4 HxMutex::HxMutex() + 193 (Thread.h:193)
2  CharmFarmTest                  0x101ffdeb8 CriticalGCError(char const*) + 546 (Immix.cpp:546)
3  CharmFarmTest                  0x1020000b4 LocalAllocator::PauseForCollect() + 5919 (Immix.cpp:5919)
4  CharmFarmTest                  0x1020064c0 LocalAllocator::CallAlloc(int, unsigned int) + 6058 (Immix.cpp:6058)
5  CharmFarmTest                  0x102000640 hx::InternalNew(int, bool) + 6491 (Immix.cpp:6491)
6  CharmFarmTest                  0x102014a5c hx::NewString(int) + 117 (GcCommon.cpp:117)
7  CharmFarmTest                  0x102015424 char const* GCStringDup<char>(char const*, int, int*) + 420 (String.cpp:420)
8  CharmFarmTest                  0x1020152f4 String::create(char const*, int) + 787 (String.cpp:787)
9  CharmFarmTest                  0x101fdefb0 alloc_string_len + 438 (CFFI.cpp:438)
10 CharmFarmTest                  0x100f74fd0 alloc_string(char const*) + 28
11 CharmFarmTest                  0x10219ffb0 nme::ByteArray::ByteArray(char const*) + 926 (ExternalInterface.cpp:926)
12 CharmFarmTest                  0x10219ffe0 nme::ByteArray::ByteArray(char const*) + 928 (ExternalInterface.cpp:928)
13 CharmFarmTest                  0x10204b9bc nme::Font::Create(nme::TextFormat&, double, bool, bool) + 480 (Font.cpp:480)
14 CharmFarmTest                  0x10218bb08 nme::CharGroup::UpdateFont(double, bool) + 2686 (TextField.cpp:2686)
15 CharmFarmTest                  0x10218ad14 nme::TextField::Layout(nme::Matrix const&) + 2097 (TextField.cpp:2097)
16 CharmFarmTest                  0x10218a2ec nme::TextField::Render(nme::RenderTarget const&, nme::RenderState const&) + 1725 (TextField.cpp:1725)
17 CharmFarmTest                  0x102191bfc nme::DisplayObjectContainer::Render(nme::RenderTarget const&, nme::RenderState const&) + 1576 (Display.cpp:1576)
18 CharmFarmTest                  0x102191bfc nme::DisplayObjectContainer::Render(nme::RenderTarget const&, nme::RenderState const&) + 1576 (Display.cpp:1576)
19 CharmFarmTest                  0x102191bfc nme::DisplayObjectContainer::Render(nme::RenderTarget const&, nme::RenderState const&) + 1576 (Display.cpp:1576)
20 CharmFarmTest                  0x102191bfc nme::DisplayObjectContainer::Render(nme::RenderTarget const&, nme::RenderState const&) + 1576 (Display.cpp:1576)
21 CharmFarmTest                  0x102191bfc nme::DisplayObjectContainer::Render(nme::RenderTarget const&, nme::RenderState const&) + 1576 (Display.cpp:1576)
22 CharmFarmTest                  0x102191bfc nme::DisplayObjectContainer::Render(nme::RenderTarget const&, nme::RenderState const&) + 1576 (Display.cpp:1576)
23 CharmFarmTest                  0x102191bfc nme::DisplayObjectContainer::Render(nme::RenderTarget const&, nme::RenderState const&) + 1576 (Display.cpp:1576)
24 CharmFarmTest                  0x102191bfc nme::DisplayObjectContainer::Render(nme::RenderTarget const&, nme::RenderState const&) + 1576 (Display.cpp:1576)
25 CharmFarmTest                  0x102191bfc nme::DisplayObjectContainer::Render(nme::RenderTarget const&, nme::RenderState const&) + 1576 (Display.cpp:1576)
26 CharmFarmTest                  0x102191bfc nme::DisplayObjectContainer::Render(nme::RenderTarget const&, nme::RenderState const&) + 1576 (Display.cpp:1576)
27 CharmFarmTest                  0x10219dbec nme::Stage::RenderStage() + 559 (Stage.cpp:559)

Guess it's because of this function isn't really gc free: https://github.com/haxenme/nme/blob/master/src/nme/display/Stage.hx#L618

@hughsando, what do you think, will it be good idea to shrink gc free zone here? I meen something like this:


            #if HXCPP_TELEMETRY
            var stack:String = hxt.unwind_stack();
            hxt.start_timing (".render");
            #end
            nme_render_stage(nmeHandle);
            #if HXCPP_TELEMETRY
            hxt.end_timing (".render");
            hxt.rewind_stack (stack);
            #end
            nme_set_render_gc_free(true); //moved down
            Gc.enterGCFreeZone(); //moved down
            nmeCollectionLock.release();
            Gc.exitGCFreeZone();
            nme_set_render_gc_free(false);
hughsando commented 3 years ago

Ah yes, that is a bit unfortunate. It should be an unusual (but not unheard of) for the fonts to get recreated. I think the best approach would be to re-attach to the GC during the getBytes call from inside the NME dll. This would allow good operation most of the time.

Font.cpp has an AutoGCUnblocking object commented out. I think this was because I was waiting for 4.1 release. Putting this back in may solve the problem.

nulld commented 3 years ago

Thanks again! Seem it fixed my problem https://github.com/haxenme/nme/pull/684