About Monkey 2 › Forums › Monkey 2 Development › (Bug) Canvas-related?
This topic contains 3 replies, has 2 voices, and was last updated by
impixi
2 years, 9 months ago.
-
AuthorPosts
-
June 29, 2016 at 3:49 am #1277
The 16th call to a method or function that creates a Canvas object will generate an array index error.
Example:
[/crayon]Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879[crayon-5cb9d7bc5aea1973211877 inline="true" ]#Import "<std>"#Import "<mojo>"Using std..Using mojo..Function Main()New AppInstanceNew MyWindow( "Test", 1024, 768)App.Run()End'--------------Const NUM_IMAGES := 16 ' ***** Crashes above 15Class MyWindow Extends WindowField initialized:Bool = FalseField generatedImages:Image[]Method New(title:String, width:Int, height:Int, flags:WindowFlags = WindowFlags.Resizable )Super.New(title, width, height, flags)ClearColor = Color.BlackMinSize = New Vec2i(800, 600)Style.BackgroundColor = Color.DarkGreySwapInterval = 0EndMethod Init:Void(canvas:Canvas)generatedImages = New Image[NUM_IMAGES]For Local i:Int = 0 Until generatedImages.LengthgeneratedImages[i] = GenerateImage()Nextinitialized = TrueEndMethod GenerateImage:Image()Local img := New Image (32, 32)Local imgCanvas := New Canvas(img)imgCanvas.Clear(New Color(0.0, 0.0, 0.0, 0.0))imgCanvas.Color = New Color(Rnd(), Rnd(), Rnd(), 1.0)imgCanvas.DrawCircle(16, 16, 16)imgCanvas.Flush()Return imgEndMethod OnRender:Void(canvas:Canvas) OverrideIf Not initializedInit(canvas)EndifApp.RequestRender()For Local i:= 0 Until generatedImages.Lengthcanvas.DrawImage(generatedImages[i], i * 32, 10)Nextcanvas.Color = Color.Whitecanvas.DrawText(App.FPS, 10, 10)canvas.Flush()EndMethod OnWindowEvent:Void(event:WindowEvent) OverrideIf event.Type = EventType.WindowCloseApp.Terminate()EndifEndMethod OnKeyEvent:Void(event:KeyEvent) OverrideIf event.Type = EventType.KeyUp And event.Key = Key.Escape Then App.Terminate()EndEndConsole output:
Array index out of range
{{!DEBUG!}}
>Bind:Void(env:mojo.graphics.ShaderEnv);C:/monkey2/modules/mojo/graphics/shader.monkey2;290;21321307
Self:mojo.graphics.Shader=@00c12a3c
env:mojo.graphics.ShaderEnv=@03ee29ac
>Validate:Void();C:/monkey2/modules/mojo/graphics/device.monkey2;317;21321306
Self:mojo.graphics.GraphicsDevice=@03ee3e84
>Render:Void(vertices:mojo.graphics.Vertex2f Ptr,order:Int,count:Int);C:/monkey2/modules/mojo/graphics/device.monkey2;168;21321305
Self:mojo.graphics.GraphicsDevice=@03ee3e84
vertices:mojo.graphics.Vertex2f Ptr=?????
order:Int=32
count:Int=1
>RenderDrawOps:Void();C:/monkey2/modules/mojo/graphics/canvas.monkey2;900;21321276
Self:mojo.graphics.Canvas=@09a1b284
p:mojo.graphics.Vertex2f Ptr=?????
0:std.collections.Stack<mojo.graphics.DrawOp>.Iterator=@00b5f9e8:0045ef94
op:mojo.graphics.DrawOp=@03ee4144
>Flush:Void();C:/monkey2/modules/mojo/graphics/canvas.monkey2;251;21321273
Self:mojo.graphics.Canvas=@09a1b284
>GenerateImage:mojo.graphics.Image();C:/Shane2016g/SimpleFW2016/bi/bugtest.monkey2;47;20198698
Self:default.MyWindow=@00c91c4c
img:mojo.graphics.Image=@03ee266c
imgCanvas:mojo.graphics.Canvas=@09a1b284
>Init:Void(canvas:mojo.graphics.Canvas);C:/Shane2016g/SimpleFW2016/bi/bugtest.monkey2;36;3357663
Self:default.MyWindow=@00c91c4c
canvas:mojo.graphics.Canvas=@00c4e73c
i:Int=15
>OnRender:Void(canvas:mojo.graphics.Canvas);C:/Shane2016g/SimpleFW2016/bi/bugtest.monkey2;54;3357662
Self:default.MyWindow=@00c91c4c
canvas:mojo.graphics.Canvas=@00c4e73c
>Render:Void(canvas:mojo.graphics.Canvas);C:/monkey2/modules/mojo/app/view.monkey2;648;3356823
Self:mojo.app.View=@00c91c4c
canvas:mojo.graphics.Canvas=@00c4e73c
>Render:Void();C:/monkey2/modules/mojo/app/window.monkey2;152;3355860
Self:mojo.app.Window=@00c91c4c
bounds:std.geom.Rect<Int>=@00b5fcec:004c1360
>MainLoop:Void();C:/monkey2/modules/mojo/app/app.monkey2;307;3355375
Self:mojo.app.AppInstance=@00c106fc
0:Void[]=@00c1705c
1:Int=0
2:Int=1
window:mojo.app.Window=@00c91c4c
>Run:Void();C:/monkey2/modules/mojo/app/app.monkey2;334;3355372
Self:mojo.app.AppInstance=@00c106fc
>Main:Void();C:/Shane2016g/SimpleFW2016/bi/bugtest.monkey2;10;89It’s apprently related to the _programs:=New ShaderProgram[16] field in the Shader class not being reset when creating a new Canvas object (because the Canvas shader fields are declared Global).
I’ve tried hacking the relevent mojo files to fix/work around it but my efforts have failed thus far…
June 29, 2016 at 4:13 am #127816 canvases should be enough for anyone!
Actually, I think this is fixed in my version…it works at 10000 anyway.
New stuff coming soon!
June 29, 2016 at 5:23 am #128016 canvases should be enough for anyone!
Haha, not if, for performance reasons, you want to pre-generate variably-sized images of blocks of text/labels/buttons/lists/etc.
EDIT: I should clarify, I’m only using 1 canvas at a time, local to a function/ method while rendering to an image.
Actually, I think this is fixed in my version…it works at 10000 anyway.
New stuff coming soon!
Great. Can’t wait to test it out… Might even be time soon for another donation.
July 1, 2016 at 1:26 am #1453Yes, this is fixed in V1.0.0. Thanks.
-
AuthorPosts
You must be logged in to reply to this topic.