In order to support text in my game I wrote a class for handling textures that generates textures from images or text. It works fine when I generate a string texture upon program initialization but when a string texture is generated dynamically while in the game the texture comes out like pixel noise. You can sort of see the string but not really because you get all these random pixels of random colors all over the place where the texture is drawn.
Has anyone had this issue before or have a probable cause for this? What was causing it and how was it solved ?
I tried adding glFlush() calls after my GL code and CGContextFlush calls after my CG calls and it makes no difference.
Im using CG to draw the string to an image buffer than I then pass to openGL to generate a texture. It works very well when the string is static, but when it is generated as needed all I get is noise.
Problem solved. Turns out I was expecting malloc to not return junk. By clearing the memory allocated I got it to work flawlessly. It still doesn't explain why the simulator stops working with my collision detection when I do this, and yet it works perfectly on the device.
Problem solved. Turns out I was expecting malloc to not return junk.
C is a language written to be efficient. If you might not require it to do something it won't. So malloc returns a chunk of memory; if you, for some reason, need it to be filled with zeros it's your responsibility to do so.
This applies to all the C parts of Objective C.
__________________
Visit Mr Jack Games for my blog and more about my games
C is a language written to be efficient. If you might not require it to do something it won't. So malloc returns a chunk of memory; if you, for some reason, need it to be filled with zeros it's your responsibility to do so.
This applies to all the C parts of Objective C.
Adding: if you've found that you do indeed need it zero-filled, use calloc() instead of malloc(), as you may already know.
thanks for your reply, ye I notice this now haha, I feel silly. On my first version of the texture class I wrote I had bzeroed the memory assuming something like this might happen but being as it worked flawlessly with so many textures upon loading I did not think twice about doing this in this class rewrite as it was working just fine when tested upon launch. I suppose the problem doesn't present itself at launch since the memory is pretty much cleared at that moment.
I prefer to rename my files to .mm and use new and delete. Seems much cleaner than malloc. I'm about to play with my texture class to generate digits 1-9 in a single texture so I can easily render numbers