Simulator crashing for some sprite rotations


I have a simple program that only loads a sprite and rotates it:

import "CoreLibs/sprites"

local gfx =

local beam ="tex/beam.png"))
beam: moveTo(200,120)
beam: add()

beam: setRotation(178) 
beam: update()

For some unfortunate rotation numbers, it crashes in 70% of the cases on both simulator and device. 178 being one of them. 177 or 179 don’t cause the game to crash. (beam: update() is not necessary to crash it).

I can’t really read the crash report, but maybe these are the important lines:

Crashed Thread: 0 Dispatch queue:

Exception Codes: KERN_INVALID_ADDRESS at 0x00000000000ff1f8

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [24761]

This sounds like a bug I’ve fixed in the next update, coming soon: I was passing the floating-point width and height of the rotated image to the allocator/initializer function (which reads them as ints, so they were truncated) but then I used ceil() when passing them to the drawing function, leading to an out-of-bounds write in certain cases.

What’s the width and height of beam.png?

That probably not the issue here, but the update function shouldn’t be called on the object itself.

You should call gfx.sprite.update() to update all the sprites that were added to the sprite system.

That’s great :slightly_smiling_face: The dimensions are 28 x 114 px.

Thanks, I will do that! (It’s not the problem, but good to know)

Yep, 28x114 rotated 178 definitely triggers that bug. We’ll have a fix for you soon!

Great, the latest update fixed it, thank you!

However, I found out that rotating two 400px images is very expensive for the framerate – even more expensive than loading an image? If I rotate them, the frame rate drops to ~15–20. Is that normal?

Yes, playdate has cheap space and expensive cpu time. If you want to rotate sprites - prerender images, load them to RAM as imagetable then change images as sprite rotates. Daily Driver once had 360 rotated images for each car…

1 Like

Good to know, thanks!

360x11 each for car and shadow. 7920 total.

Currently using only 90x11x2 (1980 total) only because of my desire to keep render times “low” during development iterations.

1 Like