trevordevore / levure

Application development framework for LiveCode
MIT License
32 stars 14 forks source link

stack with same name already in memory when building #95

Closed jim1001 closed 6 years ago

jim1001 commented 6 years ago

Be grateful for some help on this which has just come up.

I made a copy of the app.livecodescript file from the main Levure app I'm developing so I could look at the code in a external text editor whilst working on a test Levure app (to make sure I didn't change the original by accident). I put the copy on my desktop.

I finished with the test app & went back to working on the main app which loaded fine in the IDE. When I came to build my main app however with levurePackageApplication I got the message "stack that you're trying to load has same name as one already in memory . What do you want to do with stack ?”

I can’t see why building would try to load the copy (after app loads without doing so) & not sure of best way to correct it.

ps: I frequently exit & restart LiveCode when working on a Levure app and always do before switching apps.

Thanks.

jim1001 commented 6 years ago

Just to update. Restarted my PC & tried the build again. Worked fine. No messages about duplicate stacks. Very puzzling.

For info: In my LiveCode preferences I have: If destroyStack is false, when closing last stack in file => Close the file destroyStack property is set to true for new stacks

This post advises ...set the destroystack property in the stack's property inspector for each individual stack.

Is that required / a good idea for stacks in a Levure project?

trevordevore commented 6 years ago

Two questions:

  1. Had you opened both the copy of app.livecodescript and your actual Levure app in the same IDE at some point during the same session?
  2. Did you delete the copy on your desktop before or after restarting and trying to build again?

Regarding destroyStack - this can be good and bad. For example, the app.livecodescript stack is used as a library stack and has important code for your application. If you set destroyStack to true, open it during an editing session, and then close it then the stack would be removed from memory and wouldn't work the same.

For UI stacks setting the destroyStack to true can be a good thing. As users open and close UI stacks it can free up memory.

jim1001 commented 6 years ago

Your help is much appreciated Trevor.

Had you opened both the copy of app.livecodescript and your actual Levure app in the same IDE at some point during the same session?

Well I know not to do that as I've been stung in the past. As sure as possible I didn't open the copy at all in LiveCode. That was why I was amazed to see it referred to when I went back to building my main app.

Did you delete the copy on your desktop before or after restarting and trying to build again?

No - it's still there now. I made the copy outside LiveCode so I don't get how LiveCode knows anything about it. Is it a problem? What do you do if you want to refer to code in one app whilst another is opened in the IDE? An alternative I considered was to open the original file in a external text editor & set it to read-only. But I thought making a copy would be even safer...

As I said the first build after I re-booted was successful so I'm hoping the problem won't come back But it's always a concern when unexpected things happen - especially if they prevent you from building your app. It's the first worrying thing that's happened in a while & probably no coincidence right after copying the LiveCode script to look at...

jim1001 commented 6 years ago

An update on this. I loaded up the app again without any "same name" messages then built with my English build profile. No problems. Restarted LiveCode & built with my Swedish build profile. The message was back. Previously I got the message with the English profile & not the Swedish one. Hmm. I'm not sure what will happen if I delete the copy as it appears to be in some build code to load it.

ps: I clicked Save & the build was successful

screenshot 26

jim1001 commented 6 years ago

Further update:

I'm still getting the message above when I use levurePackageApplication. Don't get it on loading the app.

I searched the working directory with a "git grep Desktop" but this returned no finds.

So still puzzled where levurePackageApplication picks up that it needs to load C:/Users/Jim/Desktop/app.livecodescript and why. Since I don’t know what file contains the wrong information or can see any evidence of where the error was introduced, even with git, I guess the best I can do is go back to a commit before I saw this problem...

jim1001 commented 6 years ago

Before I returned to the commit before the problem appeared, I deleted from my desktop the files I copied. Then tried levurePackageApplication. The .apk was not produced. The last two lines in the build.log file were: Build: Saving temporary stack with IDE call Build: revSaveAsStandalone

I restarted LiveCode & tried levurePackageApplication again. This time a .apk was produced & there were no "stack with same name" messages. Tried one more time with a different build profile - another success. Hoping problem gone for good. Would like to understand how the problem may have arisen & how to prevent it in the future.

trevordevore commented 6 years ago

I'm not sure what would cause this error while building a standalone. If you can recreate the problem by placing the files back on the desktop then you could take a look at the executionContexts to see if it provides any clues.

The dialog that is appearing is triggered from the "revbackscriptlibrary" stack in the IDE. If you edit the script of stack "revbackscriptlibrary" then you will find the relevant code in the reloadStack handler. Try adding the following line below set the defaultStack to pStackName (line 976 in the script I'm looking at):

set the clipboardData to the executionContexts 

Depending on how the engine reports the executionContexts in the reloadStack message the clipboard may or may not contain useful information.

jim1001 commented 6 years ago

Thanks for reply Trevor.

The error was recreated by putting app.livecodescript back on the desktop. Here was the clipboard contents:

stack "C:/Program Files (x86)/RunRev/LiveCode Community 8.1.7/Toolset/libraries/revidelibrary.8.livecodescript",ideMessageSend,1808
stack "C:/Program Files (x86)/RunRev/LiveCode Community 8.1.7/Toolset/libraries/revidelibrary.8.livecodescript",ideMessageSendWithParameters,1784
stack "C:/Program Files (x86)/RunRev/LiveCode Community 8.1.7/Toolset/libraries/revidelibrary.8.livecodescript",ideMessageSendWithParameters,1783
stack "C:/Program Files (x86)/RunRev/LiveCode Community 8.1.7/Toolset/palettes/project browser/revideprojectbrowser.livecode",ideStackDeleted,214,stack "C:/Program Files (x86)/RunRev/LiveCode Community 8.1.7/Toolset/palettes/project browser/revprojectbrowserbehavior.livecodescript"
stack "C:/Program Files (x86)/RunRev/LiveCode Community 8.1.7/Toolset/palettes/project browser/revideprojectbrowser.livecode",deleteStackFromProjectBrowser,1961,stack "C:/Program Files (x86)/RunRev/LiveCode Community 8.1.7/Toolset/palettes/project browser/revprojectbrowserbehavior.livecodescript"
stack "C:/Program Files (x86)/RunRev/LiveCode Community 8.1.7/Toolset/libraries/revbackscriptlibrary.livecodescript",reloadStack,977
trevordevore commented 6 years ago

Do you have the Project Browser open while packaging the app? If so try closing it. Do you still get the error?

jim1001 commented 6 years ago

I found that if the Project Browser has been opened at all after loading the project I got the error, even if I closed it before running levurePackageApplication. If I didn't open the Project Browser at all after loading the project then ran levurePackageApplication, I didn't see the error.

I also observed this:

  1. Change Standalone Application Settings of Levure Standalone
  2. Run levurePackageApplication
  3. Exit without saving Levure Standalone
  4. Start LiveCode & reload project
  5. Inspect Standalone Application Settings of Levure Standalone - it has the changed settings even though these weren’t saved by user
trevordevore commented 6 years ago

I found that if the Project Browser has been opened at all after loading the project I got the error, even if I closed it before running levurePackageApplication. If I didn't open the Project Browser at all after loading the project then ran levurePackageApplication, I didn't see the error.

Well that is interesting. After looking at the code referenced in the executionContexts it isn't clear what is causing the stack from the desktop to be loaded. The error seems to occur when the PB is notified that a stack has been removed from memory. I can't see what is triggering the reload, however.

Regarding your stack being saved when packaging - yes, it is supposed to be saved. packagerBuildStandalones updates the version information in the standalone stack, saves it, and then builds the standalone(s).

jim1001 commented 6 years ago

Regarding your stack being saved when packaging - yes, it is supposed to be saved. packagerBuildStandalones updates the version information in the standalone stack, saves it, and then builds the standalone(s).

OK, understood.

Re: the "stack with same name". It's an unusual error & there is a workaround so no worries. If you want me to do any more tests though please let me know.

Thank you.

trevordevore commented 6 years ago

I don't have a specific test for you to run. I fear that getting to the bottom of this will require a fair bit of time and will involve learning a lot about how the PB is dealing with stack references.