Strange crash (native extensions?) (SOLVED)

Hello, I’ve got a crash very often and it seems it appears quite randomly. What could it be?

Process: dmengine [8070]
Path: /Applications/Defold-macosx.cocoa.x86_64/*/dmengine
Identifier: dmengine
Version: ???
Code Type: X86 (Native)
Parent Process: Defold [800]
Responsible: dmengine [8070]
User ID: 501

Date/Time: 2017-06-02 12:06:38.674 +0100
OS Version: Mac OS X 10.11.6 (15G1510)
Report Version: 11
Anonymous UUID: 5AEA5F9C-C165-9462-3821-0070EA562BC3

Time Awake Since Boot: 11000 seconds

System Integrity Protection: disabled

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000f0c4616c
Exception Note: EXC_CORPSE_NOTIFY

VM Regions Near 0xf0c4616c:
Stack 00000000bfffd000-00000000c0000000 [ 12K] rw-/rwx SM=COW
–>
Submap 00000000ffff0000-00000000ffff1000 [ 4K] r–/r-- SM=PRV process-only VM submap

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 dmengine 0x002be5b4 lua_gettop + 4
1 dmengine 0x002944eb dmScript::UpdateExtensions(dmScript::Context*) + 139
2 dmengine 0x00183e5d dmEngine::Step(dmEngine::Engine*) + 1245
3 dmengine 0x001e64f5 dmGraphics::RunApplicationLoop(void*, void ()(void), int ()(void)) + 37
4 dmengine 0x00184cae dmEngine::InitRun(dmEngineService::EngineService*, int, char**, void ()(dmEngine::Engine, void*), void ()(dmEngine::Engine, void*), void*) + 190
5 dmengine 0x00184b24 dmEngine::Launch(int, char**, void ()(dmEngine::Engine, void*), void ()(dmEngine::Engine, void*), void*) + 100
6 dmengine 0x00184e2e engine_main(int, char**) + 158
7 dmengine 0x00002035 start + 53

1 Like

It’s really difficult to say. Are you creating your own extension?

Since the top function in the call stack is lua_gettop, I’d look into stack related issues first.

One of the first things I’d look into is if you can see if any of your Lua functions doesn’t push the right number of lua objects on the stack, or return the wrong number of objects on the stack.

Are you doing any callbacks?

You can perhaps comment out (or stop using) the functions one after another, to try to pinpoint which function is the culprit.

1 Like

Ok, thank you, I’ll try these things advised by you.

Sometimes I got a slightly different crash:

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY

Application Specific Information:
abort() called
*** error for object 0x93a3a0: pointer being freed was not allocated

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x9e417572 __pthread_kill + 10
1 libsystem_pthread.dylib 0x9554f654 pthread_kill + 101
2 libsystem_c.dylib 0x95bbfc38 abort + 156
3 libsystem_malloc.dylib 0x966f1292 free + 433
4 dmengine 0x000044c5 UpdateTimerExtension(dmExtension::Params*) + 453
5 dmengine 0x002944eb dmScript::UpdateExtensions(dmScript::Context*) + 139
6 dmengine 0x00183e5d dmEngine::Step(dmEngine::Engine*) + 1245
7 dmengine 0x001e64f5 dmGraphics::RunApplicationLoop(void*, void ()(void), int ()(void)) + 37
8 dmengine 0x00184cae dmEngine::InitRun(dmEngineService::EngineService*, int, char**, void ()(dmEngine::Engine, void*), void ()(dmEngine::Engine, void*), void*) + 190
9 dmengine 0x00184b24 dmEngine::Launch(int, char**, void ()(dmEngine::Engine, void*), void ()(dmEngine::Engine, void*), void*) + 100
10 dmengine 0x00184e2e engine_main(int, char**) + 158
11 dmengine 0x00002035 start + 53

Ah, I see. There’s probably a bug in my timer extension. What kind of code are you running in your timer callbacks? Could it be that the timer callback is creating or removing timers?

I see now that I’m iterating over all created timers and for each timer I invoke it’s callback if the timer has finished and after invoking the callback I remove it. I suspect that the loop will get messed up if new timers are created while iterating. I’ll make some tests.

2 Likes

I’m unable to reproduce the crash. Could you please let me know if you are creating or canceling timers in your timer callbacks?

Yes, probably it is as you say, there are many timers here in this code. Unfortunately it’s something written by somebody else, basically a third-party lua module.

Yes, it’s written by me :slight_smile: I’d like to figure out what’s wrong so I can fix it. I’ll try to create a more complex test scenario to try and reproduce the problem. Any additional information that you can provide would help! Is this happening on mobile or desktop?

1 Like

:slight_smile: I meant I’m using third parties lua code. There may be some bugs (or something that Defold doesn’t like) inside here. It seems it happens randomly and at the moment I have tested it only on the Editor (MacOS version). I could try it on a real device.

The stack trace indicates that the crash happens inside my native extension. I’ll try to reproduce it.

I’ve update the timer extension so that it handles that timers cancel other timers in their callbacks. Please use Project->Fetch Libraries to get the latest version of the extension and let me know if the problem has been solved. Thanks!

5 Likes

Yea, it works better now, thank you very much!

4 Likes