Inconsistent behavior in the simulator and in the build

As I’ve already posted on these forums, I’m trying to debug why my project works perfectly in Corona’s simulator, and doesn’t work at all after a build (it shows the background, and nothing else). I wanted to try and debug by iteratively adding chunks of code I’ve already written and adding them to my project. I’ve had trouble starting to do this, because, as it later became apparent, building with the same name twice causes a the app to crash under XCode simulator (i.e. launch and exit immediately).
I have an example of inconsistent behavior. This is due to including code from a .lua file that is in a subfolder of the root folder. Since the latest release notes contained the following piece of info:

“Added support for sub-folders in the app bundle for iPhone device builds”

I consider this a bug.

So, this reproduces a blank screen in XCode simulator, and a functional screen with text in Corona simulator, for me:

In a fresh project with main.lua in it, create a folder in the root folder, named “Folder”, place “requireFail.lua” inside it with the following code:

background = display.newRect(0,0, display.contentWidth, display.contentHeight);  
background:setFillColor(0, 190, 220);  

Code for main.lua:

require("Folder/requireFail");  
  
local test = display.newText("Hello", 20, 20, "helvetica", 20);  
test:setTextColor(255,0,0);  

As a result, I get a blue background with text in Corona’s simulator, and a black screen in XCode’s simulator.

Also, if I remove the “require” line and build with the same name, the application crashes in XCode’s simulator. Building with a different name without the require is ok.
If the case is that folder structures don’t work, I really need to know if this is not supported, when it will be supported, and I’d like to urge developers to create a patch to support this ASAP. I’d also really appreciate help with getting my application to show up in XCode simulator exactly as it does in Corona simulator.

I’ve spent a lot of time on this already, and it really should not be this much of a problem, I’m really starting to get angry with the engine for all the misery I’m going through to get the same behavior in XCode’s simulator as in Corona’s simulator.

The reasons for my misery are things like long builds, unexpected reasons for failures - like merely adding an empty folder to the project and rebuilding with the same name - no errors in the XCode console that would point me in the right direction to fix things, etc. I realize being in a different time zone than the developers complicates support, so if AM is willing to help me with my problem at a scheduled time that I could stay in late and ask a couple of questions that I could get answers to reasonably quickly, that would be great.

If I could get a guarantee that by writing a custom parser that would transform my code base and file structure to a flat code base and file structure (which I don’t want to do, due to conflicting names), I would be prepared to solve my problem in this manner. I.e. if there are 100% no other discrepancies between Corona’s simulator and XCode’s simulator other than folder structure support, I’m OK with solving my problem myself. I don’t however want to do this extra work if this is not the problem, or if there are 10 other problems. [import]uid: 8145 topic_id: 2260 reply_id: 302260[/import]

Actually, I kind of misspoke. I don’t really have any other choice than to fix the problem, but I do want to be sure that I’m fixing the right problem (the folder structure thing), and that I don’t need to fix any other problems, so I can debug the parser with some confidence. [import]uid: 8145 topic_id: 2260 reply_id: 6809[/import]

The addition of subfolders was for storing assets (images, sounds, data) used in your program. I don’t believe iOS allows code in subfolders. I will file this as a bug but I believe the fix is to fail the program running in the Corona Simulator when trying to execute code from a subfolder. If it doesn’t work on a device it shouldn’t work in the Corona Simulator.

At this point in time I believe all your code must be located in the same folder as main.lua.

Thanks,
-Tom [import]uid: 7559 topic_id: 2260 reply_id: 7028[/import]

Thanks, getting consistent behaviour is indeed a fix.

However, I’ll probably write a parser that will transform my code and the ‘requires’ in it to a flat structure, so I can keep working with organized folder structures. If the fix allows a “force emulator consistency” switch or something like that so I can develop with folder structures, I’ll probably be able to release the parser if others want to write code using folder structures for logical organization.

It would probably make sense to later include something like this as a pre-build step, though, so the codebase is easier to keep track of. Good to know I don’t need to do this for my resources as well, because I have conflicting and parametrized names there :slight_smile: [import]uid: 8145 topic_id: 2260 reply_id: 7119[/import]

I’ve flattened my folder structure refactoring “requires” and whatnot, and am still getting inconsistent behavior: works fine in Corona Simulator, and some more things than before are showing up in XCode’s simulator (it now loads some static graphics).

I’ll try to debug this and write a follow up on the reason for the inconsistency. Still haven’t been able to get the simulator to print me some errors to somewhere, btw, so would still appreciate help on that subject. [import]uid: 8145 topic_id: 2260 reply_id: 7130[/import]

I can finally get my project to launch under XCode’s simulator, but coordinate transforms are now inconsistent :(. I can rotate the device and my logic repositions all my interface elements correctly under Corona’s simulator, but not under XCode’s simulator.

Oh shall I ever be free of this build debuggery :’(

I’ll return to debugging this later, and will try to make a test case that demonstrates this issue. In short, I respond to the device rotations by rotating the scene 90 degrees and repositioning it; the positioning is fine under Corona Simulator, and not under XCode simulator (in case I’m not alone in finding these inconsistencies in Corona Simulator’s behavior and someone wants to help out while I finally continue to work on my application for a bit :))

EDIT: text positioning also seems to be working differently. Without rotating the simulator, text that appears in Corona doesn’t appear in XCode’s simulator.

Devs, any comments? Positioning seems like a basic thing… maybe there’s a known issue that I could reference and fix this quicker? Or do I need to make test cases to demonstrate this and insert custom workarounds for every inconsistency I find? Any possible help with this? These are very nasty to debug due to builds taking so long, so anything that would help me would be very appreciated. [import]uid: 8145 topic_id: 2260 reply_id: 7173[/import]

Whew, found the new problem.

Corona’s simulator can ignore case in lua filenames, which is not true for XCode’s simulator. I guess again, consistently making Corona’s simulator fail because of this - is a fix.

(I had a file named numberWIthIcon - with the capital “I” in “With”; burried among 100 similar files, and without a hint as to why all of a sudden everything fails in the build version if I require certain files, along with long 10-minute build for sending resources over the internet… I feel like a ninja for finding this :))
EDIT: the parser I was talking about works, and is in Java. I think I’ll add a couple of tweaks before releasing it, but if there’s anyone with a similar problem out there, I’d be happy to provide it. Since I really prefer working with well-organized code, I’d prefer the devs not to take out the ability to work with them under the simulator, and add a transformation analogous to the one I’m doing, as a pre-compile step, like I’ve noted before, as a means of ensuring consistency between simulators. [import]uid: 8145 topic_id: 2260 reply_id: 7171[/import]

What API call are you saying has a filename case issue? Are you using the Corona SDK build or a beta build?

The Corona Simulator had issues with ignoring case of filenames but we believe those have been fixed.

Providing sample code of bugs is always a good thing because it help us determine if there are any issues and provides test code if we submit the bug to be fixed.

Thanks,
-Tom [import]uid: 7559 topic_id: 2260 reply_id: 7182[/import]

Why do you want to use the XCode simulator? Its not the real thing either reacts different from a device. You need to test on a device to make sure everything works right. [import]uid: 5712 topic_id: 2260 reply_id: 7186[/import]

@Tom, I’m using the Corona SDK build. I’m talking about the “require” keyword. Case appears to be ignored in the Corona Simulator for "require"s (e.g. require(“soMething”) would work for a file named “something.lua”, but it would halt execution in XCode’s simulator).

I’ll post a test case for the positioning issue, and while I’ll be at it I could also post one for the ignore-case issue. I’ll probably be working on my actual application for a couple of days, so I might post them only next week.

@MikeHart, Actually, I was assuming that if nothing works in Apple’s simulator, it won’t work on a device. I actually tried to test this, but after some problems with getting the app onto the devices I have available, I decided to work on fixing the issue instead of trying to get it to the device, when I was almost certain it wouldn’t work as well. If I had my own device, I’d probably see it through, but taking my colleague’s devices isn’t too convenient :frowning:

I will definitely test my new problem on the device before debugging it in XCode, if you say there could be a noticeable difference in behavior between the two.

[import]uid: 8145 topic_id: 2260 reply_id: 7201[/import]

@Wizem,

I filed the “require” bug as #1443 (internal) so it gets addressed.

Thanks,
-Tom [import]uid: 7559 topic_id: 2260 reply_id: 7388[/import]

This example demonstrates the difference between corona and xcode simulator positioning.

There are two bugs: initial placement, and the values of display.contentWidth and display.contentHeight when rotating the view.

Initial placement for the text is different in Corona’s simulator and in XCode simulator (closer to the top-right corner in Corona).

display.contentWidth and display.contentHeight trade values when going from portrait view to landscape view, but they remain the same in XCode’s simualtor. There are only two views in this example where this is visible, the default one and the one you get with cmd+leftarrow, with the others the positioning is such that the text can’t be read, but two position with inconsistent values between simulators demonstrates my point enough.

To test: launch in Corona’s simulator and XCode’s simulator side by side and rotate the view of both in the same manner to see different results.

[code]
local sizeText = display.newText("Display size: "… display.contentWidth… ", "… display.contentHeight, 0, 0, “helvetica”, 20);
sizeText:setTextColor(255,255,255);
local textGroup = display.newGroup();
textGroup:insert(sizeText);
textGroup.x, textGroup.y = 100, 100;

local function updateText()
sizeText.text = "Display size: "… display.contentWidth… ", "… display.contentHeight;
textGroup.x, textGroup.y = display.contentWidth/2 - textGroup.width/2, display.contentHeight/2 - textGroup.height/2;
end

local orientationSetter = function(event)
if(event.type == “portrait”) then
textGroup.rotation = 0;
updateText();
elseif(event.type == “landscapeRight”) then
textGroup.rotation = 90;
updateText();
elseif(event.type == “portraitUpsideDown”) then
textGroup.rotation = 180;
updateText();
elseif(event.type == “landscapeLeft”) then
textGroup.rotation = -90;
updateText();
end
end
Runtime:addEventListener(“orientation”, orientationSetter);
[/code] [import]uid: 8145 topic_id: 2260 reply_id: 7417[/import]

Thanks for posting your sample code.

There are two things going on here:

  1. There is a bug that I filed a week ago where the contentHeight and contentWidth are not correct when the device is rotated AND auto-rotation is not enabled (no orientation settings in build.settings file). This a Corona Simulator issue.

  2. The Xcode simulator and the device work differently in regards to when orientation events are received. When you run the Corona Simulator, you only get orientation events when you rotate the simulator. In Xcode simulator and on the device you may get an orientation event when the app starts, even if no orientation change occurred. In you sample code you are setting the text to x=100,y=100 at start time but centering the text when an orientation event occurs. I believe you are getting an orientation event on the Xcode simulator which is centering the text. You can test this theory by commenting out the EventListener and see if the text location on the Xcode simulator matches the Corona simulator.

Also note that the font “helvetica” should by “Helvetica”. The font names are case-sensitive and the font will fall back to the systemFont if it’s not correct. It also will affect the font size too (another logged bug).

Thanks,
-Tom [import]uid: 7559 topic_id: 2260 reply_id: 7430[/import]

@Mike, it’s true that you still need to test on the device b4 shipping.

However, there are some cases where iterating on the Xcode simulator can help speed up your dev time. The best example is folks who are integrating Corona graphics with native UI like web popups, text fields, alerts, etc. [import]uid: 26 topic_id: 2260 reply_id: 8354[/import]