Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Bizarre issue with View.Set command
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
hunter2




PostPosted: Sun May 21, 2017 5:48 pm   Post subject: Bizarre issue with View.Set command

This is my first post on this forum, and I am somewhat of a newbie at Turing, and obviously with this forum, so please figure any mistakes I have made with either my code, or my post, and please point them to me so I can correct them.

Anyway, I am trying to make a platformer game, where you have a ball (its a sprite) that you can move left or right or you can jump. However, I am having an issue with the View.Set command; namely, whenever I put in the following code, or some variation of it, I get an error that says "sprite was freed". I have been trying to make the window larger, by putting
Turing:
View.Set("graphics:800;800")
Whenever I run it without that line, it looks fine, but I want the window to be bigger, so I need it, but whenever I run it with it there, the whole thing freezes, it says that the sprite was freed, and the window does not become larger.
And just a note, the code as it is, is very messy, with lots of unnecessary stuff, as well as code that has been commented out momentarily. It's basically still a work in progress



bal.bmp
 Description:
when you put this in the folder, make sure to rename it to just "bal.bmp"
 Filesize:  2.62 KB
 Viewed:  2245 Time(s)

bal.bmp



map.t
 Description:
The whole program runs from this one, just put all the files into a folder, and run this one

Download
 Filename:  map.t
 Filesize:  4 KB
 Downloaded:  123 Time(s)


Platform.t
 Description:

Download
 Filename:  Platform.t
 Filesize:  2.65 KB
 Downloaded:  109 Time(s)


NewRolll.t
 Description:

Download
 Filename:  NewRolll.t
 Filesize:  1.37 KB
 Downloaded:  125 Time(s)


graphic.t
 Description:

Download
 Filename:  graphic.t
 Filesize:  1014 Bytes
 Downloaded:  115 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sun May 21, 2017 6:24 pm   Post subject: RE:Bizarre issue with View.Set command

Your problem is almost certainly caused by your use of processes. I'm not sure exactly why this bug is happening, because it is a very unusual bug, and because processes make it nearly impossible to follow the execution of the program. If you comment out process X, the bug pops up in process Y.

You should never, ever use processes except to play music. Just don't do it. This is why. Rewrite your code to completely replace your processes with procedures. If the bug persist, we'll continue from there. Even if we do fix the bug without replacing the processes, there will be tons of other bugs as well, as a direct result of using processes. Just don't use them.
hunter2




PostPosted: Sun May 21, 2017 7:01 pm   Post subject: Re: Bizarre issue with View.Set command

Thanks for the reply!

I changed both X and Y over to procedures, as opposed to processes, and the code still functions the same. It is a very easy change, I just changed

Turing:
process
process Y
over to

Turing:
procedure X
procedure Y


and then in the loop, instead of using fork, I just call the procedure by normal means. However, even after having done this, the bug persists, in the same way, with the same error message popping up, and the window still not changing size.

Also just a question; why are processes so bad to use? What is wrong with them, and what sorts of bugs show up if you do?
Insectoid




PostPosted: Sun May 21, 2017 8:40 pm   Post subject: RE:Bizarre issue with View.Set command

I think you may have found an actual bug in the language. Inside your ConstructPlatform function is a call to View.Set ("graphics"). Deleting this line makes everything work, even with View.Set ("graphics:600;800") in the main file.

Here is a small program that reproduces the bug:
code:

var pic := Pic.FileNew ("bal.bmp")
var Ball := Sprite.New (pic)
Sprite.Show (Ball) %this line executes fine
View.Set ("graphics:800;700")
Sprite.Show (Ball) %this line fails


From experimenting, I've found that changing the dimensions of the run window after creating sprites causes the bug. In your example, you set the window size to 800x600. Later you call View.Set ("graphics") which resets the window to the default 640x480 and causes the bug.

I can't find anything in the documentation to explain this, so I can only conclude that this is a bug in Turing itself.


As far as processes go, well, they pause themselves to let other processes run. This causes code to be run out of order, and if both are modifying the same data, really weird stuff can happen. There is a longer explanation in the Turing Walkthrough.
hunter2




PostPosted: Sun May 21, 2017 8:52 pm   Post subject: Re: Bizarre issue with View.Set command

Yes! That fixed my problem! I've spent hours on this, and it's been quite frustrating not being able to figure it out. Thank you very much for taking your time to help me. It is very much appreciated.
Insectoid




PostPosted: Sun May 21, 2017 8:56 pm   Post subject: RE:Bizarre issue with View.Set command

There's also a View.Set ("graphics") line in your newroll file. I suggest you remove that as well before it causes more issues.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: