Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-14-2010, 04:03 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 18
william24 is on a distinguished road
Default Success with Random Questions, but....

I have successfully created a simple quiz that takes questions/answers from a text file with no problems. I have played around with adding a randomization feature so that the questions are given randomly. I have finally succeeded in doing that, however, I have noticed that at some point in the quiz, the app closes. It appears to close at different points in the quiz (sometimes after the third question, sometimes after the ninth question....never after the same question). Again, I did not have this problem until I added arc4random.

Any ideas of what might be causing this and where I should look to fix this? I am very excited in what I have completed, but this setback is throwing me off.

Thanks in advance!
william24 is offline   Reply With Quote
Old 11-14-2010, 04:24 PM   #2 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 90
LittleX1 is on a distinguished road
Default

I guess memory problems. What does the console say? Any errors?

If you're sure, that the randomization part is responsible for the problem, you could post some of your code.
LittleX1 is offline   Reply With Quote
Old 11-14-2010, 04:35 PM   #3 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Regarding possible memory leak, did you check if your app is receiving the memory warning (didReceiveMemoryWarning)?

Also, did you run Instruments to check if you have a memory leak.
baja_yu is offline   Reply With Quote
Old 11-14-2010, 04:55 PM   #4 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 18
william24 is on a distinguished road
Default Instruments...

Quote:
Originally Posted by baja_yu View Post
Regarding possible memory leak, did you check if your app is receiving the memory warning (didReceiveMemoryWarning)?

Also, did you run Instruments to check if you have a memory leak.
This will show how new I am to all of this, but I was unaware of running Instruments to check for a memory leak. I did run it....app stopped...but did not seem to indicate a memory leak (although I may not be looking in the correct part). Anything else I should check?
william24 is offline   Reply With Quote
Old 11-14-2010, 04:56 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 18
william24 is on a distinguished road
Default Unsure

Quote:
Originally Posted by LittleX1 View Post
I guess memory problems. What does the console say? Any errors?

If you're sure, that the randomization part is responsible for the problem, you could post some of your code.
I'm not sure if it is directly responsible...I just know that the problem didn't occur until I added that code. I may post later after I look at a few other items.
william24 is offline   Reply With Quote
Old 11-14-2010, 05:18 PM   #6 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 90
LittleX1 is on a distinguished road
Default

Quote:
Originally Posted by william24 View Post
This will show how new I am to all of this, but I was unaware of running Instruments to check for a memory leak. I did run it....app stopped...but did not seem to indicate a memory leak (although I may not be looking in the correct part). Anything else I should check?
You might also check your randomization code again.. Maybe based on the random code, you're trying to access an object which doesn't exist.
LittleX1 is offline   Reply With Quote
Old 11-14-2010, 05:33 PM   #7 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Check these two texts out Loading… and Loading…

Check out the other documents too. Apple really has excellent documentation, brilliantly written and easy to read, with lots of sample code. And keep in mind I'm not that big of a fan of Apple
I actually read about 3000 pages of it before starting on "hello world", and there's lots more to go through
baja_yu is offline   Reply With Quote
Old 11-14-2010, 05:47 PM   #8 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 18
william24 is on a distinguished road
Wink

Quote:
Originally Posted by LittleX1 View Post
You might also check your randomization code again.. Maybe based on the random code, you're trying to access an object which doesn't exist.
I have discovered that it is a NSRange Exception....index is beyond bounds. I can only assume that it was my code and that what was generated was beyond what I had in the text file (?).

The following is what I have. It probably isn't pretty, but I am just trying to work on small things and learn.

int i;
int j;

i = 15; i > 0;

j = arc4random() % i;
questionNumber = (j + 1);


NSInteger row = 0;
if (questionNumber < 1);
{
row = 0;
}

if(questionNumber == 1);
{
row = questionNumber - 1;
}

if(questionNumber > 1);
{
row = ((questionNumber - 1) * 6);
}

Again, it probably isn't pretty, but I did finally get something to work...if only for a little while. Any ideas on how to make this work? I appreciate the help.
william24 is offline   Reply With Quote
Reply

Bookmarks

Tags
app crashes, random

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 374
7 members and 367 guests
apatsufas, Kirkout, lzwasyc, MarkC, Sami Gh, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:43 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0