lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


  Ok. Thanks.

  Since it is not crashing while you call IUP, and you are using Visual C++
6, so it does look like a RTL memory problem.

  I made a few tests with that code you sent:

test.exe, lua5.1.dll and iuplua51.dll (all built with vc8 depending on
MSVCR80.DLL) -> ok
test.exe, lua5.1.dll and iuplua51.dll (exe built with vc6 depending on
MSVCRT.DLL, dlls built with vc8 depending on MSVCR80.DLL) -> still ok
test.exe, lua5.1.dll and iuplua51.dll (exe built with vc6 static RTL, dlls
still built with vc8 depending on MSVCR80.DLL) -> crash

  Maybe your project configuration must have to be adjusted.

  The standard in Lua for Windows is vc8 depending on MSVCR80.DLL, so some
DLLs may work some don't. I think IUP are that case that don't. 

  You may try using the DLLs for vc6 depending on MSVCRT.DLL. There are
pre-compiled binaries for download in IUP web site.

Best Regards,
Antonio Scuri

> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-
> bounces@bazar2.conectiva.com.br] On Behalf Of "J.Jørgen von Bargen"
> Sent: domingo, 14 de março de 2010 08:01
> To: lua@bazar2.conectiva.com.br
> Subject: Re: exception when calling lua with iup
> 
> Am 12.03.2010 16:21, schrieb Antonio Scuri:
> > Are you using IUP from LfW? That would be IUP 2. Can you try the same
> using the IUP 3 DLLs?
> >
> Hi!
> I just downloaded LuaForWindows_v5.1.4-33, extracted iuplua51.dll and
> iupdll to my testdirectory (i dont want to spoil my
> LuaForWindows_v5.1.4-30 installation yet),
> changed package.cpath to point to my local folder and...
> ... the same crash. (Well not really the same, Crt now manages to show
> the error message before the exception, so it's a bit better, but I'll
> call it a crash anyway):
> 
> ---------------------------
> Microsoft Visual C++ Debug Library
> ---------------------------
> Debug Assertion Failed!
> 
> Program: D:\MYPROJECTS\LuaDialog2\LuaDialog\Debug\LuaDialog.exe
> File: dbgheap.c
> Line: 1044
> 
> Expression: _CrtIsValidHeapPointer(pUserData)
> 
> For information on how your program can cause an assertion
> failure, see the Visual C++ documentation on asserts.
> 
> (Press Retry to debug the application)
> ---------------------------
> Abbrechen   Wiederholen   Ignorieren
> ---------------------------
> 
> So the problems remain the same...
> 
> Regards
> 
> > Thanks,
> > scuri
> >
> >
> >> -----Original Message-----
> >> From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-
> >> bounces@bazar2.conectiva.com.br] On Behalf Of "J.Jørgen von Bargen"
> >> Sent: sexta-feira, 12 de março de 2010 03:17
> >> To: lua@bazar2.conectiva.com.br
> >> Subject: exception when calling lua with iup
> >>
> >> Hi folks!
> >>
> >> This error originaly occurs in a big application, but to get a focus
> on
> >> in, I reproduced it in a small environment.
> >> Im using VisualStudio (VisualC++ 6.0). I created a standard dialog
> >> application with a text field and a button to call lua with the
> text.
> >> This is the relevant code:
> >>
> >> void CLuaDialogDlg::OnDo()
> >> {
> >>       lua_State *L = lua_open();  /* create state */
> >>       if (L == NULL)
> >>       {
> >>           MessageBox("cannot create state: not enough memory");
> >>           return;
> >>       }
> >>       luaL_openlibs(L);
> >>       lua_register(L,"print",print);
> >>
> >>       CString code;
> >>       GetDlgItemText(IDC_LUACODE,code);
> >>       int status=luaL_dostring(L,code);
> >>
> >>       if (status&&  !lua_isnil(L, -1))
> >>       {
> >>           const char *msg = lua_tostring(L, -1);
> >>           if (msg == NULL) msg = "(error object is not a string)";
> >>           MessageBox(msg);
> >>           lua_pop(L, 1);
> >>       }
> >>       lua_close(L);
> >> }
> >>
> >> This works fine for a lot of lua scripts. After fiddling the
> >> package.cpath and package.path (by adding a package.cpath="... lot
> of
> >> entries..." to the script) to point to my LuaForWindows installation
> I
> >> can also use lfs and other libs with no problems.
> >>
> >> The trouble begins, when I try to use iuplua. The following code
> >>
> >> require"iuplua"
> >> iup.Alarm('TITLE','TEXT','OK')
> >>
> >> shows the alarm, but then get a "unhandled exception" inside the
> >> lua_close. Interesting, even a
> >>
> >> require"iuplua"
> >>
> >> with no further code causes the crash.
> >>
> >>
> >> The stacktrack shows up like this:
> >>
> >> 00db26a0()
> >> USER32! 7e381923()
> >> USER32! 7e37b317()
> >> USER32! 7e3778d0()
> >> NTDLL! 7c91e473()
> >> USER32! 7e369402()
> >> USER32! 7e377611()
> >> USER32! 7e3749c4()
> >> USER32! 7e38a956()
> >> USER32! 7e38a2bc()
> >> USER32! 7e3b63fd()
> >> USER32! 7e3b64a2()
> >> USER32! 7e3a0877()
> >> USER32! 7e3a082f()
> >> __crtMessageBoxA(const char * 0x0012b198, const char * 0x004d5bfc
> >> `string', unsigned int 73746) line 65
> >> CrtMessageWindow(int 2, const char * 0x004d5198 `string', const char
> *
> >> 0x0012c2cc, const char * 0x00000000, const char * 0x0012e2f0) line
> 520
> >> +
> >> 22 bytes
> >> _CrtDbgReport(int 2, const char * 0x004d5198 `string', int 1044,
> const
> >> char * 0x00000000, const char * 0x004d52b4 `string') line 419 + 76
> >> bytes
> >> _free_dbg_lk(void * 0x00e41858, int 1) line 1044 + 40 bytes
> >> _free_dbg(void * 0x00e41858, int 1) line 1001 + 13 bytes
> >> free(void * 0x00e41858) line 956 + 11 bytes
> >> l_alloc(void * 0x00000000, void * 0x00e41858, unsigned int 32,
> unsigned
> >> int 0) line 631 + 9 bytes
> >> luaM_realloc_(lua_State * 0x009a4d08, void * 0x00e41858, unsigned
> int
> >> 32, unsigned int 0) line 79 + 27 bytes
> >> luaH_free(lua_State * 0x009a4d08, Table * 0x00cb4560) line 376 + 39
> >> bytes
> >> freeobj(lua_State * 0x009a4d08, GCObject * 0x00cb4560) line 383 + 13
> >> bytes
> >> sweeplist(lua_State * 0x009a4d08, GCObject * * 0x009a4d9c, unsigned
> int
> >> 4294967289) line 424 + 13 bytes
> >> luaC_freeall(lua_State * 0x009a4d08) line 487 + 18 bytes
> >> close_state(lua_State * 0x009a4d08) line 108 + 9 bytes
> >> lua_close(lua_State * 0x009a4d08) line 212 + 9 bytes
> >> CLuaDialogDlg::OnDo() line 224 + 9 bytes
> >>
> >> After setting a breakpoint into CrtMessageWindow I could fetch the
> >> message
> >>
> >> "Debug Assertion Failed!
> >>
> >> Program: D:\MYPROJECTS\LuaDialog2\LuaDialog\Debug\LuaDialog.exe
> >> File: dbgheap.c
> >> Line: 1044
> >>
> >> Expression: _CrtIsValidHeapPointer(pUserData)
> >>
> >> So this looks to me, as if free is called with an invalid pointer,
> but
> >> there must be more memory corrupted, because the error message newer
> >> gets displayed.
> >>
> >> Im using lua-5.1.4 from the source-tar statically linked, every
> other
> >> lib or dll is loaded via package from LuaForWindows_v5.1.4-30
> >> Can you give me any helpfull hints, how to fix (or avoid) the
> problem?
> >>
> >> Regards
> >>
> >
> >
/* Sample loading IUP dynamically */

#include <stdlib.h>
#include <stdio.h>

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

char* test = "require'iuplua'\niup.Alarm('TITLE','TEXT','OK')";

int main(int argc, char **argv)
{
  lua_State *L = lua_open();  /* create state */
  int status;
  
  if (L == NULL)
  {
      printf("cannot create state: not enough memory");
      return;
  }
  luaL_openlibs(L);
//  lua_register(L,"print",print);

  status=luaL_dostring(L, test);

  if (status&&  !lua_isnil(L, -1))
  {
      const char *msg = lua_tostring(L, -1);
      if (msg == NULL) msg = "(error object is not a string)";
      printf(msg);
      lua_pop(L, 1);
  }
  lua_close(L);
}