Why the IRtcEngine instance is not created? - unity3d

i'm trying to implement a voice chat in my Unity game using agora.io. I followed the official start up tutorials and I put the code below in a script attached to an empty Gameobject in the scene:
My simple start up script
So, at the Start, the IRtcEngine instance should be created as I call the IRtcEngine.GetEngine(agoraAppID) method. The problem is that, instead od returnig the instance, this method prints an error log: "Create engine failed, error code: -7"
I looked up what the error code 7 means: "A method is called before the initialization of RtcEngine. Ensure that the RtcEngineinstance is created and initialized before calling the method".
So I tried commenting everything but the line in which the IRtcEngine.GetEngine(agoraAppID) method is called, but the error still pops up. It pops up even when I play the agora demo scene "HelloUnity".
I also tried removing the agora package and importing it again. It worked because after that the instance was created correctly, but after a few times, the error started popping up again.
Unity version: 2020.3.3f1
Agora version: 3.3.1.71
What could the problem be? Is it a bug?

I had the same issue with the same error code. Closing all Unity instances and rebooting my computer was helped me.
Usually, it happens if you don't leave the channel properly. So, putting
rtcEngine?.LeaveChannel()
to
OnDestroy()
may be a good solution.

should look something like this. don't forget the variable declaration up top.
public class Launch : MonoBehaviour
{
public IRtcEngine mRtcEngine;
void Start()
{
string agoraAccountId = "4ca78bc86f23hhhhhhhhh4444444444";
if (mRtcEngine != null)
{
Debug.Log("Agora engine exists already!!");
return;
}
mRtcEngine = IRtcEngine.GetEngine(agoraAccountId);
I suggest you join the Agora slack channel (it is easy to join) where you can get answers quickly.

Please take a look at the Demo project code and watch out how the sample app handles the life cycle in Unity. In your simple script, there is no clean up code on destroy. You left certain socket/ports open on the system. That's why when you get some success on a fresh install but not the subsequent run.

Related

How do I prevent my app from running in the "recent menu" on Android 12

Android 12 introduced the behavior where the last app you had active are continuing to run when inside the recent menu. I'm wondering if there's a flag or something to put in AndroidManifest file to prevent this behavior as it's conflicting with some logics in our app (which works fine for Android < 12). I've googled but it's hard to find unless you know exactly what this "feature" is called.
Steps:
Start app
Open recent menu
Observe that you can interact and that the app is still running as if you had it open/active
Why is this a problem? Because a user is now able to force quit the app (swiping it away) without entering the "paused" state in our game (using Unity) meaning some save logic won't run.
This can be worked around in one way or another, but for now I would like to just pause the app in recent menu if possible (our app has zero reason for being active in recent menu).
EDIT:
As #WyattL mentioned in his answer, android:excludeFromRecents="true" might work, but it will cause drop in playtime and retention of the game and would prefer to have a more proper solution to this "unnecessary" feature of Android 12.
I can't be sure without testing on every phone as it seems the issue varies by device (thanks Ruzihm), but if opening the Recent Apps screen generates an OnApplicationFocus() call, this would provide a solution.
In an active MonoBehaviour:
private void OnApplicationFocus( bool focus )
{
if( focus ) {
UnpauseLogic();
}
else {
PauseLogic();
SaveLogic();
}
}
(It might also be worth trying OnApplicationQuit() in case it's called on specific devices during a swipe termination, but in my own tests it was never called.)
According to some brief research, did you try adding
<activity>
...
android:excludeFromRecents="true"
android:label=""
...
</activity>
to the AndroidManifest.xml?

Memory Access Out of Bounds - WebGL

I was getting this error when I try to load my Web game:
My game is loaded at this domain:
Highest Flavor Website Link
This is my project settings at the time of build export:
Please give me some suggestion to solve this problem.
This error happened to me due to using the dynamic keyword. After replacing all my dynamic types with object the error was gone. Apparently the dynamic keyword is not supported on WebGL builds.
I've finally fixed the same error in my project. Here is what i did:
Narrow down the line of code that crashes WebGL.
Go through the painfull process of pinpointing the line of code that
is the source of the error. I had this "luck" that error occured
when I've hit button and tried to load UIScene in Addition mode. So
at first I found the script in the scene which when disabled got rid
of the crash. Then I've repeated the steps and digged deeper into
lines. After 2 hours of builds, comments etc I've found that the code
was not working was setting the new color for UnityEngine.UI.Image.
Which was pretty weird because in playmode everything worked ok.
Find solution. I think my solution might not be universal but I think there is something going in the Unity gameloop/lifecycle when running WebGL. The source of the problem was that i set the field that was storing my UI.Image in the Start method and then in some function I've tried to change the color.
Property was not exposed in inspector.
public class ModuleUI : MonoBehaviour
{
Image qualityBG;
void Start()
{
qualityBG = GetComponent<Image>();
}
...
then this line below was the cause of the crash
public void Set(Module module)
{
...
qualityBG.color = module.Quality.ToColor();
}
Fixing - so I've added [SerializeField] attribute to the field and set it up in editor, dragged the Image into the inspector slot. An it fixed it. I suspect that WebGL build might perform some methods in different order, or maybe the multipleScene loaded together might to do with it. I'm not sure but the field was not set properly with previous code fot WebGL build.
Bonus:
I've also fixed some issues that was not critical (not crushing WebGL game) but not working properly as expected in playmode. This also has got to do with trying to set some object in Start() method and then doing something on them. The collection was not set up (probably null) in WebGL.
EffectUI[] effects;
Start()
{
effects = GetComponentsInChildren<EffectUI>();
}
void HideAllEffects()
{
if (effects != null)
for (int i = 0; i < effects.Length; ++i)
effects[i].gameObject.SetActive(false);
}
And this also started working when I've added [SerializeField] to effects and hook it up in the scene...
Hope this will help some of you guys & gals!
To run this build within the web browser - I have removed all extra things related code those can't work within the web build like in-app purchase, advertisements, leaderboard, native sharing etc...
After these things code removed from the project, I uploaded the exported build content to my hosting. Then after it started working properly.

Uncaught exception: abort(80) at jsStackTrace - Airconsole Unity

When i test a preview of the game in the Developer Console, the following error occurs in the browser. This occurs at the moment when it tries to request persistent data from the player. Someone knows what it is? NOTE* During development on Windows and in tests with Open Exported Port everything went well.
Complete log:
https://drive.google.com/open?id=1R4dJx4NSDDMbLirLENz_r0cgoedmS-tk
I would like to get the saved data from the main player with this code.
public void RequestPersistentData()
{
List<string> connectedUids = new List<string>();
connectedUids.Clear();
connectedUids.Add(AirConsole.instance.GetUID(AirConsole.instance.GetMasterControllerDeviceId()));
AirConsole.instance.RequestPersistentData(connectedUids);
}
First the scene is executed with AirInputManager.cs. Then the main menu scene where the MenuController script is executed is loaded (this is where the error happens). Finally, if the player finishes the game the data is stored on the champion screen where the ChampionManage.cs script runs.
More code: github
I solved it that way. In WebGL Player settings -> Publishing Settings-> Compression Format, change Gzip to Disabled. For some reason Gzip takes a long time to extract the necessary files when loading the game. And make sure that the name of the root folder where you will build the project has no blank space. "Crazy Game" (Bad). CrazyGame (Good).
To ensure it will work, make sure that the script execution order responsible for managing AirConsole runs at least -90 in Default Time. You can use the Script Execution Order settings (menu: Edit > Project Settings, then select the Script Execution Order__ category).

Unity - Deprecated EditorApplication

I just have updated my Unity to 5.3.1 and it seems like EditorApplication class is already deprecated. The Unity suggests me to use instead the EditorSceneManager.OpenScene but looks like it's not returning of type bool anymore. Therefore causing my game to stop compiling.
Any help about this?
Thanks!
Usually due to deprecated code unity itself offers some changes in your code you can make a backup and try that if unity informs you of it ,but if you want to know if it has been loaded or not you can use its return value which is a struct of type Scene.
SceneManagement.Scene newScene = EditorSceneManager.OpenScene("myScene");
if(newScene.isLoaded) {
//do something
}
There is another method also named IsVaild You Can try that too.
further doc :
http://docs.unity3d.com/ScriptReference/SceneManagement.Scene.html
It's hard to help you without any information on what you actually want to do... This link may help though, it's about upgrading to Unity 5.3.

Eclipse - Blackberry SDK - Debugging on device: "details unavailable - not supported by VM"

I'm having a strange problem while debugging my Blackberry Application on a real device (BB Bold 9700). When I debug the same application within the BB emulator, the app runs fine, but when I run it on the real device, the app behaves differently (custom painting goes completely wrong). What's even worse is that my Eclipse environment seems to be unable to view live objects correctly while being at a break point (debug time).
I've added a screenshot to illustrate the strange behaviour:
As you can see, the app stops at the breakpoint within the IF statement, but the Variables pane says that the variable "methodName" equals null. Moreover, when I want to look at the variable "methodArguments" which is of type org.json.me.JSONArray, it says "details unavailable - not supported by VM".
Does anyone know what's going on here? My app works great on the emulator, but it's currently useless on the real device.
Thanks in advance!
I think I fixed it:
The problem was that I was laying out Fields on a manager that wasn't yet added to the viewstack.
What did the trick for me was overriding onDisplay() in the manager that contained the Fields that were displayed wrong:
protected void onDisplay()
{
//Make sure superclass is called
super.onDisplay();
/*You have to call "this.setDirty(true)" when you perform layout on a
*manager that isn't added to the viewstack. Then you can use
*"this.isDirty()" to determine whether you need to re-layout the fields
*when the manager becomes visible.*/
if(this.isDirty())
{
//I'm not sure if I need to use "invokeAndWait" and not "invokeLater"
UiApplication.getUiApplication().invokeAndWait(new Runnable()
{
public void run()
{
for (int i = 0; i < getFieldCount(); i++)
{
/*This (custom) function makes sure the Field gets its
*size and position*/
layoutItem(getField(i));
}
}
});
//Make sure you set "dirty" to false, to make sure this only happens once
this.setDirty(false);
}
}
If anyone has a better solution, I'd be glad to hear it (and maybe improve my app).
org.json.me.JSONArray, it says "details unavailable - not supported by VM".
the JSON related stuff is not available on device running 4.5 and 4.6 BB OS. Import it into the code.
Download it from here.
https://github.com/douglascrockford/JSON-java
it is available as Open Source and then use it into your applications.