Errors in IUP scripts are causing my application to shut down

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Errors in IUP scripts are causing my application to shut down

Simon Orde-2

Hi – My Visual C++ app uses Lua to run scripts.  Following various upgrades, I now have a problem with scripts that use IUP.  If an error occurs in an IUP script, what usually happens is that instead of displaying a sensible error message, it shuts down my application somehow.  This is a new problem that has only started happening since I upgraded  my application from Visual Studio 2010 to 2017.  When I upgraded my compiler, I also upgraded from Lua 5.1 to Lua 5.3.5 and from IUP 3.9 to IUP 3.26.  That required a number of changes to get everything working.  I’ve manged to overcome most issues, but this one is still unresolved.

 

The following simplified script illustrates the problem:

 

text = iup.multiline{expand = "YES"}

dlg = iup.dialog{text; title="Simple Dialog",size="QUARTERxQUARTER"}

dlg:show()

 

t = {}

t.force_error()

 

iup.MainLoop()

 

The script puts up an IUP dialog and then forces an error with the line "t.force_error()".  The “iup.MainLoop()” line is never reached (for interest, if I move the “t.force_error()” line before the dlg:show” line, or after the “iup.MainLoop()” line, the error does not force my application to shut down).

 

I run Lua scripts from my C++ application using the Lua API.   For historical reasons, I use run-time dynamic linking.  I use ::LoadLibrary to load lua53.dll and iuplua53.dll, and make numerous ::GetProcAddress calls to get the addresses of the various functions I need to call.  I had to make some changes to cope with incompatibilities between Lua 5.3 and Lua 5.1, but it mostly seems to be working now.  I call the function iuplua_open in the iuplua53.dll before running the script.  I then run the script by calling lua_load followed by lua_pcallk ( I call the latter with parameters (L, 0, LUA_MULTRET, 0, 0, NULL)).  When the script hits the error, I get an error return from lua_pcallk.  Normally, at this point I would call iuplua_close.  However, if I do that, my application exits after the function returns (the ‘ExitInstance’ method of my application object gets called).

 

I can of course test for an error return from lua_pcallk and simply not call iuplua_close if the former returns an error.  But if I do that, the IUP dialog is left on-screen.  If I click on its Close button, my application immediately closes down.

 

I tried taking out the calls to iuplua_open and iuplua_close, and adding the line “require iuplua” at the start of my script (e.g. the script above), with a suitable cpath set up (I came across some issues in the process, which I will probably post about separately, but never mind that for now).  This worked up to a point.  When the line “t.force_error()” was hit, the script ended with an error and my application stayed open.  But unfortunately so did the IUP dialog.  And if I closed it manually, my application also closed.

 

I never had this problem under the old build of my application using Lua 5.1 and IUP 3.9.  If I run the script shown above in that version, when the error is forced, the IUP dialog is immediately closed, and lua_pcall (as it then was) returns an error; but my application does not shut down. 

 

Can anyone suggest a solution?  All help much appreciated.


Simon

 

 

Reply | Threaded
Open this post in threaded view
|

Re: Errors in IUP scripts are causing my application to shut down

Antonio Scuri-2
  Hi Simon,

  I don't have a solution but a few comments.

  I wouldn't call iuplua_close for every script, if this is what you are doing. Using require is the recommended option. But notice that does not call IupClose anywhere. 

  I don't see why an error in Lua code would close an IUP dialog. If this happen before could be an error in older IupLua error management. The current IupLua error dialog allow 3 actions: Copy the error report to the clipboard, Continue with the execution (the Lua script will abort but will not close any dialogs), and Exit the application. You can replace this dialog with your own version that can close your dialogs.

Best,
Scuri

  

Em qua, 27 de mar de 2019 às 17:39, Simon Orde <[hidden email]> escreveu:

Hi – My Visual C++ app uses Lua to run scripts.  Following various upgrades, I now have a problem with scripts that use IUP.  If an error occurs in an IUP script, what usually happens is that instead of displaying a sensible error message, it shuts down my application somehow.  This is a new problem that has only started happening since I upgraded  my application from Visual Studio 2010 to 2017.  When I upgraded my compiler, I also upgraded from Lua 5.1 to Lua 5.3.5 and from IUP 3.9 to IUP 3.26.  That required a number of changes to get everything working.  I’ve manged to overcome most issues, but this one is still unresolved.

 

The following simplified script illustrates the problem:

 

text = iup.multiline{expand = "YES"}

dlg = iup.dialog{text; title="Simple Dialog",size="QUARTERxQUARTER"}

dlg:show()

 

t = {}

t.force_error()

 

iup.MainLoop()

 

The script puts up an IUP dialog and then forces an error with the line "t.force_error()".  The “iup.MainLoop()” line is never reached (for interest, if I move the “t.force_error()” line before the dlg:show” line, or after the “iup.MainLoop()” line, the error does not force my application to shut down).

 

I run Lua scripts from my C++ application using the Lua API.   For historical reasons, I use run-time dynamic linking.  I use ::LoadLibrary to load lua53.dll and iuplua53.dll, and make numerous ::GetProcAddress calls to get the addresses of the various functions I need to call.  I had to make some changes to cope with incompatibilities between Lua 5.3 and Lua 5.1, but it mostly seems to be working now.  I call the function iuplua_open in the iuplua53.dll before running the script.  I then run the script by calling lua_load followed by lua_pcallk ( I call the latter with parameters (L, 0, LUA_MULTRET, 0, 0, NULL)).  When the script hits the error, I get an error return from lua_pcallk.  Normally, at this point I would call iuplua_close.  However, if I do that, my application exits after the function returns (the ‘ExitInstance’ method of my application object gets called).

 

I can of course test for an error return from lua_pcallk and simply not call iuplua_close if the former returns an error.  But if I do that, the IUP dialog is left on-screen.  If I click on its Close button, my application immediately closes down.

 

I tried taking out the calls to iuplua_open and iuplua_close, and adding the line “require iuplua” at the start of my script (e.g. the script above), with a suitable cpath set up (I came across some issues in the process, which I will probably post about separately, but never mind that for now).  This worked up to a point.  When the line “t.force_error()” was hit, the script ended with an error and my application stayed open.  But unfortunately so did the IUP dialog.  And if I closed it manually, my application also closed.

 

I never had this problem under the old build of my application using Lua 5.1 and IUP 3.9.  If I run the script shown above in that version, when the error is forced, the IUP dialog is immediately closed, and lua_pcall (as it then was) returns an error; but my application does not shut down. 

 

Can anyone suggest a solution?  All help much appreciated.


Simon

 

 

Reply | Threaded
Open this post in threaded view
|

RE: Errors in IUP scripts are causing my application to shut down

Simon Orde-2

OK thanks.  I’ve taken your advice and no longer auto-open IUP, so henceforth scripts that use IUP will have to use a require statement.  This doesn’t solve all problems.  It’s still the case that closing an IUP dialog following an error is likely to close the application, as far as I can see.  But at least it only happens if there’s an error; and this way users at least get to see the error message.

 

Simon

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Antonio Scuri
Sent: 28 March 2019 1:38 PM
To: Lua mailing list
Subject: Re: Errors in IUP scripts are causing my application to shut down

 

  Hi Simon,

 

  I don't have a solution but a few comments.

 

  I wouldn't call iuplua_close for every script, if this is what you are doing. Using require is the recommended option. But notice that does not call IupClose anywhere. 

 

  I don't see why an error in Lua code would close an IUP dialog. If this happen before could be an error in older IupLua error management. The current IupLua error dialog allow 3 actions: Copy the error report to the clipboard, Continue with the execution (the Lua script will abort but will not close any dialogs), and Exit the application. You can replace this dialog with your own version that can close your dialogs.

 

Best,

Scuri

 

  

 

Em qua, 27 de mar de 2019 às 17:39, Simon Orde <[hidden email]> escreveu:

Hi – My Visual C++ app uses Lua to run scripts.  Following various upgrades, I now have a problem with scripts that use IUP.  If an error occurs in an IUP script, what usually happens is that instead of displaying a sensible error message, it shuts down my application somehow.  This is a new problem that has only started happening since I upgraded  my application from Visual Studio 2010 to 2017.  When I upgraded my compiler, I also upgraded from Lua 5.1 to Lua 5.3.5 and from IUP 3.9 to IUP 3.26.  That required a number of changes to get everything working.  I’ve manged to overcome most issues, but this one is still unresolved.

 

The following simplified script illustrates the problem:

 

text = iup.multiline{expand = "YES"}

dlg = iup.dialog{text; title="Simple Dialog",size="QUARTERxQUARTER"}

dlg:show()

 

t = {}

t.force_error()

 

iup.MainLoop()

 

The script puts up an IUP dialog and then forces an error with the line "t.force_error()".  The “iup.MainLoop()” line is never reached (for interest, if I move the “t.force_error()” line before the dlg:show” line, or after the “iup.MainLoop()” line, the error does not force my application to shut down).

 

I run Lua scripts from my C++ application using the Lua API.   For historical reasons, I use run-time dynamic linking.  I use ::LoadLibrary to load lua53.dll and iuplua53.dll, and make numerous ::GetProcAddress calls to get the addresses of the various functions I need to call.  I had to make some changes to cope with incompatibilities between Lua 5.3 and Lua 5.1, but it mostly seems to be working now.  I call the function iuplua_open in the iuplua53.dll before running the script.  I then run the script by calling lua_load followed by lua_pcallk ( I call the latter with parameters (L, 0, LUA_MULTRET, 0, 0, NULL)).  When the script hits the error, I get an error return from lua_pcallk.  Normally, at this point I would call iuplua_close.  However, if I do that, my application exits after the function returns (the ‘ExitInstance’ method of my application object gets called).

 

I can of course test for an error return from lua_pcallk and simply not call iuplua_close if the former returns an error.  But if I do that, the IUP dialog is left on-screen.  If I click on its Close button, my application immediately closes down.

 

I tried taking out the calls to iuplua_open and iuplua_close, and adding the line “require iuplua” at the start of my script (e.g. the script above), with a suitable cpath set up (I came across some issues in the process, which I will probably post about separately, but never mind that for now).  This worked up to a point.  When the line “t.force_error()” was hit, the script ended with an error and my application stayed open.  But unfortunately so did the IUP dialog.  And if I closed it manually, my application also closed.

 

I never had this problem under the old build of my application using Lua 5.1 and IUP 3.9.  If I run the script shown above in that version, when the error is forced, the IUP dialog is immediately closed, and lua_pcall (as it then was) returns an error; but my application does not shut down. 

 

Can anyone suggest a solution?  All help much appreciated.


Simon

 

 

Reply | Threaded
Open this post in threaded view
|

Re: Errors in IUP scripts are causing my application to shut down

Jane Taubman
In reply to this post by Antonio Scuri-2
I have been working with Simon's application and am having a problem and wondered if there is a solution which I could ask Simon to implement

When I use this code

require 'iuplua'
iup.GetText('Send me a message','Hello')
thisdoesnotexist()
if iup.Close then iup.Close() end

It fails on line 3.  This means the iup.Close() is not called and the next time I run the script the program crashes out and closes completely.

As you can see at the point the script fails no dialogue is open,  using any iup dialogue of any sort and not getting to the iup.Close command has the same affect,  but this is the simplest one.

On Thu, 28 Mar 2019 at 13:38, Antonio Scuri <[hidden email]> wrote:
  Hi Simon,

  I don't have a solution but a few comments.

  I wouldn't call iuplua_close for every script, if this is what you are doing. Using require is the recommended option. But notice that does not call IupClose anywhere. 

  I don't see why an error in Lua code would close an IUP dialog. If this happen before could be an error in older IupLua error management. The current IupLua error dialog allow 3 actions: Copy the error report to the clipboard, Continue with the execution (the Lua script will abort but will not close any dialogs), and Exit the application. You can replace this dialog with your own version that can close your dialogs.

Best,
Scuri

  

Em qua, 27 de mar de 2019 às 17:39, Simon Orde <[hidden email]> escreveu:

Hi – My Visual C++ app uses Lua to run scripts.  Following various upgrades, I now have a problem with scripts that use IUP.  If an error occurs in an IUP script, what usually happens is that instead of displaying a sensible error message, it shuts down my application somehow.  This is a new problem that has only started happening since I upgraded  my application from Visual Studio 2010 to 2017.  When I upgraded my compiler, I also upgraded from Lua 5.1 to Lua 5.3.5 and from IUP 3.9 to IUP 3.26.  That required a number of changes to get everything working.  I’ve manged to overcome most issues, but this one is still unresolved.

 

 



--
Reply | Threaded
Open this post in threaded view
|

Re: Errors in IUP scripts are causing my application to shut down

Antonio Scuri-2
  Hi,

  Usually iup.Close is called at the end of the program, not every time a script is run. 

  iup.Open is automatically called on require"iuplua", but once you did the require once I think Lua will mark iuplua as loaded and will not call its initialization function again. So the second time your script will fail because iup.Close was called.

  But if you really need to call iup.Close, then I think you should explicitly call iup.Open at the beginning of the script even calling require. 

  IUP was designed to be initialized and closed only once, although multiple times can be done. Notice that doing that every time a script is run turn your scripts slower than usual. 

Best,
Scuri


Em qui, 6 de jun de 2019 às 07:28, Jane Taubman <[hidden email]> escreveu:
I have been working with Simon's application and am having a problem and wondered if there is a solution which I could ask Simon to implement

When I use this code

require 'iuplua'
iup.GetText('Send me a message','Hello')
thisdoesnotexist()
if iup.Close then iup.Close() end

It fails on line 3.  This means the iup.Close() is not called and the next time I run the script the program crashes out and closes completely.

As you can see at the point the script fails no dialogue is open,  using any iup dialogue of any sort and not getting to the iup.Close command has the same affect,  but this is the simplest one.

On Thu, 28 Mar 2019 at 13:38, Antonio Scuri <[hidden email]> wrote:
  Hi Simon,

  I don't have a solution but a few comments.

  I wouldn't call iuplua_close for every script, if this is what you are doing. Using require is the recommended option. But notice that does not call IupClose anywhere. 

  I don't see why an error in Lua code would close an IUP dialog. If this happen before could be an error in older IupLua error management. The current IupLua error dialog allow 3 actions: Copy the error report to the clipboard, Continue with the execution (the Lua script will abort but will not close any dialogs), and Exit the application. You can replace this dialog with your own version that can close your dialogs.

Best,
Scuri

  

Em qua, 27 de mar de 2019 às 17:39, Simon Orde <[hidden email]> escreveu:

Hi – My Visual C++ app uses Lua to run scripts.  Following various upgrades, I now have a problem with scripts that use IUP.  If an error occurs in an IUP script, what usually happens is that instead of displaying a sensible error message, it shuts down my application somehow.  This is a new problem that has only started happening since I upgraded  my application from Visual Studio 2010 to 2017.  When I upgraded my compiler, I also upgraded from Lua 5.1 to Lua 5.3.5 and from IUP 3.9 to IUP 3.26.  That required a number of changes to get everything working.  I’ve manged to overcome most issues, but this one is still unresolved.

 

 



--
Reply | Threaded
Open this post in threaded view
|

Re: Errors in IUP scripts are causing my application to shut down

Jane Taubman
The problem is if I don't call iup.close the program crashes next time I run the script.

The main application does not use IUP only the lua plugins do.  I did wonder if the problem is when the Lua run time environment is closed, the iup "code" is left up if iup.close is not called and wondered if there was something which could be done when the lua virtual is closed.



On Thu, 6 Jun 2019 at 12:24, Antonio Scuri <[hidden email]> wrote:
  Hi,

  Usually iup.Close is called at the end of the program, not every time a script is run. 

  iup.Open is automatically called on require"iuplua", but once you did the require once I think Lua will mark iuplua as loaded and will not call its initialization function again. So the second time your script will fail because iup.Close was called.

  But if you really need to call iup.Close, then I think you should explicitly call iup.Open at the beginning of the script even calling require. 

  IUP was designed to be initialized and closed only once, although multiple times can be done. Notice that doing that every time a script is run turn your scripts slower than usual. 

Best,
Scuri


Em qui, 6 de jun de 2019 às 07:28, Jane Taubman <[hidden email]> escreveu:
I have been working with Simon's application and am having a problem and wondered if there is a solution which I could ask Simon to implement

When I use this code

require 'iuplua'
iup.GetText('Send me a message','Hello')
thisdoesnotexist()
if iup.Close then iup.Close() end

It fails on line 3.  This means the iup.Close() is not called and the next time I run the script the program crashes out and closes completely.

As you can see at the point the script fails no dialogue is open,  using any iup dialogue of any sort and not getting to the iup.Close command has the same affect,  but this is the simplest one.

On Thu, 28 Mar 2019 at 13:38, Antonio Scuri <[hidden email]> wrote:
  Hi Simon,

  I don't have a solution but a few comments.

  I wouldn't call iuplua_close for every script, if this is what you are doing. Using require is the recommended option. But notice that does not call IupClose anywhere. 

  I don't see why an error in Lua code would close an IUP dialog. If this happen before could be an error in older IupLua error management. The current IupLua error dialog allow 3 actions: Copy the error report to the clipboard, Continue with the execution (the Lua script will abort but will not close any dialogs), and Exit the application. You can replace this dialog with your own version that can close your dialogs.

Best,
Scuri

  

Em qua, 27 de mar de 2019 às 17:39, Simon Orde <[hidden email]> escreveu:

Hi – My Visual C++ app uses Lua to run scripts.  Following various upgrades, I now have a problem with scripts that use IUP.  If an error occurs in an IUP script, what usually happens is that instead of displaying a sensible error message, it shuts down my application somehow.  This is a new problem that has only started happening since I upgraded  my application from Visual Studio 2010 to 2017.  When I upgraded my compiler, I also upgraded from Lua 5.1 to Lua 5.3.5 and from IUP 3.9 to IUP 3.26.  That required a number of changes to get everything working.  I’ve manged to overcome most issues, but this one is still unresolved.

 

 



--


--
Reply | Threaded
Open this post in threaded view
|

Re: Errors in IUP scripts are causing my application to shut down

Antonio Scuri-2
  Yes, that's exactly what's happening. I thought the Lua context remains. 

  Considering that, there is no method (that I know of) to notify IUP that the Lua context is closed, so IUP could be closed too. 

  But in the case you never call iup.Close, a fresh Lua context would call iuplua initialization again, and iup.Open has a safeguard for being called twice so it should be ok. Don't know why it is crashing. Can you tell where it crashes? If during require"iuplua" or in iup.GetText?

Best,
Scuri


Em qui, 6 de jun de 2019 às 09:28, Jane Taubman <[hidden email]> escreveu:
The problem is if I don't call iup.close the program crashes next time I run the script.

The main application does not use IUP only the lua plugins do.  I did wonder if the problem is when the Lua run time environment is closed, the iup "code" is left up if iup.close is not called and wondered if there was something which could be done when the lua virtual is closed.



On Thu, 6 Jun 2019 at 12:24, Antonio Scuri <[hidden email]> wrote:
  Hi,

  Usually iup.Close is called at the end of the program, not every time a script is run. 

  iup.Open is automatically called on require"iuplua", but once you did the require once I think Lua will mark iuplua as loaded and will not call its initialization function again. So the second time your script will fail because iup.Close was called.

  But if you really need to call iup.Close, then I think you should explicitly call iup.Open at the beginning of the script even calling require. 

  IUP was designed to be initialized and closed only once, although multiple times can be done. Notice that doing that every time a script is run turn your scripts slower than usual. 

Best,
Scuri


Em qui, 6 de jun de 2019 às 07:28, Jane Taubman <[hidden email]> escreveu:
I have been working with Simon's application and am having a problem and wondered if there is a solution which I could ask Simon to implement

When I use this code

require 'iuplua'
iup.GetText('Send me a message','Hello')
thisdoesnotexist()
if iup.Close then iup.Close() end

It fails on line 3.  This means the iup.Close() is not called and the next time I run the script the program crashes out and closes completely.

As you can see at the point the script fails no dialogue is open,  using any iup dialogue of any sort and not getting to the iup.Close command has the same affect,  but this is the simplest one.

On Thu, 28 Mar 2019 at 13:38, Antonio Scuri <[hidden email]> wrote:
  Hi Simon,

  I don't have a solution but a few comments.

  I wouldn't call iuplua_close for every script, if this is what you are doing. Using require is the recommended option. But notice that does not call IupClose anywhere. 

  I don't see why an error in Lua code would close an IUP dialog. If this happen before could be an error in older IupLua error management. The current IupLua error dialog allow 3 actions: Copy the error report to the clipboard, Continue with the execution (the Lua script will abort but will not close any dialogs), and Exit the application. You can replace this dialog with your own version that can close your dialogs.

Best,
Scuri

  

Em qua, 27 de mar de 2019 às 17:39, Simon Orde <[hidden email]> escreveu:

Hi – My Visual C++ app uses Lua to run scripts.  Following various upgrades, I now have a problem with scripts that use IUP.  If an error occurs in an IUP script, what usually happens is that instead of displaying a sensible error message, it shuts down my application somehow.  This is a new problem that has only started happening since I upgraded  my application from Visual Studio 2010 to 2017.  When I upgraded my compiler, I also upgraded from Lua 5.1 to Lua 5.3.5 and from IUP 3.9 to IUP 3.26.  That required a number of changes to get everything working.  I’ve manged to overcome most issues, but this one is still unresolved.

 

 



--


--
Reply | Threaded
Open this post in threaded view
|

Re: Errors in IUP scripts are causing my application to shut down

Jane Taubman
When you run it the second time.  The dialog appears and then after a few seconds it and the application which is hosting it both close.

--
Reply | Threaded
Open this post in threaded view
|

Re: Errors in IUP scripts are causing my application to shut down

Antonio Scuri-2
  Sorry I don't know what's going on. It seems to be garbage stored at IUP side when the Lua context is destroyed but the IUP internal context is not. But I checked what's stored from Lua and it seems to be refresh when iuplua is initialized again.

  So, if iup.Close is called, the scripts work ok? The problem does not occurs, right?

  The maybe you could force a iup.Close on a Lua error. Because Lua errors are trapped by iuplua, if the application does not overwrite that behavior.

Best,
Scuri


Em qui, 6 de jun de 2019 às 11:06, Jane Taubman <[hidden email]> escreveu:
When you run it the second time.  The dialog appears and then after a few seconds it and the application which is hosting it both close.

--
Reply | Threaded
Open this post in threaded view
|

Re: Errors in IUP scripts are causing my application to shut down

Jane Taubman
Thanks for your help.   Simon has added a lua line call when closing the VM of

If iup and iup.Close then iup.Close()

which means if iup has been required it's closed.  This seems to be working.


On Thu, 6 Jun 2019 at 21:39, Antonio Scuri <[hidden email]> wrote:
  Sorry I don't know what's going on. It seems to be garbage stored at IUP side when the Lua context is destroyed but the IUP internal context is not. But I checked what's stored from Lua and it seems to be refresh when iuplua is initialized again.

  So, if iup.Close is called, the scripts work ok? The problem does not occurs, right?

  The maybe you could force a iup.Close on a Lua error. Because Lua errors are trapped by iuplua, if the application does not overwrite that behavior.

Best,
Scuri


Em qui, 6 de jun de 2019 às 11:06, Jane Taubman <[hidden email]> escreveu:
When you run it the second time.  The dialog appears and then after a few seconds it and the application which is hosting it both close.

--


--