Some days ago I posted some rant(ish) comments about differences between the debug and the release version behavior. Today I’ve managed to find the bug, so thanks you guys for your help.
Programmer Tip: a crash course into “how to debug” can be found from the comments of that blog post.
In retrospect, I think it’s pretty hard to know if this was “my code problem” or “Leadwerks engine problem”. It sort of lies in between. I could argue that the difference between debug mode and release mode was caused by Leadwerks, but in the same time I kind of feel that if I had used a better coding structure, I would have never experienced the problem. I just let you decide whose the blame.
Anyway, here’s the problem and the solution. I try to explain this in a non-techy way right after the code parts, so check this out:
(This was my original code, it worked only in debug mode)
function drawhovertext(entity:tentity) if (entity = null) return endif physicalObject = TPhysicalObject(GetEntityUserData(entity)) drawtext(physicalobject.hovertext) end function function update(...) ... do stuff entity = campick.entity updateappspeed updateworld renderworld drawhovertext(entity) end function
And here’s the code that works (I’ll explain the difference below).
function sethovertext(entity:tentity) physicalObject= TPhysicalObject(GetEntityUserData(entity)) self.hovertext = physicalobject.hovertext end function function drawhovertext(entity:tentity) drawtext(self.hovertext) end function function update(...) ... do stuff entity = campick.entity sethovertext(entity) updateappspeed updateworld renderworld drawhovertext() end function
So, basically all you programmer geeks can perhaps read what’s going on but I still want to explain what was happening.
- I was basically doing messing with an “entity”, then running “update world (and collisions)”, and then “drawing text on screen using the entity”. This didn’t work.
- I changed things that I first “messed with the entity, prepared the hover text”, then run “update world (and collisions)” and after that “draw text on screen using a prepared variable”. This worked.
- Also notice that entity was usable all the time – I wasn’t trying to use a “null” entity. It was only a collision of physics controllers (of all characters) that weren’t working.
The entity was no longer used after “collision check”, and basically I could have prevented this by simply “preparing things for render” before doing collision checks, renders and other things – and then simply draw the textual parts (in a “dummy way”) to the screen.
I’m glad that the problem was sorted out (but whose fault was it…?)