About Monkey 2 › Forums › Monkey 2 Programming Help › Memory Access violation
Tagged: M1 M2 performance errors
This topic contains 11 replies, has 4 voices, and was last updated by
abakobo
1 year, 3 months ago.
-
AuthorPosts
-
January 3, 2018 at 11:17 am #12591
This is a two part-question.
The first one is about a memory access violation from missing a New image I’m not sure why I’m getting this error message.
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104Namespace Myapp#Import "<std>"#Import "<mojo>"#Import "<mojo3d>"#Import "assets/"Using std..Using mojo..Const w:=1920, h:=1080 ' w:=1440 h:= 900Class Myapp Extends WindowField canvas:Canvas, icanvas:Canvas, scanvas:Canvas, sourcecanvas:CanvasField image:Image, sourceImage:Image, targetImage:ImageField s:Int, cx:Int, wx:Int, wy:IntField tilemap:Int[] = New Int[512*512]Field size:Int=4*4' ---------------------------------------------------------------------------------------Method New()Super.New("Myapp", w, h, WindowFlags.Resizable)For Local y:=0 To 511For Local x:=0 To 511tilemap[x + y * 512] = Int(Rnd(127))NextNext' Create empty tilessourceImage=New Image(512,512,PixelFormat.RGBA8,TextureFlags.Dynamic)sourcecanvas = New Canvas(sourceImage)sourcecanvas.Clear(Color.Black)' or load tiles'sourceImage=Image.Load("sheet.png") ' 0,0,0 in Mx ! PixelFormat.RGBA8,TextureFlags.Dynamic)' Getting an error "Attempt to invoke method on null instance"targetImage=New Image(sourceImage.Width,sourceImage.Height,PixelFormat.RGBA8,TextureFlags.Dynamic) ' ,,,0)image=New Image(512,512,PixelFormat.RGBA8,TextureFlags.Dynamic) ' image=New Image(512,512,0,0,0) & Image.SetFlagsMask(Image.Managed)icanvas=New Canvas(image)scanvas=New Canvas(targetImage)' canvas=New Canvas() not needed image.Texture.Flags &=~ TextureFlags.FilterMipmapEnd' ---------------------------------------------------------------------------------------Method OnRender( canvas:Canvas ) OverrideApp.RequestRender()' canvas.Alpha=1.0scanvas.Clear(Color.Black)scanvas.DrawImage(sourceImage,0,0) ' Instead of shader, it copies sourceImage without alteration to targetImage.scanvas.Flush()' Init canvas & imagecanvas.Clear(Color.Black) ' canvas.Viewport(0,0,w,h) ; canvas.Scissor(0,0,w,h) ; canvas.Projection2d(0,w,0,h)icanvas.Clear(Color.Black) ' icanvas.Viewport(0,0,w,h) ; icanvas.Scissor(0,0,w,h) ; icanvas.Projection2d(0,w,0,h)' Draw to image' Scroll by drawing onto itselficanvas.Clear(Color.Black)icanvas.DrawImage(sourceImage,0,0)icanvas.DrawImage(targetImage,256,256)cx=(cx+2) Mod 512For Local temp:=0 To 127icanvas.DrawRect(64+temp,0,1,64,targetImage,0+temp+cx,0,1,64)Next' Plot something to show how to draw to image after shader have been applied.For Local temp:=1 To 16If Int(Rnd(1)) Then icanvas.Color = Color.Black Else icanvas.Color = Color.WhiteLocal xx:= Int(Rnd(7))Local yy:= Int(Rnd(7))icanvas.Color = Color.Greenicanvas.DrawRect(xx*4,yy*4,2*4,2*4)Nexticanvas.Flush()' Draw to canvas.Local scrx:=wx Mod sizeLocal scry:=wy Mod sizeLocal mapx:=wx / sizeLocal mapy:=wy / sizeLocal cnty:= -scryFor Local y:=mapy To mapy+((h/size)+1)Local cntx:=-scrxFor Local x:=mapx To mapx+((w/size)+1)Local char:= tilemap[x + y * 512]Local tilex:= char & 15Local tiley:= char Shr 4canvas.DrawRect(cntx,cnty,size,size,image,tilex Shl 5,tiley Shl 5,32,32)cntx=cntx+sizeNextcnty=cnty+sizeNextcanvas.Flush()' User input here as there is no OnUpdate() equivalent in Monkey2If Keyboard.KeyReleased(Key.Escape) Then App.Terminate()wx=wx+2End MethodEnd' ---------------------------------------------------------------------------------------Function Main()New AppInstanceNew MyappApp.Run()End FunctionThe second question is about the performance.
High Sierra sucks big balls and am still waiting for Apple’s bugfixes and the next version of macOS.On my main computer I still got Sierra and Monkey1 1.87e as they behave butter smooth and without problems. Love it.
Of course I needed to be progressive and added Monkey2 but I couldn’t add anything but V1.1.07 to it, as Monkey2 v1.1.08 needs an updated Xcode which in turn needs High sierra and NO I want something that works and am NOT ruining the performance of both of my computers. Updating is scary business !The Monkey 1.87e sourcecode works absolutely perfectly smooth (at least on Sierra for now, but probably on higher versions too I just don’t have that many computers to try it on. The important point I wanna make is, It’s 100% stable, never any hiccups, EVER.
The Monkey2 source code *almost* works, so in any macOS and any M1 and M2 version you use… check those two source codes out and compare them. Notice how M1 is 100% smooth, and how Monkey2 is only 99.9% smooth. I want to know why and if possible… fix it.
January 3, 2018 at 11:20 am #12592“Included File exceeded size”
But I want you to see the M1 equvialent code too, so I put it here.
[/crayon]Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103[crayon-5cb9cc179cd84134812717 inline="true" ]#GLFW_WINDOW_WIDTH = 1920 ' 1440#GLFW_WINDOW_HEIGHT = 1080 ' 900#GLFW_WINDOW_FULLSCREEN =TrueImport mojo2Class MyApp Extends AppField canvas:Canvas, icanvas:Canvas,scanvas:Canvas, sourcecanvas:CanvasField image:Image, sourceImage:Image, targetImage:ImageField s:Int = 4, cx:Int, d, wx:Int, wy:IntField tilemap:Int[512*512]Field size:Int=4*4' ---------------------------------------------------------------------------------------Method OnCreate()For Local y:=0 To 511For Local x:=0 To 511tilemap[x + y * 512] = Int(Rnd(127))NextNext' Create empty tilessourceImage=New Image(512,512,0,0,0) ' THISsourcecanvas = New Canvas(sourceImage)sourcecanvas.Clear 0,0,0' or load tiles '' sourceImage=Image.Load("sheet.png",0,0,0)targetImage=New Image(sourceImage.Width,sourceImage.Height,0,0,0) ' THISimage=New Image(512,512,0,0,0) ' THISImage.SetFlagsMask(Image.Managed) ' THISicanvas=New Canvas(image)scanvas=New Canvas(targetImage)canvas=New CanvasEnd' ---------------------------------------------------------------------------------------Method OnUpdate()If KeyHit(KEY_ESCAPE) Then EndAppwx=wx+2EndMethod OnRender()scanvas.Clear 0,0,0scanvas.DrawImage sourceImage,0,0 ' Instead of shader, it copies sourceImage without alteration to targetImage.scanvas.Flush()' Init canvas & imageLocal w=DeviceWidthLocal h=DeviceHeight'canvas.SetViewport 0,0,w,h'canvas.SetScissor 0,0,w,h'canvas.SetProjection2d 0,w,0,hcanvas.Clear 0,0,0'icanvas.SetViewport 0,0,w,h'icanvas.SetScissor 0,0,w,h'icanvas.SetProjection2d 0,w,0,h' Draw to image' Scroll by drawing onto itselficanvas.Clear 0,0,0icanvas.DrawImage sourceImage,0,0icanvas.DrawImage targetImage,256,256cx=(cx+2) Mod 512For Local temp:=0 To 127icanvas.DrawRect 64+temp,0,1,64,targetImage,0+temp+cx,0,1,64Next' Plot something to show how to draw to image after shader have been applied.For Local temp:=1 To 16If Int(Rnd(1)) Then icanvas.SetColor 0,0,0 Else icanvas.SetColor 1,1,1Local xx:= Int(Rnd(7))Local yy:= Int(Rnd(7))icanvas.SetColor 0,1,0icanvas.DrawRect xx*4,yy*4,2*4,2*4Nexticanvas.Flush' Draw to canvas.Local scrx:=wx Mod sizeLocal scry:=wy Mod sizeLocal mapx:=wx / sizeLocal mapy:=wy / sizeLocal cnty:= -scryFor Local y:=mapy To mapy+((h/size)+1)Local cntx:=-scrxFor Local x:=mapx To mapx+((w/size)+1)Local char:= tilemap[x + y * 512] ; Local tilex:= char & 15 ; Local tiley:= char Shr 4canvas.DrawRect cntx,cnty,size,size,image,tilex Shl 5,tiley Shl 5,32,32cntx=cntx+sizeNextcnty=cnty+sizeNextcanvas.FlushEndEnd' ---------------------------------------------------------------------------------------Function Main()New MyAppEndJanuary 3, 2018 at 11:29 am #12593January 3, 2018 at 3:48 pm #12599To check memory access violation error you can run your game in debug mode: menu Build — Debug.
Or you know the line with error but don’t understand why?
January 3, 2018 at 4:23 pm #12600Yes I’m running debug mode, I have no idea why I get the error message though?
Attachments:
January 3, 2018 at 5:29 pm #12603I fixed it, I had missed a asset:: again.
Now to the main question, there performance of Monkey2. I tried to make the examples as similar to eachoother as I could. Compare the Monkey1 and Monkey2.
A good way to try these are on a stock new MacBook of some kind.
The Monkey1 runs perfectly smooth using for example v87e.Monkey2 does *almost* run perfectly smooth using one of the last two versions available.
Why does it not run as smooth? And what to do about it? I’m sure it’s behind the hood so its nothing I could do about it. But why does it happen?
Attachments:
January 3, 2018 at 5:34 pm #12605A stock macbook Air 2015 for instance runs the Monkey1 code 60fps without hiccups for hours.
Well if you don’t move your mouse and keyboard that is.The Monkey2 (You’re forced to use the 1.0.0.7 version bc 1.0.0.8 does not work on stock MacBook wo a xcode/macos update, and you DON’T WANT TO DO THAT YET). Monkey2 works you would think, and it does, but now and then graphical hickups comes around and hit you in the face.
January 3, 2018 at 6:25 pm #12609I guess though it would perform as it should on Android and iOs.
But, it would be nice if it would perform great once again on macOS too.. I’d love to have a “classic computer platform” that really REALLY works without any flaws.
Time changes.. this was one year ago, what about now? should I give up on perfect 60 fps with macOS and Monkey2?
Shoulld I buy an old 2015 MacBook and keep it unupdated forever and just use Monkey1 on it for my “strange retro desires” of having a perfectly smooth computer and language? or will the Monkey2 graphics be fixed for macOS?
January 3, 2018 at 9:55 pm #12613Monkey2 speed on desktop may or may not improve in futre. I am quite happy with the current speed so have no immediate optimization efforts planned. As for the future, I always like to tinker with things so who knows?
I recommend sticking with monkey1 if you absolutely need the speed you were getting with that and you don’t care about anything else monkey2 has to offer. The cerberus guys seem to be successfully keeping it alive so it wont be going anywhere for a while yet.
January 3, 2018 at 10:18 pm #12615Okay. How about the performances on iOS devices? Do they also differ or do they have a consistent fps quality with M2?
January 3, 2018 at 11:04 pm #12618I wish there could be a “Blitzmode” available, as there were in BlitzBASIC I (as well as II).
I’m well knowing that platforms such as iOS, Android, Windows, macOS etc would never support such a thing. It’s a pity because sometime realtime and media quality is what you want from your devices.January 5, 2018 at 8:49 am #12667oh man! the generated image is very psychedelic! I had to jump on alt+F4!
about your code:
you are using two canvases, canvases slows down you computer, you’d probably will have better perfs with transform matrixes and a single canvas.And yes there’s a OnUpdate() event but also OnKeyEvent() and OnMouseEvent(). OnUpdate is not documented though!(will post issue). You can have a look at spacechimps banana to see an example of an app using both OnUpdate() and OnKeyEvent()
-
AuthorPosts
You must be logged in to reply to this topic.
