Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Bug Reports

Reply
 
Thread Tools Display Modes
Old 11-27-2023, 03:29 PM   #1
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,722
Default Third party extensions errors (Imgui) passing thru pcall

So writing some script that uses protected calls in order not to crash the main script. While it works fine with reaper API (most I've tried) ImGui errors still pass thru and crash the script.

While talking to cfillion the errors made by Imgui are called
Code:
ReaScriptError('!message')
! meaning kill it with fire

But it does not play nice with pcall (expect the main script to keep working).

Script is calling (generating) another script and calling it with pcall
Code:
local code = generated_string
local func, err = load(code , "ScriptRun", "t", script_vars)
    if func then
        local status, err2 = pcall(func)
        if err2 then
            r.ShowConsoleMsg("\nERROR LOADING SCRIPT : " .. err2)
            end
        end
    else
        r.ShowConsoleMsg("\nERROR LOADING SCRIPT : " .. err)
    end
But any Imgui error crashes everything down

Also related from back a while:
https://forum.cockos.com/showthread.php?t=177319

Last edited by Sexan; 11-27-2023 at 03:36 PM.
Sexan is offline   Reply With Quote
Old 11-27-2023, 03:37 PM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 5,038
Default

Argument validation errors of extension API functions are also not fully catchable by Lua's protected mode. To be precise: pcall/xpcall does see the error as expected. However REAPER proceeds to report the error in its popup anyway, and gfx.getchar() returns < 0.


Last edited by cfillion; 11-27-2023 at 03:57 PM.
cfillion is offline   Reply With Quote
Old 11-28-2023, 02:26 PM   #3
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 5,038
Default

It seems there are two bugs related to catching ReaScriptError from Lua's protected mode:
  1. REAPER shows its custom error modal popup anyway instead of using standard Lua error processing
  2. REAPER then stops invoking deferred callbacks unless the IDE is open
The snippet below duplicates both issues. The expected behavior is:
  • No error popup is displayed
  • 'success!' is printed to the ReaScript console
Code:
local did_error = false

local function loop()
  if did_error then
    reaper.ShowConsoleMsg('success!\n')
    return
  end
  
  pcall(function() reaper.ReaScriptError('foo') end)
  -- pcall(function() reaper.SNM_GetIntConfigVar()    end) -- argument count validation error
  -- pcall(function() reaper.ImGui_Image_GetSize(nil) end) -- ReaScriptError('!message') from extension

  did_error = true
  reaper.defer(loop)
end

reaper.defer(loop)

Last edited by cfillion; 11-28-2023 at 03:02 PM.
cfillion is offline   Reply With Quote
Old 11-28-2023, 02:48 PM   #4
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,722
Default

It also has random factor which is sometimes it would kill the script immediately when error pops up (when IDE is closed) and sometimes script would be killed after pressing continue or end script.

This happens for example if script has GUI: sometimes gui gets killed immediately on error popup, sometimes it would stay until confirming the error

Last edited by Sexan; 11-28-2023 at 02:54 PM.
Sexan is offline   Reply With Quote
Old 03-22-2024, 11:09 AM   #5
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 5,038
Default

Bump! ReaScriptError('!...') should ideally just lead to lua_error after control has left the extension (like it does now), but without inhibiting defer callbacks if the script caught that error and didn't abort, nor showing a special error window.

Last edited by cfillion; 03-22-2024 at 11:50 AM.
cfillion is offline   Reply With Quote
Old 04-12-2024, 12:50 AM   #6
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 2,023
Default

bamp
daniellumertz is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 12:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.