Old 10-15-2018, 07:04 PM   #1
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 51
Default A Lua script that can make reaper CRASH

I tried to creat a script to make a new mediaitem at edit cursor base on a exist item

Code:
--Get information from an item

item=reaper.GetMediaItem(0,0)

take=reaper.GetMediaItemTake(item,0)

file=reaper.GetMediaItemTake_Source(take)

length=reaper.GetMediaItemInfo_Value(item,"D_LENGTH")

pos=reaper.GetCursorPosition()

track=reaper.GetMediaItemTrack(item)

--Creat new item base on the first one

itemnew=reaper.AddMediaItemToTrack(track)

reaper.SetMediaItemInfo_Value(itemnew,"D_LENGTH",length)

reaper.SetMediaItemInfo_Value(itemnew,"D_POSITION",pos)

takenew=reaper.AddTakeToMediaItem(itemnew)

reaper.SetMediaItemTake_Source(takenew,file)

reaper.UpdateArrange()
It worked actually, created a new mediaitem exactly the same as the original one. But then I try to delete any of them, either the original one or the new one, reaper CRASH, and showed a warning message like this:



Anybody can tell me what's wrong with the script?
Attached Images
File Type: png 微信截图_20181016095203.png (9.6 KB, 128 views)
dsyrock is online now   Reply With Quote
Old 10-15-2018, 08:31 PM   #2
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 513
Default

This is a Reaper-Bug and needs to be fixed by the devs themselves.

In addition to your script, can you post the project itself as well?
Run the script to create the duplication of the items(without deleting them!) and save the project.
Post that RPP-File to your post to give insight, what is happening in your project.

This could be helpful for the devs to bugfix it.

Another thing, everytime Reaper crashes, you should post into the Bug Reports-subforum, so the devs don't miss your bugreport accidentally.

Which Reaper-version and which Operating-System-version are you using?


Edit: I can confirm this crash on Windows 7Pro with Reaper 5.96 and SWS 2.97
__________________
Reaper Fun Fact of the week: Font in the IDE is too small?
Change Config-variable edit_fontsize or the reaper.ini entry [REAPER]->edit_fontsize to the fontsize you need.
mespotine is offline   Reply With Quote
Old 10-15-2018, 08:52 PM   #3
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 513
Default

Until the bug is fixed, you can use this function to help you do the copying.

Code:
function CopyItemToPosition(track, item, position)
  retval, statechunk=reaper.GetItemStateChunk(item,"",false)
  newitem = reaper.AddMediaItemToTrack(track)
  reaper.SetItemStateChunk(newitem, statechunk, false)
  reaper.SetMediaItemPosition(newitem, 10, false)
  return item
end


CopyItemToPosition(reaper.GetTrack(0,1), reaper.GetMediaItem(0,0), 20)
-- first parameter the track,
-- second parameter is the MediaItem to create a copy from
-- third parameter, the position in seconds
--
-- it returns the newly created item
__________________
Reaper Fun Fact of the week: Font in the IDE is too small?
Change Config-variable edit_fontsize or the reaper.ini entry [REAPER]->edit_fontsize to the fontsize you need.
mespotine is offline   Reply With Quote
Old 10-15-2018, 10:55 PM   #4
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,051
Default

its not a bug,you cannot use file name (source) directly
Code:
filename=reaper.GetMediaSourceFileName(source, "")
clonedsource=reaper.PCM_Source_CreateFromFile(filename)
reaper.SetMediaItemTake_Source(take, clonedsource)
Sexan is offline   Reply With Quote
Old 10-16-2018, 08:24 PM   #5
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 51
Default

Quote:
Originally Posted by Sexan View Post
its not a bug,you cannot use file name (source) directly
Code:
filename=reaper.GetMediaSourceFileName(source, "")
clonedsource=reaper.PCM_Source_CreateFromFile(filename)
reaper.SetMediaItemTake_Source(take, clonedsource)
Yes, that's the big mistake in my script. I fixed that according to your advise, and then it worked! Thank you so much!
dsyrock is online now   Reply With Quote
Old 10-16-2018, 08:25 PM   #6
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 51
Default

Quote:
Originally Posted by mespotine View Post
Until the bug is fixed, you can use this function to help you do the copying.

Code:
function CopyItemToPosition(track, item, position)
  retval, statechunk=reaper.GetItemStateChunk(item,"",false)
  newitem = reaper.AddMediaItemToTrack(track)
  reaper.SetItemStateChunk(newitem, statechunk, false)
  reaper.SetMediaItemPosition(newitem, 10, false)
  return item
end


CopyItemToPosition(reaper.GetTrack(0,1), reaper.GetMediaItem(0,0), 20)
-- first parameter the track,
-- second parameter is the MediaItem to create a copy from
-- third parameter, the position in seconds
--
-- it returns the newly created item
Maybe I misunderstanding about the correct way of using the function "GetMediaSourceFileName"
dsyrock is online now   Reply With Quote
Old 10-16-2018, 08:26 PM   #7
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: The vast, frozen wasteland of western Canadia.
Posts: 5,552
Default

It's still a Reaper bug in the sense that the API functions shouldn't be able to crash it because you gave it the wrong value.
__________________
Currently enrolled in a coding bootcamp; don't expect timely responses from me.
Default 5.0 Nitpicky Edition / GUI tutorial for Lua / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate / ReaPack
Lokasenna is offline   Reply With Quote
Old 10-16-2018, 11:04 PM   #8
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 2,051
Default

then I guess it is not easy to fix since this issue was brought up few times before and I even had discussion with scwha about it on PM
Sexan is offline   Reply With Quote
Old 10-17-2018, 12:02 AM   #9
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,248
Default

https://forum.cockos.com/showthread.php?t=212276
cfillion is online now   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 02:57 AM.


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