99
1010public class ComponentHooks <T > {
1111 private final Linker linker ;
12- private final Arena arena ;
12+ private final Flecs world ;
1313 private final Component <T > component ;
1414 private IterHookCallback <T > onAddCallback ;
1515 private IterHookCallback <T > onSetCallback ;
@@ -24,7 +24,7 @@ public class ComponentHooks<T> {
2424
2525 public ComponentHooks (Flecs world , Component <T > component ) {
2626 this .linker = Linker .nativeLinker ();
27- this .arena = world . arena () ;
27+ this .world = world ;
2828 this .component = component ;
2929 }
3030
@@ -108,7 +108,7 @@ private MemorySegment createIterHookStub(IterHookCallback<T> callback) {
108108
109109 MethodHandle target = MethodHandles .lookup ().bind (this , "invokeIterHook" , MethodType .methodType (void .class , IterHookCallback .class , MemorySegment .class )).bindTo (callback );
110110
111- return this .linker .upcallStub (target , descriptor , this .arena );
111+ return this .linker .upcallStub (target , descriptor , this .world . arena () );
112112 } catch (Exception e ) {
113113 throw new RuntimeException ("Failed to create iter hook stub" , e );
114114 }
@@ -123,7 +123,7 @@ private MemorySegment createReplaceHookStub(ReplaceHookCallback<T> callback) {
123123
124124 MethodHandle target = MethodHandles .lookup ().bind (this , "invokeReplaceHook" , MethodType .methodType (void .class , ReplaceHookCallback .class , MemorySegment .class )).bindTo (callback );
125125
126- return this .linker .upcallStub (target , descriptor , this .arena );
126+ return this .linker .upcallStub (target , descriptor , this .world . arena () );
127127 } catch (Exception e ) {
128128 throw new RuntimeException ("Failed to create replace hook stub" , e );
129129 }
@@ -138,7 +138,7 @@ private MemorySegment createXtorStub(XtorCallback<T> callback) {
138138
139139 MethodHandle target = MethodHandles .lookup ().bind (this , "invokeXtorHook" , MethodType .methodType (void .class , XtorCallback .class , MemorySegment .class , int .class , MemorySegment .class )).bindTo (callback );
140140
141- return this .linker .upcallStub (target , descriptor , this .arena );
141+ return this .linker .upcallStub (target , descriptor , this .world . arena () );
142142 } catch (Exception e ) {
143143 throw new RuntimeException ("Failed to create xtor hook stub" , e );
144144 }
@@ -153,7 +153,7 @@ private MemorySegment createCopyMoveStub(CopyMoveCallback<T> callback) {
153153
154154 MethodHandle target = MethodHandles .lookup ().bind (this , "invokeCopyMoveHook" , MethodType .methodType (void .class , CopyMoveCallback .class , MemorySegment .class , MemorySegment .class , int .class , MemorySegment .class )).bindTo (callback );
155155
156- return this .linker .upcallStub (target , descriptor , this .arena );
156+ return this .linker .upcallStub (target , descriptor , this .world . arena () );
157157 } catch (Exception e ) {
158158 throw new RuntimeException ("Failed to create copy/move hook stub" , e );
159159 }
@@ -263,7 +263,7 @@ private void writeComponentArray(MemorySegment ptr, T[] components, int count) {
263263 for (int i = 0 ; i < count ; i ++) {
264264 if (components [i ] != null ) {
265265 MemorySegment componentSegment = buffer .asSlice (i * size , size );
266- this .component .write (componentSegment , components [i ]);
266+ this .component .write (componentSegment , components [i ], this . world );
267267 }
268268 }
269269 }
0 commit comments