Variable return runtime error - objective-c

I am making an iPhone app with cocos2d and Everytime I try to return a variable from a function I get a run time error on the code below...
GB2ShapeCache *cache = [GB2ShapeCache sharedShapeCache];
//EXC_BAD_ACCESS run time error here
*eggFixture = [cache addFixturesToBody:body forShapeName:#"egg3"];
I don't know what I am doing wrong... here is the code for addFixturesToBody...
-(b2Fixture) addFixturesToBody:(b2Body*)body forShapeName:(NSString*)shape
{
BodyDef *so = [shapeObjects objectForKey:shape];
assert(so);
b2Fixture *Fixi;
FixtureDef *fix = so->fixtures;
while(fix)
{
Fixi = body->CreateFixture(&fix->fixture);
fix = fix->next;
}
return *Fixi;
}
and here I define my variable eggFixture
b2Fixture *eggFixture;
and here is where I try to use the b2fixture eggFixture later
for(pos = _contactListener->_contacts.begin();
pos != _contactListener->_contacts.end(); ++pos) {
MyContact contact = *pos;
if ((contact.fixtureA == locations.platformFixture && contact.fixtureB == eggFixture) ||
(contact.fixtureA == eggFixture && contact.fixtureB == locations.platformFixture)) {
NSLog(#"Ball hit bottom!");
}
}
Any help? thankyou :)

Looks like body is nil. It will certainly crash here when body is nil:
Fixi = body->CreateFixture(&fix->fixture);
This article has some tips for debugging issues like EXC_BAD_ACCESS.

Related

HTTP request won't get data from API. Gamemaker Studio 1.4.9

I'm trying to figure out how to get information from a dictionary API in Gamemaker Studio 1.4.9
I'm lost since I can't figure out how to get around the API's server block. All my return shows is a blank result.
Step Event:
if(keyboard_check_pressed(vk_space)){
http_get("https://api.dictionaryapi.dev/api/v2/entries/en/test");
}
HTTP Event:
var requestResult = ds_map_find_value(async_load, "result");
var resultMap = json_decode(requestResult);
if(resultMap == -1)
{
show_message("Invalid result");
exit;
}
if(ds_map_exists(resultMap,"word")){
var name= ds_map_find_value(resultMap, "word");
show_message("The word name is "+name);
}
Maybe my formatting is wrong? It's supposed to say the word test in the show_message function, but again, all I get returned is a blank result.
Any help would be appreciated, thanks!
You can see through the debugger that the data is coming from the server. But your code does not correctly try to retrieve the Word.
https://imgur.com/a/icQSnnx
This code gets this word
show_debug_message("http received")
var requestResult = ds_map_find_value(async_load, "result");
var resultMap = json_decode(requestResult);
if(resultMap == -1)
{
show_message("Invalid result");
exit;
}
if(ds_map_exists(resultMap,"default")){
var defaultList = ds_map_find_value(resultMap, "default")
var Map = ds_list_find_value(defaultList, 0)
var name= ds_map_find_value(Map, "word");
show_message("The word name is "+name);
}

Improved / efficient code for multiple if - React Native

I´m a technical project manager coordinating developers. My coding skills are limited and so I align with my devs on logical structure. For a mobile app (React Native to serve Android and iOS) we are currently developing user current location logic. Turned out we have specific Android and iOS settings, what may require native developmetn for location service handling.
I´m currently reviewing the following pseudocode and, besides others, concerned about the MULTIPLE IF statements and thinking if there is a more efficient way, as here we seem to jump into every IF, even when location is set already before.
I think there can be something like "until", "break" or similar .. and maybe relevant to consider the specific dev language, React Native in that case?
Any help, as pseudocode or if possible to make it specific already considering React Native, is very much appreciated.
Many thanks in advance!
Code
////Central Location Service to get current location.
var currentLocation;
var locationType
if Android {
DEFINED_ACCURACY = QUALITY_BALANCED_POWER
} else id iOS {
DEFINED_ACCURACY = kCLLocationAccuracyHundredMeters
}
DEFINED_DISTANCE = 3000
function startLocationService(){
var locationservice = LocationService()
locationservcie.accuracy = DEFINED_ACCURACY
locationservcie.distance = DEFINED_DISTANCE
locationservcie.startListnertoLocationUpdate() {
cacheData(location, currentTime);
currentLocation = location
}
}
function getLocationFromLocationService() {
if locationServcieEnabled == false
return NULL;
if locationPermissionGranted == false
return NULL;
return currentLocation;
}
function getCurrentLocation() {
var lcoation = NULL;
var accuracy = Not_defined;
lcoation = getLocationFromLocationService() //GPS, network
locationType = locationService
if lcoation == NULL {
locationdata == getLastKnownLocation()
if locationdata.Age < DEFINED_DURATION {
location = locationdata.location
locationType = locationService
}
}
if location == NULL {
location == getCachedLocationWithin24Hour()
locationType = locationService
}
if location == NULL {
location = getLocationfromTelephony()
locationType = other
}
if location == NULL {
if permissionToUseBilling == false {
askForPermissionToUseBilling()
}
location = getLocationFromBillimg()
accuracy = other
}
if location == NULL {
location = getLocationOfDEfaultCountry()
accuracy = other
}
return location, Other
}
I think you can use switches to cover different cases from javascript.
Probably your dev team knows, but did not want to bring it into pseudo code?
const location = getLocationFromLocationService() ;
switch (location) {
case 'NULL':
//DO SOMETHING WHEN NULL;
break;
case 'New York':
// DO SOMETHING WHEN New York;
// No break leads to run also into the next case
case 'Bern':
console.log('I love nice cities.');
break;
default:
console.log(`Sorry, we are out of ${location}.`);
}
Interestingly you seem to have multiple times the same if case?
Maybe you will to nest it or have to use a switch with multiple expressions.
case ("Bern" && "ANOTHERExpression to be true"):
Link to switch documentation
Please don't underestimate your dev team. ;-)

Read 'hidden' input for CLI Dart app

What's the best way to receive 'hidden' input from a command-line Dart application? For example, in Bash, this is accomplished with:
read -s SOME_VAR
Set io.stdin.echoMode to false:
import 'dart:io' as io;
void main() {
io.stdin.echoMode = false;
String input = io.stdin.readLineSync();
// or
var input;
while(input != 32) {
input = io.stdin.readByteSync();
if(input != 10) print(input);
}
// restore echoMode
io.stdin.echoMode = true;
}
This is a slightly extended version, key differences are that it uses a finally block to ensure the mode is reset if an exception is thrown whilst the code is executing.
The code also uses a waitFor call (only available in dart cli apps) to turn this code into a synchronous call. Given this is a cli command there is no need for the complications that futures bring to the table.
The code also does the classic output of '*' as you type.
If you are doing much cli work the below code is from the dart package I'm working on called dcli. Have a look at the 'ask' method.
https://pub.dev/packages/dcli
String readHidden() {
var line = <int>[];
try {
stdin.echoMode = false;
stdin.lineMode = false;
int char;
do {
char = stdin.readByteSync();
if (char != 10) {
stdout.write('*');
// we must wait for flush as only one flush can be outstanding at a time.
waitFor<void>(stdout.flush());
line.add(char);
}
} while (char != 10);
} finally {
stdin.echoMode = true;
stdin.lineMode = true;
}
// output a newline as we have suppressed it.
print('');
return Encoding.getByName('utf-8').decode(line);
}

How to use ngx_write_chain_to_temp_file correctly?

I am writing nginx module which construct nginx chain then write this chain buffer to nginx temporary file to use it later (just after write happen). I've been searching every page and the only solution come up is the one bellow:
// Create temp file to test
ngx_temp_file_t *tf;
tf = ngx_pcalloc(r->pool, sizeof (ngx_temp_file_t));
if (tf == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
tf->file.fd = NGX_INVALID_FILE;
tf->file.log = nlog;
tf->path = clcf->client_body_temp_path;
tf->pool = r->pool;
tf->log_level = r->request_body_file_log_level;
tf->persistent = r->request_body_in_persistent_file;
tf->clean = r->request_body_in_clean_file;
// if (r->request_body_file_group_access) {
// tf->access = 0660;
// }
if (ngx_create_temp_file(&tf->file, tf->path, tf->pool, tf->persistent, tf->clean, tf->access) != NGX_OK) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
if (ngx_write_chain_to_temp_file(tf, bucket->first) == NGX_ERROR) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
This code does not return NGX_ERROR, is this meant nginx successful write temporary file into client_body_temporay_path? It the answer is yes, after that, I use fopen to open file, the file is not exist?
Can anyone please give me the right solution to handle ngx_write_chain_to_temp_file?
I find myself the solution
ngx_temp_file_t *tf;
tf = ngx_pcalloc(r->pool, sizeof (ngx_temp_file_t));
tf->file.fd = NGX_INVALID_FILE;
tf->file.log = nlog;
tf->path = clcf->client_body_temp_path;
tf->pool = r->pool;
tf->persistent = 1;
rc = ngx_create_temp_file(&tf->file, tf->path, tf->pool, tf->persistent, tf->clean, tf->access);
//ngx_write_chain_to_file(&tf->file, bucket->first, bucket->content_length, r->pool);
ngx_write_chain_to_temp_file(tf, bucket->first);
The only thing I cannot understand is if I set tf->persistentto false (0), after the file created, I cannot read from it even if I've not passed response to output_filter yet.

How to get output of a webpage in ActionScript 2

For Actionscript 2.0
Let's say this page
www.example.com/mypage
returns some html that I want to parse in Actionscript.
How do i call this page from Actionscript while getting back the response in a string variable?
use LoadVars():
var lv = new LoadVars();
//if you want to pass some variables, then:
lv.var1 = "BUTTON";
lv.var2 = "1";
lv.sendAndLoad("http://www.example.com/mypage.html", lv, "POST");
lv.onLoad = loadedDotNetVars;
function loadedDotNetVars(success)
{
if(success)
{
// operation was a success
trace(lv.varnameGotFromPage)
}
else
{
// operation failed
}
}
//if you dont want to send data, just get from it, then use just lv.Load(...) instead of sendAndLoad(...)
I understand. Use this code then:
docXML = new XML(msg);
XMLDrop = docXML.childNodes;
XMLSubDrop = XMLDrop[0].childNodes;
_root.rem_x = (parseInt(XMLSubDrop[0].firstChild));
_root.rem_y = (parseInt(XMLSubDrop[1].firstChild));
_root.rem_name = (XMLSubDrop[2].firstChild);
var htmlFetcher:LoadVars = new LoadVars();
htmlFetcher.onData = function(thedata) {
trace(thedata); //thedata is the html code
};
Use:
htmlFetcher.load("http://www.example.com/mypage");
to call.
I suppose you could use:
page = getURL("www.example.com/mypage.html");
And it would load the page contents on the page variable.