<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi,<div class="">As my source of inspiration and with reference to:</div><div class=""><a href="https://github.com/FlyingJester/SDL2.m/blob/master/sdl2.m" class="">https://github.com/FlyingJester/SDL2.m/blob/master/sdl2.m</a></div><div class="">around line 554….</div><div class=""></div><div class=""><table class="js-file-line-container highlight tab-size" data-tab-size="8" data-paste-markdown-skip=""><tbody class=""><tr class=""><td id="LC553" class="js-file-line blob-code-inner blob-code"><span class="pl-s"><font face="Courier" class=""> _________\/_______</font></span></td>
</tr>
<tr class="">
</tr></tbody></table><table class="js-file-line-container highlight tab-size" data-tab-size="8" data-paste-markdown-skip=""><tbody class=""><tr class=""><td id="LC554" class="js-file-line blob-code-inner blob-code"><span class="pl-s"><font face="Courier" class=""> case SDL_KEYDOWN: Event = createYesEvent(createKeyDown(e.key.keysym.sym)); break;</font></span></td>
</tr>
<tr class="">
</tr></tbody></table><table class="js-file-line-container highlight tab-size" data-tab-size="8" data-paste-markdown-skip=""><tbody class=""><tr class=""><td id="LC555" class="js-file-line blob-code-inner blob-code"><span class="pl-s"><font face="Courier" class=""> default: Event = createYesEvent(createUnknown()); break;</font></span></td>
</tr>
<tr class="">
</tr></tbody></table><table class="js-file-line-container highlight tab-size" data-tab-size="8" data-paste-markdown-skip=""><tbody class=""><tr class=""><td id="LC556" class="js-file-line blob-code-inner blob-code"><span class="pl-s"><font face="Courier" class=""> }</font></span></td>
</tr>
<tr class="">
</tr></tbody></table><span class="pl-s"><font face="Courier" class=""> }</font></span></div><div class=""><span class="pl-s"><br class=""></span></div><div class=""><span class="pl-s">I think this is what is causing my crash problem, I copied that line of code and the key definitions and when I press a key down, in my C code I display the name and in the Mercury code I display what it got back and they are most definitely not the same. I suspect that the value of e.key.keysym is sometimes out of range for the key type and causing the crash.</span></div><div class=""><span class="pl-s"><br class=""></span></div><div class=""><span class="pl-s"><div class=""><font face="Courier" class="">*** Mercury runtime: caught segmentation violation ***</font></div><div class=""><font face="Courier" class="">cause: address not mapped to object</font></div><div class=""><font face="Courier" class="">address involved: 0x0</font></div><div class=""><font face="Courier" class="">This may have been caused by a stack overflow, due to unbounded recursion.</font></div><div class=""><font face="Courier" class="">exiting from signal handler</font></div><div class=""><font face="Courier" class="">[1] 57015 segmentation fault ./main</font></div><div class=""><br class=""></div></span></div><div class=""><span class="pl-s"><br class=""></span></div><div class=""><span class="pl-s">For example, pressing the <font face="Courier" class="">`1` </font>key causes this output:</span></div><div class=""><span class="pl-s"><br class=""></span></div><div class=""><span class="pl-s"><div class=""><font face="Courier" class="">>>> SDL_KEYDOWN 49</font></div><div class=""><font face="Courier" class="">KEY-DOWN: key_g: 1</font></div><div class=""><font face="Courier" class="">>>> SDL_KEYUP 49</font></div><div class=""><font face="Courier" class="">KEY-UP: key_g: 1</font></div><div class=""><br class=""></div><div class="">key_g just happens to be the 50th value in the declaration of `key` so its plain to me that there needs to be some kind of mapping between them. I don’t know what the best way is to do that. On lines 97-102 of the linked file we have:</div><div class=""><br class=""></div><div class=""><table class="js-file-line-container highlight tab-size" data-tab-size="8" data-paste-markdown-skip=""><tbody class=""><tr class=""><td id="LC97" class="js-file-line blob-code-inner blob-code"><font face="Courier" class=""><span class="pl-k"><span class="pl-k">:-</span> pred</span> key_name<span class="pl-k">(</span>string<span class="pl-k">,</span> key<span class="pl-k">)</span><span class="pl-k">.</span></font></td>
</tr>
<tr class="">
</tr></tbody></table><table class="js-file-line-container highlight tab-size" data-tab-size="8" data-paste-markdown-skip=""><tbody class=""><tr class=""><td id="LC98" class="js-file-line blob-code-inner blob-code"><font face="Courier" class=""><span class="pl-k"><span class="pl-k">:-</span> mode</span> key_name<span class="pl-k">(</span>in<span class="pl-k">,</span> uo<span class="pl-k">)</span> <span class="pl-k">is</span> <span class="pl-c1">semidet</span><span class="pl-k">.</span></font></td>
</tr>
<tr class="">
</tr></tbody></table><table class="js-file-line-container highlight tab-size" data-tab-size="8" data-paste-markdown-skip=""><tbody class=""><tr class=""><td id="LC99" class="js-file-line blob-code-inner blob-code"><font face="Courier" class=""><span class="pl-k"><span class="pl-k">:-</span> mode</span> key_name<span class="pl-k">(</span>di<span class="pl-k">,</span> uo<span class="pl-k">)</span> <span class="pl-k">is</span> <span class="pl-c1">semidet</span><span class="pl-k">.</span></font></td>
</tr>
<tr class="">
</tr></tbody></table><table class="js-file-line-container highlight tab-size" data-tab-size="8" data-paste-markdown-skip=""><tbody class=""><tr class=""><td id="LC100" class="js-file-line blob-code-inner blob-code"><font face="Courier" class=""><span class="pl-k"><span class="pl-k">:-</span> mode</span> key_name<span class="pl-k">(</span>uo<span class="pl-k">,</span> in<span class="pl-k">)</span> <span class="pl-k">is</span> <span class="pl-c1">det</span><span class="pl-k">.</span></font></td>
</tr>
<tr class="">
</tr></tbody></table><table class="js-file-line-container highlight tab-size" data-tab-size="8" data-paste-markdown-skip=""><tbody class=""><tr class=""><td id="LC101" class="js-file-line blob-code-inner blob-code"><font face="Courier" class=""><span class="pl-k"><span class="pl-k">:-</span> mode</span> key_name<span class="pl-k">(</span>uo<span class="pl-k">,</span> di<span class="pl-k">)</span> <span class="pl-k">is</span> <span class="pl-c1">det</span><span class="pl-k">.</span></font></td>
</tr>
<tr class="">
</tr></tbody></table><font face="Courier" class=""><span class="pl-k"><span class="pl-k">:-</span> mode</span> key_name<span class="pl-k">(</span>in<span class="pl-k">,</span> in<span class="pl-k">)</span> <span class="pl-k">is</span> <span class="pl-c1">semidet</span><span class="pl-k">.</span> <span class="pl-c"><span class="pl-c">%</span><span class="pl-c"> implied.</span></span></font></div><div class=""><span class="pl-c"><span class="pl-c"><br class=""></span></span></div><div class="">I could use this code to map back from the string name and then hand that into the constructor, perhaps that’s what the intention is/was, I shall certainly try. It just seems somehow horribly inefficient but then again I guess a mapping has to happen. The only other option I was thinking about was to reflect the entire set of key definitions back into Mercury using <font face="Courier" class="">`pragma_foreign_enum`</font> and then change the key constructor to just be a an integer.</div><div class=""><br class=""></div><div class="">Any suggestions / input most welcome.</div><div class=""><br class=""></div><div class="">Thanks again,</div><div class="">Sean.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></span></div><div class=""><span class="pl-s"><br class=""></span></div><div class=""><span class="pl-s"><br class=""></span></div></body></html>