objectbox-swift: Crash on ObjectBox initialization: Duplicate index ID 1 found for property EntityD.group
Issue Basics
App crashes when we initialize ObjectBox
- ObjectBox version (are using the latest version?): 0.5.0
- Reproducibility: occurs always
Reproducing the bug
Description
I’m initializing the BoxStore on app start during the initialization of the Swinject graph.
Code
extension Store {
static func createStore() throws -> Store {
let directory = try FileManager.default.url(
for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true)
return try Store(directoryPath: directory.path)
}
}
DBUtils
class DBUtils {
static var sharedInstance = DBUtils()
var store : Store!
init() {
store = try! Store.createStore()
store.register(entity: EntityA.self)
store.register(entity: EntityB.self)
store.register(entity: EntityC.self)
store.register(entity: EntityD.self)
}
}
Swinject code
container.register(Store.self) { _ in
DBUtils.sharedInstance.store }.inObjectScope(.container)
Entities
class EntityA: Entity {
var id : Id<EntityA> = 0
var name = ""
var played = 0
var won = 0
var group: ToOne<EntityC> = nil
required init() {
}
}
class EntityB: Entity {
var id : Id<EntityB> = 0
var name = ""
var matches : ToMany<EntityD, EntityB> = nil
required init() {
}
}
class EntityC: Entity {
var id : Id<EntityC> = 0
var name = ""
var entitiesA: ToMany<EntityA, EntityC> = nil
required init() {
}
}
class EntityD: Entity {
var id : Id<EntityD> = 0
var day : Int?
var date: Date?
var isPlayed : Bool = false
var localPoints: Int?
var foreignPoints: Int?
var group: ToOne<EntityC> = nil
var fase: ToOne<EntityB> = nil
var local: ToOne<EntityA> = nil
var foreign: ToOne<EntityA> = nil
required init() {
}
}
Stacktrace
Terminating app due to uncaught exception 'Unhandled ObjectBox C++ Exception', reason: 'Duplicate index ID 1 found for property EntityD.group
*** First throw call stack:
(
0 CoreFoundation 0x0000000106cbb1e6 __exceptionPreprocess + 294
1 libobjc.A.dylib 0x000000010586b031 objc_exception_throw + 48
2 ObjectBox 0x0000000104d13086 _Z24runWithExceptionHandlingPU15__autoreleasingP7NSErrorU13block_pointerFvvE + 2401
3 ObjectBox 0x0000000104d1384a _Z24runWithExceptionHandlingPU15__autoreleasingP7NSErrorU13block_pointerFvvE + 4389
4 MyApp 0x00000001046c9140 $SSo8OBXStoreC17MyAppE13directoryPath16maxDbSizeInKByte8fileMode0G7ReadersABSS_s6UInt64Vs6UInt32VAKtKcfc + 256
5 MyApp 0x00000001046c8fe7 $SSo8OBXStoreC17MyAppE13directoryPath16maxDbSizeInKByte8fileMode0G7ReadersABSS_s6UInt64Vs6UInt32VAKtKcfC + 87
6 MyApp 0x00000001046ca76b $SSo8OBXStoreC17MyAppE11createStoreAByKFZ + 411
7 MyApp 0x00000001046ca09d $S17MyApp7DBUtilsCACycfc + 173
8 MyApp 0x00000001046c9d10 $S17MyApp7DBUtilsCACycfC + 64
9 MyApp 0x00000001046c9cbc globalinit_33_9CDCCD402CC08FC843F21FD87EBB68C2_func0 + 28
10 libdispatch.dylib 0x000000010b12c848 _dispatch_client_callout + 8
11 libdispatch.dylib 0x000000010b12ddc0 dispatch_once_f + 285
12 libswiftCore.dylib 0x00000001063feea9 swift_once + 25
13 MyApp 0x00000001046c9d94 $S17MyApp7DBUtilsC14sharedInstanceACvau + 36
14 MyApp 0x00000001046c1b7f $S17MyApp16ContainerFactoryCACycfcSo8OBXStoreC8Swinject8Resolver_pcfU_ + 15
15 MyApp 0x00000001046c1c70 $S8Swinject8Resolver_pSo8OBXStoreCIegno_AaB_pADIegnr_TR + 16
16 MyApp 0x00000001046c1cd1 $S8Swinject8Resolver_pSo8OBXStoreCIegno_AaB_pADIegnr_TRTA + 17
17 Swinject 0x0000000105084e1f $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTR + 63
18 Swinject 0x0000000105084ebd $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTRTA + 29
19 Swinject 0x0000000105089428 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_ + 120
20 Swinject 0x000000010508944c $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_TA + 12
21 Swinject 0x000000010508668b $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTR + 75
22 Swinject 0x000000010508854d $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTRTA + 61
23 Swinject 0x00000001050866d4 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTR + 52
24 Swinject 0x00000001050885d2 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTRTA + 50
25 Swinject 0x0000000105086c8e $S8Swinject9ContainerC7resolve33_B0248D9BB4D17AC900F06660C57FEB11LL5entry7invokerxSgAA20ServiceEntryProtocol_p_ypq_XEtr0_lF + 1454
26 Swinject 0x0000000105085eaf $S8Swinject9ContainerC8_resolve4name6option7invokerxSgSSSg_AA16ServiceKeyOption_pSgypypq_XEctr0_lF + 959
27 Swinject 0x0000000105089389 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlF + 201
28 Swinject 0x00000001050892b8 $S8Swinject9ContainerC7resolveyxSgxmlF + 56
29 Swinject 0x0000000105089574 $S8Swinject9ContainerCAA8ResolverA2aDP7resolveyqd__Sgqd__mlFTW + 20
30 SwinjectAutoregistration 0x00000001051dbf44 $S8Swinject8ResolverP0A16AutoregistrationE7resolveqd__SgylF + 68
31 SwinjectAutoregistration 0x00000001050f88d8 $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq_ctr0_lFxAA8Resolver_pcfU_ + 232
32 SwinjectAutoregistration 0x00000001050f8ad2 $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq_ctr0_lFxAA8Resolver_pcfU_TA + 50
33 Swinject 0x0000000105084e1f $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTR + 63
34 Swinject 0x0000000105084ebd $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTRTA + 29
35 Swinject 0x0000000105089428 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_ + 120
36 Swinject 0x000000010508944c $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_TA + 12
37 Swinject 0x000000010508668b $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTR + 75
38 Swinject 0x000000010508854d $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTRTA + 61
39 Swinject 0x00000001050866d4 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTR + 52
40 Swinject 0x00000001050885d2 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTRTA + 50
41 Swinject 0x0000000105086c8e $S8Swinject9ContainerC7resolve33_B0248D9BB4D17AC900F06660C57FEB11LL5entry7invokerxSgAA20ServiceEntryProtocol_p_ypq_XEtr0_lF + 1454
42 Swinject 0x0000000105085eaf $S8Swinject9ContainerC8_resolve4name6option7invokerxSgSSSg_AA16ServiceKeyOption_pSgypypq_XEctr0_lF + 959
43 Swinject 0x0000000105089389 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlF + 201
44 Swinject 0x00000001050892b8 $S8Swinject9ContainerC7resolveyxSgxmlF + 56
45 Swinject 0x0000000105089574 $S8Swinject9ContainerCAA8ResolverA2aDP7resolveyqd__Sgqd__mlFTW + 20
46 SwinjectAutoregistration 0x00000001051dbf44 $S8Swinject8ResolverP0A16AutoregistrationE7resolveqd__SgylF + 68
47 SwinjectAutoregistration 0x00000001050f9186 $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq__q0_t_tctr1_lFxAA8Resolver_pcfU_ + 342
48 SwinjectAutoregistration 0x00000001050f9535 $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq__q0_t_tctr1_lFxAA8Resolver_pcfU_TA + 69
49 Swinject 0x0000000105084e1f $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTR + 63
50 Swinject 0x0000000105084ebd $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTRTA + 29
51 Swinject 0x0000000105089428 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_ + 120
52 Swinject 0x000000010508944c $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_TA + 12
53 Swinject 0x000000010508668b $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTR + 75
54 Swinject 0x000000010508854d $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTRTA + 61
55 Swinject 0x00000001050866d4 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTR + 52
56 Swinject 0x00000001050885d2 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTRTA + 50
57 Swinject 0x0000000105086c8e $S8Swinject9ContainerC7resolve33_B0248D9BB4D17AC900F06660C57FEB11LL5entry7invokerxSgAA20ServiceEntryProtocol_p_ypq_XEtr0_lF + 1454
58 Swinject 0x0000000105085eaf $S8Swinject9ContainerC8_resolve4name6option7invokerxSgSSSg_AA16ServiceKeyOption_pSgypypq_XEctr0_lF + 959
59 Swinject 0x0000000105089389 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlF + 201
60 Swinject 0x00000001050892b8 $S8Swinject9ContainerC7resolveyxSgxmlF + 56
61 Swinject 0x0000000105089574 $S8Swinject9ContainerCAA8ResolverA2aDP7resolveyqd__Sgqd__mlFTW + 20
62 SwinjectAutoregistration 0x00000001051dbf44 $S8Swinject8ResolverP0A16AutoregistrationE7resolveqd__SgylF + 68
63 SwinjectAutoregistration 0x0000000105100ff0 $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq__q0_q1_q2_q3_t_tctr4_lFxAA8Resolver_pcfU_ + 688
64 SwinjectAutoregistration 0x000000010510192c $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq__q0_q1_q2_q3_t_tctr4_lFxAA8Resolver_pcfU_TA + 108
65 Swinject 0x0000000105084e1f $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTR + 63
66 Swinject 0x0000000105084ebd $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTRTA + 29
67 Swinject 0x0000000105089428 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_ + 120
68 Swinject 0x000000010508944c $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_TA + 12
69 Swinject 0x000000010508668b $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTR + 75
70 Swinject 0x000000010508854d $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTRTA + 61
71 Swinject 0x00000001050866d4 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTR + 52
72 Swinject 0x00000001050885d2 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTRTA + 50
73 Swinject 0x0000000105086c8e $S8Swinject9ContainerC7resolve33_B0248D9BB4D17AC900F06660C57FEB11LL5entry7invokerxSgAA20ServiceEntryProtocol_p_ypq_XEtr0_lF + 1454
74 Swinject 0x0000000105085eaf $S8Swinject9ContainerC8_resolve4name6option7invokerxSgSSSg_AA16ServiceKeyOption_pSgypypq_XEctr0_lF + 959
75 Swinject 0x0000000105089389 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlF + 201
76 Swinject 0x00000001050892b8 $S8Swinject9ContainerC7resolveyxSgxmlF + 56
77 Swinject 0x0000000105089574 $S8Swinject9ContainerCAA8ResolverA2aDP7resolveyqd__Sgqd__mlFTW + 20
78 SwinjectAutoregistration 0x00000001051dbf44 $S8Swinject8ResolverP0A16AutoregistrationE7resolveqd__SgylF + 68
79 SwinjectAutoregistration 0x00000001050fa9d4 $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq__q0_q1_t_tctr2_lFxAA8Resolver_pcfU_ + 452
80 SwinjectAutoregistration 0x00000001050faf43 $S8Swinject9ContainerC0A16AutoregistrationE12autoregister_4name11initializerAA12ServiceEntryCyxGxm_SSSgxq__q0_q1_t_tctr2_lFxAA8Resolver_pcfU_TA + 83
81 Swinject 0x0000000105084e1f $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTR + 63
82 Swinject 0x0000000105084ebd $S8Swinject8Resolver_pxIegnr_AaB_pypIegnr_lTRTA + 29
83 Swinject 0x0000000105089428 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_ + 120
84 Swinject 0x000000010508944c $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlFypypAA8Resolver_pXEcfU_TA + 12
85 Swinject 0x000000010508668b $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTR + 75
86 Swinject 0x000000010508854d $Sq_ypIgnr_ypIegyr_q_ypIegnr_ypIeggr_r0_lTRTA + 61
87 Swinject 0x00000001050866d4 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTR + 52
88 Swinject 0x00000001050885d2 $Sq_ypIegnr_ypIggr_q_ypIegnr_ypIegnr_r0_lTRTA + 50
89 Swinject 0x0000000105086c8e $S8Swinject9ContainerC7resolve33_B0248D9BB4D17AC900F06660C57FEB11LL5entry7invokerxSgAA20ServiceEntryProtocol_p_ypq_XEtr0_lF + 1454
90 Swinject 0x0000000105085eaf $S8Swinject9ContainerC8_resolve4name6option7invokerxSgSSSg_AA16ServiceKeyOption_pSgypypq_XEctr0_lF + 959
91 Swinject 0x0000000105089389 $S8Swinject9ContainerC7resolve_4namexSgxm_SSSgtlF + 201
92 Swinject 0x00000001050892b8 $S8Swinject9ContainerC7resolveyxSgxmlF + 56
93 MyApp 0x00000001046a081d $S17MyApp11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0l6LaunchK3KeyaypGSgtFyycfU_ + 189
94 MyApp 0x00000001046a0941 $S17MyApp11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0l6LaunchK3KeyaypGSgtFyycfU_TA + 17
95 MyApp 0x00000001046a09ad $SIeg_IeyB_TR + 45
96 libdispatch.dylib 0x000000010b12c848 _dispatch_client_callout + 8
97 libdispatch.dylib 0x000000010b132b35 _dispatch_continuation_pop + 967
98 libdispatch.dylib 0x000000010b13dfa6 _dispatch_source_invoke + 1635
99 libdispatch.dylib 0x000000010b137b9e _dispatch_main_queue_callback_4CF + 1255
100 CoreFoundation 0x0000000106c7dc99 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
101 CoreFoundation 0x0000000106c41ea6 __CFRunLoopRun + 2342
102 CoreFoundation 0x0000000106c4130b CFRunLoopRunSpecific + 635
103 GraphicsServices 0x000000010d633a73 GSEventRunModal + 62
104 UIKit 0x00000001080f20b7 UIApplicationMain + 159
105 MyApp 0x00000001046a2057 main + 71
106 libdyld.dylib 0x000000010b1a9955 start + 1
)
I also tried without Swinject with the same results. I got the same classes and relationships on Android and it works.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 20 (10 by maintainers)
I have tested new version 0.5.4, and it seems it’s working fine, even with optionals properties. Tested on the emulator and on my iPhone 6s, and both tests are working flawless.
@Zpecter I just posted 0.5.4 which should fix two more issues that might have affected you. I’ve also added my test code to the example app. Should this release not work for you, we should probably compare what else is different from the example code in your case, to narrow down what is preventing it from working.
That it wouldn’t work with non-optional properties is unusual, though. What (simulated?) device are you building for/running on?
@Zpecter Thank you for all the patience and help tracking this one down! Feel free to let us know what you think of the alpha, and we’re here for any questions you may have. 🙂
Ah, to fix that, remove the
Store.register(entity:)calls for the entities from your app’s source code (in the example app they were inServicesresp. the app delegate), they are no longer necessary (the code generator now registers them for you).@Zpecter Have you tried updating to ObjectBox Swift 0.5.2? There was a possible issue with device deployment we fixed there. If it doesn’t help, is there any message or backtrace for the crash that you could provide?
Also, I assume you have a
print()in your actual code in thecatchblock and there’s no error coming back fromput()? I presumeMatchisEntityD?Happy to hear that! Keep us updated how it goes. We still have to go a long way…
Yes, now it works. Thank you very much. I have been expecting for a long time to use ObjectBox with Swift, that’s why I found the repo before it was released.
@Zpecter Please verify, that an update to 0.5.1 fixes the issue. Thank you!