1. Calling dll function causes program to end

What would cause a euphoria program to just die with no explanation whenever i try to call a certain function in a dll file? The function is supposed to return an error (or success), but it just ends the program. No machine exception, no error message. It just....ends.

new topic     » topic index » view message » categorize

2. Re: Calling dll function causes program to end

ryanj said...

What would cause a euphoria program to just die with no explanation whenever i try to call a certain function in a dll file? The function is supposed to return an error (or success), but it just ends the program. No machine exception, no error message. It just....ends.

Typically that would be associated with a machine-level crash or some other out-of-range memory access attempt. Which function in which DLL are you calling?

Make sure you mind your pointers (don't pass a value that should be a pointer to a value, or vice-versa). Can you provide the function signature?

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: Calling dll function causes program to end

Apparently, i needed to add a '+' to use the cdecl calling convention. Now it gives me an error instead of crashing. At least that's progress. I'm making a wrapper for portaudio. The function is Pa_OpenDefaultStream(). I seem to be calling it correctly now, but the function is returning an error code. I need to find out what error that is...

new topic     » goto parent     » topic index » view message » categorize

4. Re: Calling dll function causes program to end

I got it to open a stream and start the stream, but it calls the callback function (to stream the audio buffer) exactly 1 time, then dies with no error.

new topic     » goto parent     » topic index » view message » categorize

5. Re: Calling dll function causes program to end

Ah, i forgot i also had to do this:

callbackaddr = call_back({'+', streamCallback})

Now it runs. I still don't hear audio, though. Another interesting thing i discovered: if i call task_yield() while the audio stream is running, it dies with no error. I'm curious what task_yield() does that would cause problems with a callback.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Calling dll function causes program to end

ryanj said...

Now it runs. I still don't hear audio, though. Another interesting thing i discovered: if i call task_yield() while the audio stream is running, it dies with no error. I'm curious what task_yield() does that would cause problems with a callback.

I believe task_yield() moves the internal stack pointer, which is probably affecting a threaded asynchronous call to your callback function. Matt or Jim can probably shed more light on this. It sound obvious when I say it, but it's been my experience that multitasking is generally not thread-safe. And the thread safety of PortAudio is currently unspecified, with the note that "calls to open and close streams are definitely not thread safe on any platform."

-Greg

new topic     » goto parent     » topic index » view message » categorize

7. Re: Calling dll function causes program to end

I've had this problem once in a while on Linux where some socket operations would activate a kernel bug, killing the process. I think that was mostly in the 2.6 kernels, though. Haven't seen it in a long time.

new topic     » goto parent     » topic index » view message » categorize

8. Re: Calling dll function causes program to end

ryanj said...

Ah, i forgot i also had to do this:

callbackaddr = call_back({'+', streamCallback})

Now it runs. I still don't hear audio, though. Another interesting thing i discovered: if i call task_yield() while the audio stream is running, it dies with no error. I'm curious what task_yield() does that would cause problems with a callback.

Most DLLs aside from the ones provided by Windows will probably use cdecl. That's generally the default for C compilers.

On Windows, tasks are implemented using Fibers, which are cooperative multitasking constructs for Windows. They're actually quite analogous to euphoria's tasks. Odd things can happen if you mix these with treads. If we eventually get true multi-threading, I think we'll have to switch to using threads for euphoria tasks (which we already do on non-Windows platforms).

We no longer to any low level manipulation of the stack (which was really only done for translated code). Current operating systems thwart this sort of thing as it looks like stack smashing or something similarly malicious.

Matt

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu