Thanks for your reply Marc,<div><br><div>The reference to David's interface is very helpful. It works perfectly, and I think I can get to the root of the problem with a little digging.</div><div><br></div><div>  -Patrick</div>
<div><br><div class="gmail_quote">On Wed, Feb 15, 2012 at 6:38 PM, Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca">feeley@iro.umontreal.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
On 2012-02-15, at 9:17 PM, Patrick Li wrote:<br>
<br>
> Hi,<br>
><br>
> I am trying to get Gambit playing well with SDL, and am running into some strange problems when trying to set up the scheme environment.<br>
><br>
> This is the main() function that starts up a SDL window:<br>
><br>
> int main(int argc, char *argv[])<br>
> {<br>
>   /* //SETUP */<br>
>   ___setup_params_struct setup_params;<br>
>   ___setup_params_reset (&setup_params);<br>
>   setup_params.version = ___VERSION;<br>
>   setup_params.linker  = SCHEME_LIBRARY_LINKER;<br>
>   ___setup (&setup_params);<br>
><br>
>   x = 0;<br>
>   run_stuff(); //Starts a simple SDL animation<br>
><br>
>   /* //CLEANUP */<br>
>   ___cleanup ();<br>
> }<br>
><br>
> Currently everything is still in C, so there are *no* calls to any scheme functions yet.<br>
<br>
</div>That's not necessarily the case.  When ___setup() is called, your Scheme program will be run and it might contain Scheme calls (in your previous example you were calling println for instance).  Usually this "execution" of your Scheme program takes care of the initializations your program requires.  After ___setup() returns, but before you call ___cleanup(), you can call Scheme functions declared using c-define in your Scheme code.<br>

<div class="im"><br>
><br>
> I found that the animation runs for about 3 seconds before the whole program hangs. If I comment out __setup(&setup_params), then the program executes normally.<br>
><br>
> Are there some subtleties when setting up the Gambit environment that I have to watch out for? Is Gambit spawning another thread and causing some deadlock problems? I am fairly certain that SDL is single-threaded, and the whole animation runs in an infinite loop.<br>

><br>
<br>
</div>The Gambit runtime is also single threaded (it does not create any OS threads, except on Windows to simulate interval timers, but that's not relevant here).<br>
<br>
The problem could be an interference between the OS resources used by SDL and those used by the Gambit runtime, in particular the Gambit runtime sets up some signal handlers, for example to implement the heartbeat interrupt.  Perhaps the SDL library is doing the same?<br>

<br>
I know that David St-Hilaire wrote an interface to SDL which is on the Gambit Dumping Grounds (the space invaders demo).  Maybe you should check that out to see how he did it?<br>
<span class="HOEnZb"><font color="#888888"><br>
Marc<br>
<br>
</font></span></blockquote></div><br></div></div>