[plt-scheme] Peculiar pause with MzScheme

From: join at krakendev.com (join at krakendev.com)
Date: Mon Jul 12 10:28:59 EDT 2004

Hello all,
   I'm finally getting a handle on integrating MzScheme with my app,
though now I've run into a rather peculiar issue.

I'm writing some extensions right now, which basically look like this:
// define function pointer structure
typedef int(*iFPi)(int);
typedef int(*iFPv)(void);
typedef struct {
    iFPi    Main;
    iFPv    GetDelta;
} CSharedFuncs;

static CSharedFuncs *gEngine;

Scheme_Object *scheme_initialize(Scheme_Env *env)
{
  gEngine = 0;
  return scheme_reload(env);
}

Scheme_Object *render(int argc, Scheme_Object **argv)
{
    gEngine->Main(gEngine->GetDelta());
    return scheme_void;
}

Scheme_Object *get_global(int argc, Scheme_Object **argv)
{
    return (Scheme_Object*)&gEngine;
}

Scheme_Object *scheme_reload(Scheme_Env *env)
{
    /* When the extension is loaded, return a Scheme string: */
    scheme_add_global("render",
                        scheme_make_prim_w_arity(render,
                                            "render",
                                                // min and max arguments
                                                0, 0),
                env);
    scheme_add_global("get-global",
                scheme_make_prim_w_arity(get_global,
                            "get-global",
                                                // min and max arguments
                            0, 0),
                env);
    return scheme_void;
}

Now, in my main, I init the window and api things, then use the following
to init scheme and its static structure:
    Scheme_Env *e = scheme_basic_env();

    char test[128];
    sprintf(test,"(load-extension \"hello.dll\")");
    Scheme_Object *v = scheme_eval_string(test, e);

    sprintf(test,"(get-global)");
    v = scheme_eval_string(test, e);

    CSharedFuncs** r = (CSharedFuncs **)v;
    *r = new CSharedFuncs;
    (*r)->Main = Display;
    (*r)->GetDelta = ReturnDelta;

    Scheme_Object* q;

and in the primary loop:
    sprintf(test,"(render)");
    q = scheme_eval_string(test, e);

which seems to work fine as it operates as expected. However, for some
reason there are intermittent pauses (for roughly 6-10s) during which the
call to scheme_eval_string() in the primary loop blocks. What is causing
this? The only thing I can guess is gc though honestly that's a shot in
the dark (especially as I'm not really allocating anything...).

I know that it has to be something with this call as I've tested the
functions pretty thoroughly before I started tying them into this
extension (and have replaced the above problem functions with there direct
counterparts which are smooth as silk).

The example windows binaries (requiring dx9) can be found at:
(With scheme calls)
http://www.krakendev.com/forums/MzDX.zip
(With direct calls)
http://www.krakendev.com/forums/DXwoScript.zip

The difference between the two is exactly this:
    Display(delta);
OR:
    sprintf(test,"(render)");
    q = scheme_eval_string(test, e);


*Update*
Ok. I've done some searching and found this:
GC_enable_incremental();
which seems to be what I want.
I've included gc.h and set include paths "~\PLT
src\src\mzscheme\gc\include" and "~\PLT src\include" and it is compiling
fine.

However, when it is run with the call to (render) it immediately crashes
with an
unhandled exception (writing violation).

When I use the direct calls this same error occurs after I cleanup memory
allocated in the driver as I return((int)msg.wParam); in my winmain
function.

Is this somehow set up wrong?

Thanks in advance for any insight,
and I'll continue to search the docs for a better understanding. Cheers.


Posted on the users mailing list.