evanbowman / BPCore-Engine

Lua game framework for Gameboy Advance
The Unlicense
166 stars 10 forks source link

tostring #15

Open shakna-israel opened 3 months ago

shakna-israel commented 3 months ago

I'm honestly just sort of fishing here.

It works in mGBA, so the problem might not be in BPCore-Engine.

However, on my GB300, I get a crash if I either call tostring or string.format. The overlay turns blue, and processing freezes.

I have no real idea where or why this happens. Because I do think both of those are included in BPCE, because it does work under an emulator. I do know the GB300's emulators are not well respected, because they do have faults.

Kinda hard to output a highscore, and I don't particularly want to rewrite tostring in Lua.

shakna-israel commented 3 months ago

I think it's a memory problem. Probably?

I managed to stop the crashes with this insane little bit o' code:

do
    local std_tostring = tostring
    tostring = function(i)
         if i == 0 then
            return "0"
         elseif i < 0 then
            return "-" .. tostring(-i)
         else
            local str = ""
            while i > 0 do
                local digit = i % 10
                str = std_tostring(digit) .. str
                i = math.floor(i / 10)
            end
            return str
         end
    end
end
evanbowman commented 3 months ago

Hi! I could try to debug it if you have some sample code, and do you know what emulator that the GB300 uses? If I can run the code (or a minimal subset of it that reproduces the problem), along with a copy of the emulator, I may be able to resolve the problem. Unfortunately, without either the GB300 or the emulator that the GB300 uses to run GBA games, it could be difficult for me to diagnose the issue. tostring and string.format are both built into the Lua runtime, for it to be a software issue, I would think that these functions would need to be bugged in the Lua implementation, which is unlikely, although there may be a problem elsewhere in the engine code that results in a memory fault downstream. All of this is a bit speculative on my part.

shakna-israel commented 3 months ago

Afraid the only real thing I know about the GB300's GBA is it uses this. It is a bit hacky.

I did actually use Lua's tostring - just sharded the value so it was smaller, so I'm assuming it was some sort of memory fault in the GB300's implementation. Maybe it has some sort of limit on the size that can be allocated at any one time?

Anyways, it's probably way out of scope for BPCore-Engine. Just me fooling around to get stuff on a physical device, because that's fun.