Run-Time Check Failure followed by Access violation

Are you developing an External using the LiveCode Externals SDK?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Run-Time Check Failure followed by Access violation

Post by Janschenkel » Fri Mar 27, 2009 5:45 pm

I'm writing my first external, on Windows, using Visual C++ 2008 Express with the aid of ExternalsEnvironmentV3. Just started debugging the work I've done so far, using the green triangle 'Start Debugging' button in VS.
One function call (to check if everything has been initialized or not) works just fine, but when I next call the initialization function, I first get:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
and then:
First-chance exception at 0x00000000 in Revolution.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x00000000 in Revolution.exe: 0xC0000005: Access violation reading location 0x00000000.
and then I basically have no choice but to kill Revolution.

Any pointers from more experienced external developers on how I can tackle this?

TIA,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Post by mwieder » Fri Mar 27, 2009 7:09 pm

Well, there's not a whole lot to go on there. From the looks of things you're dealing with a null pointer, and the fact that the stack pointer is messed up sounds like

A: you haven't declared the initialization function using the proper calling convention or
B: the engine's cleanup routine has freed a pointer to something in your code, probably the return string.

Either of those sound like possibilities?

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Post by Janschenkel » Fri Mar 27, 2009 7:36 pm

Thanks for taking a stab at this. Having just re-ran the test after sprinkling the external code with breakpoints, and stepping through the code, I noticed that:
1) the ESP error actually happens three times, twice inside the external and then once more upon return from the external.
2) everything still seems to work correctly inside the external, so I must be messing things up in there somehow, in such a way that Revolution goes nuts.
3) the return value is a simple strdup("") like in the other examples, so I don't think that's the culprit.

A little more background information: I'm dynamically loading another .DLL, and then declare some function pointers based on the return value of GetProcAddress - and the debug session showed that the first two ESP errors appear whenever I'm calling these two function pointers.
No idea if it's relevant, but I created a "C++ with exceptions" style of external.

I am confident it's something stupid that I'm doing - the code is assembled from various example sources, so the odds are good that I've put it together incorrectly - my expertise is in Revolution, Progress ABL and Java, definitely not in C/C++

TIA,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Post by mwieder » Fri Mar 27, 2009 9:14 pm

I'm dynamically loading another .DLL, and then declare some function pointers based on the return value of GetProcAddress
That can get pretty dangerous if memory gets moved around. Are you locking the memory locations? Is there some reason you can't just call the functions in the other dll rather than hardwiring pointers to them?

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Post by Janschenkel » Fri Mar 27, 2009 9:54 pm

Luckily, I only need those two function pointers during the initialization faze - the rest of the time I have the object those create, and call onto that object's methods. At any rate, I figured it out by taking another look around the web for more example code calling into that DLL.
So no more Run-Time Check Failures :-)

However, I am now getting other memory problems, so it looks like I'll need to take another look at how I put together my return values. It never seizes to amaze me how many *'s I have to or _not_ type in C - and it's 10PM now anyway, so I'll call it a day.

The ExternalsEnvironment that Mark Waddingham posted in his newsletter articles helps a lot for the setup. I do wish there were more rev external sample sources available to learn from, though...

Thanks for nudging me in the right direction. Indubitably, I'll be back with more questions in the near future.

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

SparkOut
Posts: 2857
Joined: Sun Sep 23, 2007 4:58 pm

Re: Run-Time Check Failure followed by Access violation

Post by SparkOut » Sat Mar 28, 2009 1:54 am

Janschenkel wrote:with the aid of ExternalsEnvironmentV3.
I've only got v2 from the articles. Can you advise the source of v3?
Thanks.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Post by mwieder » Sat Mar 28, 2009 6:32 am

Yeah - I didn't know about v3 either, but I just adjusted the url and grabbed it.

Post Reply

Return to “Building Externals”