<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br>Not sure what you mean?&nbsp;</div><div id="AppleMailSignature">The positional arg $0 is never used outside the closure whatever the version...</div><div id="AppleMailSignature">No attempt is ever made to save and reuse after withMemoryRebound?</div><div id="AppleMailSignature">Why would I use a separate function?</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">Are we looking at the same code? đź¤“</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">rĂ©digĂ© sur mon iPhone.</div><div><br>On Sep 3, 2016, at 4:16 PM, Jacob Bandes-Storch &lt;<a href="mailto:jtbandes@gmail.com">jtbandes@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">Yikes! That's unsafe! When using withMemoryRebound, I think you're only supposed to use the argument $0 inside the block. Saving it and using it after withMemoryRebound is probably undefined behavior. But maybe you can move your ".pointee = x" into a separate function rather than using a closure?<div class="gmail_extra">
<br><div class="gmail_quote">On Sat, Sep 3, 2016 at 1:12 PM, Patrice Kouame via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Finally Success!&nbsp; I’m seeing my pretty little 3D twirling Metal Renderer cubes again… Here’s how<div><br></div><div>Snippet of old &nbsp;sample code which no longer compiles in Xcode 8 beta 6 with stricter Swift3 unsafe type casting restrictions&nbsp;</div><div>(in MetalView.swift from&nbsp;<span style="color:rgb(120,73,42);font-family:Menlo;font-size:11px"># Adopting Metal II: Designing and Implementing a Real-World Metal Renderer)</span></div><div><br></div><div><span class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span><span style="white-space:pre-wrap">        </span>let shadowPtr = UnsafeMutablePointer&lt;<wbr>ShadowPass&gt;(<wbr>constantBufferForFrame.<wbr>contents())</span></div></span><span class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span><span style="white-space:pre-wrap">        </span>let mainPtr = UnsafeMutablePointer&lt;MainPass&gt;<wbr>(shadowPtr.advanced(by: 1))</span></div></span><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span><span style="white-space:pre-wrap">        </span>mainPtr.pointee = mainPassFrameData</span></div><span class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span><span style="white-space:pre-wrap">        </span>var ptr = UnsafeMutablePointer&lt;<wbr>ObjectData&gt;(mainPtr.advanced(<wbr>by: 1))</span></div><div><span><br></span></div></span><div>My conversion attempt that crashes Swift 3 Xcode 8 beta 6 (see &nbsp;RADAR&nbsp;<span style="color:rgb(102,102,102);font-family:Helvetica,Arial,sans-serif;font-size:15px;white-space:nowrap">28150447 -&nbsp;Swift 3 UnsafeMutablePointer conversion crashes the compiler and IDE)</span></div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="color:#ba2da2">let</span><span> shadowPtr = constantBufferForFrame.</span><span style="color:#3e1e81">content<wbr>s</span><span>().</span><span style="color:#3e1e81">bindMemory</span><span>(to: </span><span style="color:#4f8187">ShadowPass</span><span>.</span><span style="color:#ba2da2">self</span><span>, capacity: MemoryLayout&lt;</span><span style="color:#4f8187">shadowPassData&gt;.<wbr>size</span><span>)</span></div><span class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#ba2da2">let</span><span> mainPtr : </span><span style="color:#703daa">UnsafeMutablePointer</span><span>&lt;</span><span style="color:#4f8187">MainPass</span><span>&gt; = shadowPtr.</span><span style="color:#3e1e81">advanced</span><span>(by: </span><span style="color:#272ad8">1</span><span>).</span><span style="color:#3e1e81">withMemoryRebound</span><span>(to: </span><span style="color:#4f8187">MainPass</span><span>.</span><span style="color:#ba2da2">self</span><span>, capacity: </span><span style="color:#272ad8">1</span><span>) {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><span style="white-space:pre-wrap">                </span>$0.pointee = mainPassFrameData</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><span style="white-space:pre-wrap">        </span>}</span></div></span><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="color:rgb(186,45,162)">var</span><span> ptr : </span><span style="color:rgb(112,61,170)">UnsafeMutablePointer</span><span>&lt;</span><span style="color:rgb(79,129,135)">ObjectDat<wbr>a</span><span>&gt; = mainPtr.</span><span style="color:rgb(62,30,129)">advanced</span><span>(by: </span><span style="color:rgb(39,42,216)">1</span><span>).</span><span style="color:rgb(62,30,129)">withMemoryRebound</span><span>(to: </span><span style="color:rgb(79,129,135)">ObjectData</span><span>.</span><span style="color:rgb(186,45,162)">self</span><span>, capacity:&nbsp;</span><span><span>MemoryLayout&lt;</span><span style="color:rgb(79,129,135)">&nbsp;<wbr>ObjectData&nbsp;&gt;.size</span>) {$0}</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>Latest conversion that make Xcode and Swift 3 smile again...</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><span class=""><div style="margin:0px;line-height:normal"><span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="color:#ba2da2">let</span><span> shadowPtr = constantBufferForFrame.</span><span style="color:#3e1e81">content<wbr>s</span><span>().</span><span style="color:#3e1e81">bindMemory</span><span>(to: </span><span style="color:#4f8187">ShadowPass</span><span>.</span><span style="color:#ba2da2">self</span><span>, capacity: </span><span style="color:#4f8187">shadowPassData</span><span>.</span><span style="color:#703daa">count</span><span>)</span></div></span><span class=""><div style="margin:0px;line-height:normal"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#ba2da2">let</span><span> mainPtr : </span><span style="color:#703daa">UnsafeMutablePointer</span><span>&lt;</span><span style="color:#4f8187">MainPass</span><span>&gt; = shadowPtr.</span><span style="color:#3e1e81">advanced</span><span>(by: </span><span style="color:#272ad8">1</span><span>).</span><span style="color:#3e1e81">withMemoryRebound</span><span>(to: </span><span style="color:#4f8187">MainPass</span><span>.</span><span style="color:#ba2da2">self</span><span>, capacity: </span><span style="color:#272ad8">1</span><span>) {$0}</span></div></span><div style="margin:0px;line-height:normal"><span>&nbsp; &nbsp; &nbsp; &nbsp; mainPtr.</span><span style="color:#703daa">pointee</span><span> = </span><span style="color:#4f8187">mainPassFrameData</span></div><div style="margin:0px;line-height:normal"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#ba2da2">var</span><span> ptr : </span><span style="color:#703daa">UnsafeMutablePointer</span><span>&lt;</span><span style="color:#4f8187">ObjectDat<wbr>a</span><span>&gt; = mainPtr.</span><span style="color:#3e1e81">advanced</span><span>(by: </span><span style="color:#272ad8">1</span><span>).</span><span style="color:#3e1e81">withMemoryRebound</span><span>(to: </span><span style="color:#4f8187">ObjectData</span><span>.</span><span style="color:#ba2da2">self</span><span>, capacity: </span><span style="color:#4f8187">objectsToRender</span><span>) {$0}</span></div><div><span><br></span></div><div><span>Yes… Xcode/Swift3 SIL generation definitely did NOT like my "$0.pointee = mainPassFrameData" statement.&nbsp;</span></div><div><span>Apparently, reassigning the pointee within the closure makes Swift gag out of disgust. Sorry ;-(</span></div><div><span>That’s what I get&nbsp;</span>for trying to be fancy…</div><div>And fixed my â€ścapacity” issues thanks to some previous posters.</div><div><span><br></span></div><div><span>Hope this helps anyone trying to get the Metal projects to compile again.</span></div><div><span><br></span></div><div><span>At least I got a Radar out of this ;-) Compilers should never burn and crash out like this...</span></div><div><span><br></span></div><div><span>Regards to all, Patrice</span></div></span></div><div><div class="h5"><div><span><br></span></div><div><br><div><blockquote type="cite"><div>On Sep 3, 2016, at 1:22 PM, Patrice Kouame via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word">Gerard-&nbsp;<div><br></div><div>Excellent!&nbsp; Looking forward to seeing your fix (hoping you get your book back soon ;-) )</div><div><br></div><div>I think Xcode/Swift gags on the last ptr advance to objectData.&nbsp; I recently tried another variant using withUnsafeMutablePointer like this:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;var ptr : UnsafeMutablePointer&lt;<wbr>ObjectData&gt;&nbsp; = withUnsafeMutablePointer(to: &amp;mainPtr) {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $0.withMemoryRebound(to: ObjectData.self, capacity: objectsToRender) {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $0.pointee = renderables[0].objectData</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span><br></span></div><div>..but still crashes with no hints.</div><div><br></div><div>My bug report also mentions that the Xcode migration/conversion tool is incomplete. &nbsp;</div><div>It handles the â€śsimpler" UnsafeMutableRawPointer&lt;X&gt; to UnsafeMutablePonter&lt;Y&gt; with bindMemory cases correctly (one still has to mind the capacity value though)</div><div>In all fairness, migrating/converting automagically in these cases is always a little bit tricky - the proposed Xcode fixes should always be reviewed by a human...</div><div><br></div><div>Patrice</div><div><br></div><div><blockquote type="cite"><div>On Sep 3, 2016, at 1:05 PM, Gerard Iglesias via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div><br><div><div dir="auto"><div><div style="direction:inherit">Ok</div><div style="direction:inherit"><br></div><div style="direction:inherit">For the record I succeeded this transformation phase last week</div><div style="direction:inherit"><br></div><div style="direction:inherit">I remember the tedious stuff to advance pointer from one struct to the other kind of struct... it worked</div><div style="direction:inherit"><br></div><div style="direction:inherit">But I don't have my MacBook with me, only the phone, the six :)</div><br>GĂ©rard&nbsp;</div><div><br>Le 3 sept. 2016 Ă  18:22, Patrice Kouame &lt;<a href="mailto:pkouame@me.com" target="_blank">pkouame@me.com</a>&gt; a Ă©crit&nbsp;:<br><br></div><blockquote type="cite"><div>Indeed. There is a difference between stride and size, but I interpreted capacity incorrectly for my purposes.&nbsp; It should indicate the number of &lt;T&gt; elements (not their size - right?) and the snippets below should work.<div><br><div>Still, compiler crashes and Xcode IDE is left in inconsistent state.&nbsp; So I filed this Apple radar against Developer Tools.</div><div><br></div><div><h2 style="outline:none;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;min-height:26px;padding:1px 0px 5px;margin:0px;font-size:15px;font-family:Helvetica,Arial,sans-serif"><span style="outline:none;color:rgb(102,102,102);font-weight:normal;padding:0px 10px 0px 0px"><span style="white-space:pre-wrap">        </span>28150447 -&nbsp;Swift 3 UnsafeMutablePointer conversion crashes the compiler and IDE</span></h2><div>Should I file a Swift bug too? Would that be helpful?</div><div><br></div><div>Regards, Patrice</div><div><br></div><div><blockquote type="cite"><div>On Sep 3, 2016, at 11:39 AM, Gerard Iglesias via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div><br><div><div dir="auto"><div><div style="direction:inherit">Hello,</div><div style="direction:inherit"><br></div><div style="direction:inherit">I think that it is more secure to use stride in place of size, sometimes it is not the same value.</div><div style="direction:inherit"><br></div><div style="direction:inherit">I use it in my own use of raw bindings&nbsp;</div><div style="direction:inherit"><br></div><div style="direction:inherit">Regards</div><br>GĂ©rard&nbsp;</div><div><br>Le 3 sept. 2016 Ă  10:03, Patrice Kouame via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; a Ă©crit&nbsp;:<br><br></div><blockquote type="cite"><div><div>Hi Jacob -&nbsp;</div><div><br></div>I think you’re right. â€ścapacity” should be the count of type T elements in my buffer.&nbsp; So in my case that line should read<div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="color:#ba2da2">let</span><span> shadowPtr = constantBufferForFrame.<wbr>contents().bindMemory(to: ShadowPass.</span><span style="color:#ba2da2">self</span><span>, capacity: shadowPassData.count)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><br></span></div><div><span>The&nbsp;withMemoryRebound&nbsp;calls need similar adjustments. The pointer to MainPass is actually a single structure to it should be safe to do this</span></div><div><span><br></span></div><div><span><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="color:#ba2da2">let</span><span> mainPtr : </span><span style="color:#703daa">UnsafeMutablePointer</span><span>&lt;</span><span style="color:#703daa">MainPass</span><span>&gt; = shadowPtr.advanced(by: </span><span style="color:#272ad8">1</span><span>).withMemoryRebound(to: MainPass.</span><span style="color:#ba2da2">self</span><span>, capacity: </span><span style="color:#272ad8">1</span><span>) {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $0.pointee = mainPassFrameData</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><br></span></div><div><span>Whereas the unsafe pointer to &lt;ObjectData&gt; is actually a buffer of renderable objects, so this should work:</span></div><div><span><br></span></div><div><span><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="color:#ba2da2">var</span><span> ptr : </span><span style="color:#703daa">UnsafeMutablePointer</span><span>&lt;</span><span style="color:#703daa">ObjectDat<wbr>a</span><span>&gt; = mainPtr.advanced(by: </span><span style="color:#272ad8">1</span><span>).withMemoryRebound(to: ObjectData.</span><span style="color:#ba2da2">self</span><span>, capacity: objectsToRender) {_ in</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><span style="white-space:pre-wrap">        </span>}</span></div><div style="margin:0px;line-height:normal"><br></div></span></div></span></div><div><span>There are surely ways to refactor and simplify this, but I’m trying to retain as much of the original sample code approach as possible.</span></div><div><span><br></span></div><div><span>However, the compiler still segs badly.&nbsp;</span></div><div><span>Xcode also borks an internal error often.&nbsp;</span>Only cleaning or restarting the project can clear up that state.</div><div>Compilers (or Playgrounds for that matter) should never crash, and I’m not sure where to file this bug : Swift or Apple radar against Xcode or both? I now Xcode 8 is beta but…it’s been doing this for quite a while now...</div><div><br></div><div>In both our â€śclose to the metal” (no pun intended) cases, it seems like a lot of churning for very little gain. Don’t you think? The easier, but â€śunsafe” casting afforded previously did the trick with the normal caveats.</div><div>Don’t get me wrong, I love Swift and â€śget" all the neat type safety features. Guess we can’t have our cake and eat it too, especially when interfacing with â€śunsafe” C APIs.</div><div><br></div><div>Anyway, back to rtfm â€¦ maybe some of the Swift Gods can chime in? &nbsp;;-)&nbsp;</div><div><br></div><div>I must be doing something stupid...Patrice</div><div><br></div><div><blockquote type="cite"><div>On Sep 3, 2016, at 2:32 AM, Jacob Bandes-Storch &lt;<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>&gt; wrote:</div><br><div><div dir="ltr">Hi Patrice,<div>I don't have a solution for you, but I just wanted to point out what I think may be an error with your use of the new UnsafeRawPointer APIs:</div><div><br></div><div><span style="font-family:menlo;font-size:11px">constantBufferForFrame.content<wbr>s().bindMemory(to: ShadowPass.</span><span style="font-family:menlo;font-size:11px;color:rgb(186,45,162)">self</span><span style="font-family:menlo;font-size:11px">, capacity: MemoryLayout&lt;</span><span style="font-family:menlo;font-size:11px;color:rgb(112,61,170)">ShadowPass</span><span style="font-family:menlo;font-size:11px">&gt;.size)</span><br></div><div><br></div><div>I believe the `capacity` should actually be the number of ShadowPass elements in the buffer, not the size of each element. Using `bindMemory(to: ShadowPass.self` already implies that MemoryLayout&lt;ShadowPass&gt;.size is the size of each element.</div><div><br></div><div>More info at <a href="https://developer.apple.com/reference/swift/unsaferawpointer/2428875-bindmemory" target="_blank">https://developer.apple.com/<wbr>reference/swift/<wbr>unsaferawpointer/2428875-<wbr>bindmemory</a><br></div><div><br></div><div>I just updated a small Metal project of mine to Swift 3. I ran into some compiler (playground) crashes, but it does seem to work most of the time. Although I only have 1 buffer :-) <a href="https://github.com/jtbandes/Metalbrot.playground" target="_blank">https://github.com/jtbandes/<wbr>Metalbrot.playground</a></div><div class="gmail_extra"><br clear="all"><div><div><div dir="ltr"><div>Jacob<br></div></div></div></div>
<br><div class="gmail_quote">On Fri, Sep 2, 2016 at 11:00 AM, Patrice Kouame via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><span>Hi all -&nbsp;</span><div><span><br></span></div><div><span>I’m converting Apple’s Swift Sample "</span><span>Adopting Metal II: Designing and Implementing a Real-World Metal Renderer” in Xcode 8 beta6 to the latest UnsafeMutablePointer API for&nbsp;untyped memory access. &nbsp;</span><div><span>Changes are necessary in MetalView.swift (Apple hasn’t updated their sample code for the latest beta yet…)&nbsp;</span></div><div><span>The Swift Compiler crashes (Segmentation Fault:&nbsp;</span>11) on the attempt:<div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span>// Grab a pointer to the constant buffer's data store</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span>// Since we are using Swift, it is easier to cast the pointer to the ShadowPass type to fill the constant buffer</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span>// We need to make a copy of these so the block captures the correct data</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span>//&nbsp; &nbsp; &nbsp; let shadowPtr = UnsafeMutablePointer&lt;ShadowPas<wbr>s&gt;(constantBufferForFrame.cont<wbr>ents())</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(186,45,162)">let</span><span> shadowPtr = constantBufferForFrame.content<wbr>s().bindMemory(to: ShadowPass.</span><span style="color:rgb(186,45,162)">self</span><span>, capacity: MemoryLayout&lt;</span><span style="color:rgb(112,61,170)">ShadowPass</span><span>&gt;.size)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; shadowPtr.pointee = shadowPassData[</span><span style="color:rgb(39,42,216)">0</span><span>]</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span>//More Swift specific stuff - advance pointer and cast to MainPass</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span>//&nbsp; &nbsp; &nbsp; let mainPtr = UnsafeMutablePointer&lt;MainPass&gt;<wbr>(shadowPtr.advanced(by: 1))</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span>//&nbsp; &nbsp; &nbsp; mainPtr.pointee = mainPassFrameData</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(186,45,162)">let</span><span> mainPtr : </span><span style="color:rgb(112,61,170)">UnsafeMutablePointer</span><span>&lt;</span><span style="color:rgb(112,61,170)">MainPass</span><span>&gt;<wbr>&nbsp; = shadowPtr.advanced(by: </span><span style="color:rgb(39,42,216)">1</span><span>).withMemoryRebound(to: MainPass.</span><span style="color:rgb(186,45,162)">self</span><span>, capacity: MemoryLayout&lt;</span><span style="color:rgb(112,61,170)">MainPass</span><span>&gt;.size) {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $0.pointee = mainPassFrameData</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span>//Advance and cast to ObjectData</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span>//&nbsp; &nbsp; &nbsp; var ptr = UnsafeMutablePointer&lt;ObjectDat<wbr>a&gt;(mainPtr.advanced(by: 1))</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(186,45,162)">var</span><span> ptr : </span><span style="color:rgb(112,61,170)">UnsafeMutablePointer</span><span>&lt;</span><span style="color:rgb(112,61,170)">ObjectDat<wbr>a</span><span>&gt; = mainPtr.advanced(by: </span><span style="color:rgb(39,42,216)">1</span><span>).withMemoryRebound(to: ObjectData.</span><span style="color:rgb(186,45,162)">self</span><span>, capacity: MemoryLayout&lt;</span><span style="color:rgb(112,61,170)">ObjectData</span><span>&gt;.size) {</span><span style="color:rgb(186,45,162)">_</span><span> </span><span style="color:rgb(186,45,162)">in</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(186,45,162)">let</span><span> shadowOffset = </span><span style="color:rgb(39,42,216)">0</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(186,45,162)">let</span><span> mainPassOffset = MemoryLayout&lt;</span><span style="color:rgb(112,61,170)">ShadowPass</span><span>&gt;.size + shadowOffset</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(186,45,162)">let</span><span> objectDataOffset = MemoryLayout&lt;</span><span style="color:rgb(112,61,170)">MainPass</span><span>&gt;.size + mainPassOffset</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span>// Update position of all the objects</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(186,45,162)">if</span><span> multithreadedUpdate {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DispatchQueue.concurrentPerfor<wbr>m(iterations: objectsToRender) { i </span><span style="color:rgb(186,45,162)">in</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(186,45,162)">let</span><span> thisPtr = ptr.advanced(by: i)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(186,45,162)">_</span><span> = </span><span style="color:rgb(186,45,162)">self</span><span>.renderables[i].UpdateData<wbr>(ptr, deltaTime: </span><span style="color:rgb(39,42,216)">1.0</span><span>/</span><span style="color:rgb(39,42,216)">60.0</span><span>)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(186,45,162)">else</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(186,45,162)">for</span><span> index </span><span style="color:rgb(186,45,162)">in</span><span> </span><span style="color:rgb(39,42,216)">0</span><span>..&lt;objectsToRender {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ptr = renderables[index].UpdateData(<wbr>ptr, deltaTime: </span><span style="color:rgb(39,42,216)">1.0</span><span>/</span><span style="color:rgb(39,42,216)">60.0</span><span>)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; ptr = ptr.advanced(by: objectsToRender)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(186,45,162)">_</span><span> = groundPlane!.UpdateData(ptr, deltaTime: </span><span style="color:rgb(39,42,216)">1.0</span><span>/</span><span style="color:rgb(39,42,216)">60.0</span><span>)</span></div><div><span><br></span></div><div>Any help is appreciated.&nbsp; I have the latest Xcode log handy if necessary.&nbsp; Here’s a clip of the stack trace.</div><div><br></div><div><div>0 &nbsp;swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x000000010714a99d PrintStackTraceSignalHandler(v<wbr>oid*) + 45</div><div>1 &nbsp;swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x000000010714a3e6 SignalHandler(int) + 470</div><div>2 &nbsp;libsystem_platform.dylib 0x00007fff91461bba _sigtramp + 26</div><div>3 &nbsp;libsystem_platform.dylib 000000000000000000 _sigtramp + 1857676384</div><div>4 &nbsp;swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x00000001047207b3 (anonymous namespace)::SILGenApply::visit<wbr>Expr(swift::Expr*) + 51</div><div>5 &nbsp;swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x0000000104723ace (anonymous namespace)::SILGenApply::visit<wbr>ApplyExpr(swift::ApplyExpr*) + 5182</div><div>6 &nbsp;swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x0000000104711cc1 prepareApplyExpr(swift::Loweri<wbr>ng::SILGenFunction&amp;, swift::Expr*) + 273</div><div>7 &nbsp;swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x00000001047624e7 swift::ASTVisitor&lt;(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext&gt;::<wbr>visit(swift::Expr*, swift::Lowering::SGFContext) + 103</div><div>8 &nbsp;swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x0000000104762313 swift::Lowering::SILGenFunctio<wbr>n::emitExprInto(swift::Expr*, swift::Lowering::Initializatio<wbr>n*) + 195</div><div>9 &nbsp;swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x000000010474fbc3 swift::Lowering::SILGenFunctio<wbr>n::emitPatternBinding(swift::P<wbr>atternBindingDecl*, unsigned int) + 195</div><div>10 swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x00000001047077bd swift::ASTVisitor&lt;swift::Lower<wbr>ing::SILGenFunction, void, void, void, void, void, void&gt;::visit(swift::Decl*) + 125</div><div>11 swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x00000001047c0019 swift::ASTVisitor&lt;(anonymous namespace)::StmtEmitter, void, void, void, void, void, void&gt;::visit(swift::Stmt*) + 4169</div><div>12 swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x00000001047809ba swift::Lowering::SILGenFunctio<wbr>n::emitFunction(swift::<wbr>FuncDecl*) + 314</div><div>13 swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x00000001046fd775 swift::Lowering::SILGenModule:<wbr>:emitFunction(swift::FuncDecl*<wbr>)::$_1::operator()(swift::SILF<wbr>unction*) const + 1877</div><div>14 swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x00000001046fc322 swift::Lowering::SILGenModule:<wbr>:emitFunction(swift::FuncDecl*<wbr>) + 626</div><div>15 swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x00000001047c7007 (anonymous namespace)::SILGenType::emitTy<wbr>pe() + 1271</div><div>16 swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x00000001047c6a9e swift::Lowering::SILGenModule:<wbr>:visitNominalTypeDecl(swift::N<wbr>ominalTypeDecl*) + 30</div><div>17 swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x0000000104709093 swift::Lowering::SILGenModule:<wbr>:emitSourceFile(swift::SourceF<wbr>ile*, unsigned int) + 1795</div><div>18 swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x000000010470ad4d swift::SILModule::constructSIL<wbr>(swift::ModuleDecl*, swift::SILOptions&amp;, swift::FileUnit*, llvm::Optional&lt;unsigned int&gt;, bool, bool) + 1629</div><div>19 swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x00000001045621bf performCompile(swift::Compiler<wbr>Instance&amp;, swift::CompilerInvocation&amp;, llvm::ArrayRef&lt;char const*&gt;, int&amp;, swift::FrontendObserver*) + 19487</div><div>20 swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x000000010455b2c5 swift::performFrontend(llvm::A<wbr>rrayRef&lt;char const*&gt;, char const*, void*, swift::FrontendObserver*) + 17029</div><div>21 swift &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x000000010451888d main + 8685</div><div>22 libdyld.dylib &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x00007fff91255255 start + 1</div></div><span><font color="#888888"><div><br></div><div><br></div><div>Patrice</div><div><span><br></span></div></font></span></div></div></div></div><br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-users</a><br>
<br></blockquote></div><br></div></div>
</div></blockquote></div><br></div></div></blockquote><blockquote type="cite"><div><span>______________________________<wbr>_________________</span><br><span>swift-users mailing list</span><br><span><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a></span><br></div></blockquote></div>______________________________<wbr>_________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div></div></blockquote></div>______________________________<wbr>_________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div>______________________________<wbr>_________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div></div></div></div><br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div></div>
</div></blockquote></body></html>