- Home /
Binnary Formatter working nicely in editor - but I have crashing after scene load paramteras on both iOS and Android device
Hi guys,
We appreciate your help as we are stuck in middle of nowhere. Usually all things we find on this more than usefull forum, but right now - we read for last 2 weeks, our budget for project are going up - we breaking a costs and have finished very large project until very end and STUCK...yes stuck because of some errors which can find it out :( We are so depressed, we doing every day until 5am - stripping code trying to find solutions but no way and there is nothing on internet about this errors.
Firstly we have 2 classes - 1 arrays of vehicles with parametears (bhp, weight...) and 2nd playerInfo class. We have standard Binnary formater - with whom we have problem already of missing / before file name - but right now as we implement Mono.Reflect on iOS and use preowned parameters scene works ok on mobile. But if I create class of cars JIT and save it and back from show room to garage...guess what it bringing me for 2 weeks same errors - he freeze iphone5 device (up to then runs smoothly) and Xcode bring me bunch of treads and this is always standard - also Android log give me all the time Null reference exceptions as something which I get it from car-script are not right - or array passing maximum no. I'm not sure - what is about - we have XML for multilanguage -but its works - we have tested and confirmed that loading - saving scene working (or maybe part of it) here is vehicle class we have for every car( when I preset it it works fine): using UnityEngine; using System.Collections; using System.Collections.Generic;
[System.Serializable]
public class Vehicles {
private int carModel;
private int tier;
private float bhp;
private float weight;
private float grip;
private float gearbox;
private float brakes;
private float steering;
private int stageBrakes;
private int stageEngine;
private int stageGearBox;
private int stageSteering;
private int stageNOS;
private int stageTurbo;
private int stageTyre;
private int stageBody;
private float rating;
public Vehicles (int carModel, int tier, float bhp, float weight, float grip, float gearbox, float brakes, float steering)
{
Bhp=bhp;
Weight=weight;
Grip=grip;
Gearbox=gearbox;
Brakes=brakes;
Steering=steering;
CarModel=carModel;
Tier = tier;
//postaviti sve levele na 1 pri kupovini kola
stageBrakes=1;
stageEngine=1;
stageGearBox=1;
stageSteering=1;
stageNOS=1;
stageTurbo=1;
stageTyre=1;
stageBody=1;
rating=0;
}
public int Tier
{
get
{
return tier;
}
set
{
tier = value;
}
}
public float Rating //rating sistem
{
get
{
rating = bhp/5+steering/70+brakes/80+weight/33+gearbox/40;
return rating;
}
set
{
rating = value;
}
}
public float Gearbox
{
get
{
return gearbox;
}
set
{
gearbox = value;
}
}
public int StageBody
{
get
{
return stageBody;
}
set
{
stageBody = value;
}
}
public int StageTyre
{
get
{
return stageTyre;
}
set
{
stageTyre = value;
}
}
public int StageTurbo
{
get
{
return stageTurbo;
}
set
{
stageTurbo = value;
}
}
public int StageNOS
{
get
{
return stageNOS;
}
set
{
stageNOS = value;
}
}
public int StageSteering
{
get
{
return stageSteering;
}
set
{
stageSteering = value;
}
}
public int StageGearBox
{
get
{
return stageGearBox;
}
set
{
stageGearBox = value;
}
}
public int StageEngine
{
get
{
return stageEngine;
}
set
{
stageEngine = value;
}
}
public int StageBrakes
{
get
{
return stageBrakes;
}
set
{
stageBrakes = value;
}
}
public int CarModel
{
get
{
return carModel;
}
set
{
carModel = value;
}
}
public float Bhp
{
get
{
return bhp;
}
set
{
bhp = value;
}
}
public float Weight
{
get
{
return weight;
}
set
{
weight = value;
}
}
public float Grip
{
get
{
return grip;
}
set
{
grip = value;
}
}
public float Brakes
{
get
{
return brakes;
}
set
{
brakes = value;
}
}
public float Steering
{
get
{
return steering;
}
set
{
steering = value;
}
}
}
here is seconds part binnary formater we use for that:
void SaveCarData() {
var b = new BinaryFormatter();
var f = File.Create(Application.persistentDataPath + imeFajlaWTRData );
for (int i = 1; i <= brojMojihVozila; i++)
b.Serialize(f, mojaVozila[i]);
f.Close();
}
void LoadSavedCarData()
{
//LOAD ako je vec otvarano
if(File.Exists(Application.persistentDataPath + imeFajlaWTRData )) {
var b = new BinaryFormatter();
var f = File.Open(Application.persistentDataPath + imeFajlaWTRData , FileMode.Open);
**for (int i = 1; i <= brojMojihVozila; i++)
mojaVozila[i] = (Vehicles) b.Deserialize(f);**
f.Close();
}
just to mention that I start usage of vehicles from 1 - so 1st array was never initialized - does it matter on mobile? (I realized that I do not test with that option setup).
Guy, we really appreaciate if you find a time, I know you have job to do's but please if you have similar issue we will not spent weeks after anyhow hard work for this kind of stuff.
All the best and thanks!
Do you get any message written into the console? Have you tried symbolicating the code, so the call stacks make more sense?
Hi Graham, I just have this
1 ArgumentNullException: Argument cannot be null.
Parameter name: obj
at System.Runtime.Serialization.ObjectIDGenerator.GetId (System.Object obj, System.Boolean& firstTime) [0x00000] in :0
at $$anonymous$$ain$$anonymous$$enu1.SaveCarData () [0x00000] in :0
at $$anonymous$$ain$$anonymous$$enu1.OnGUI () [0x00000] in :0
2 ArgumentNullException: Argument cannot be null.
Parameter name: obj
at System.Runtime.Serialization.ObjectIDGenerator.GetId (System.Object obj, System.Boolean& firstTime) [0x00000] in :0
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph) [0x00000] in :0
at $$anonymous$$ain$$anonymous$$enu1.SaveCarData () [0x00000] in :0
at $$anonymous$$ain$$anonymous$$enu1.OnGUI () [0x00000] in :0
3 IOException: Sharing violation on path /var/mobile/Applications/2BA371E4-AC97-4FF3-9318-C6A656008FF2/Documents/333eeee3.wtr
(this file is wtr file for saving car data and savings happening after buying and getting back to 1st scene
main issue which I find is that:
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteQueuedObjects
this is what I usually get (10x in one xcode running):
IOException: Sharing violation on path /var/mobile/Applications/2BA371E4-AC97-4FF3-9318-C6A656008FF2/Documents/333eeee3.wtr
at System.IO.FileStream..ctor (System.String path, File$$anonymous$$ode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in :0
at System.IO.FileStream..ctor (System.String path, File$$anonymous$$ode mode, FileAccess access, FileShare share, Int32 bufferSize) [0x00000] in :0
at System.IO.File.Create (System.String path, Int32 bufferSize) [0x00000] in :0
at System.IO.File.Create (System.String path) [0x00000] in :0
at $$anonymous$$ain$$anonymous$$enu1.SaveCarData () [0x00000] in :0
at $$anonymous$$ain$$anonymous$$enu1.OnGUI () [0x00000] in :0
and CarSavedData() is saving method from:
void SaveCarData() {
var b = new BinaryFormatter();
var f = File.Create(Application.persistentDataPath + imeFajlaWTRData );
for (int i = 1; i <= broj$$anonymous$$ojihVozila; i++)
b.Serialize(f, mojaVozila[i]);
f.Close();
}
Appreciate your help!
PS. Also which I think maybe caused that error is as I do saving of array and maybe it crash on mobile:
for (int i = 1; i <= broj$$anonymous$$ojihVozila; i++) b.Serialize(f, mojaVozila[i]);
Just to confirm that everythings working nicely in editor and when I put preowned cars (not initialized in buying) adn games load all that data and selected player and runs game- but as soon as it back to the garage it NRE (null ref.exception).