we are facing a crash in our game during prefab instatiation, below is the crashlog.
Unknown:-2 libunity.00124d68 // resolves to GameObject::QueryComponentByType(Unity::Type const*) const
Unknown:-2 libunity.001de6d8 // resolves to CollectAndProduceClonedIsland(Object&, Transform*, vector_map<int, int, std::less<int>, stl_allocator<std::pair<int, int>, (MemLabelIdentifier)1, 16> >&)
Unknown:-2 libunity.001df368 // resolves to CloneObjectImpl(Object*, Transform*, vector_map<int, int, std::less<int>, stl_allocator<std::pair<int, int>, (MemLabelIdentifier)1, 16> >&)
Unknown:-2 libunity.001df274 // resolves to CloneObject(Object&)
Unknown:-2 libunity.00a56340 // resolves to Object_CUSTOM_Internal_CloneSingle(MonoObject*)
Unknown Unknown.0000ca04
Unknown:-2 Object.Internal_CloneSingle
<0x00030>:48 Object.Instantiate
<0x002eb>:747 DialogManager.CreateAndShowDialog
<0x0024b>:587 DialogManager.TryToShowNextDialog
<0x0013f>:319 DialogManager.Update
Unknown:-2 Object.runtime_invoke_void__this__
Unknown:-2 libmono.00021f23
mono_runtime_invoke:136 libmono.mono_runtime_invoke
Unknown:-2 libunity.004ec6a0
Unknown:-2 libunity.004dab50
Unknown:-2 libunity.001e1300
Unknown:-2 libunity.0031f8a8
Unknown:-2 libunity.005efc68
Unknown:-2 libunity.005f2a7c
Unknown:-2 base.000839fb
basically this looks like a crash happening while instantiating a prefab.
Does our unity version has anything to do with this? its 5.6.4p4.
We are loading this from an asset bundle. Is that the reason by any chance?
We are Instantiating this from a co-routine. Can this happen because of this?
Could this be a memory issue?
Please let me know if anyone has some context on this crash.
Thank you.
Related
I have a swift app where I use the native C++ lib and there is a method that takes as an argument void * on MTLTexture
void RenderAPI_Metal::EndModifyTexture(void* textureHandle)
{
id<MTLTexture> tex = (__bridge id<MTLTexture>)textureHandle;
...
}
and Swift call is
func foo(texture: MTLTexture) {
...
EndModifyTexture(&texture)
...
}
So, on the Swift side, I call the method and pass a pointer, and then on the C++ side when I try to cast it back I got an error
om.apple.scenekit.scnview-renderer (20): EXC_BAD_ACCESS (code=1, address=0x0)
So, according to the error looks like the pointer is nil, however, when I check it in the debug I see that it has an address void* textureHandle is 0x0000000280a08178
What is the problem here? Why did I pass MTLTexture and then I got a problem casting it back?
P.S.
I can't change the implementation, C++ method should receive void*
Thanks to #MartinR I found the solution here
https://stackoverflow.com/a/33310021/5709159
exactly this method helps me to solve the problem
func bridgeRetained<T : AnyObject>(obj : T) -> UnsafeRawPointer {
return UnsafeRawPointer(Unmanaged.passRetained(obj).toOpaque())
}
I'm going over a programming example in a book on Swift and have an initializer to an SKScene that looks like this:
class GameOverScene: SKScene
{
init(size:CGSize,won:Bool,time:CFTimeInterval)
{
...........
}
}
This initializer is then called in another part of the program with the following line:
let gameOverScene=GameOverScene(size:self.size,won:true,time:CFTimeInterval)
It seems that this should all be fairly simple but then I get this strange looking error that says:
Cannot convert value of type 'CFTimeInterval.Type (aka 'Double.Type')
to expected argument type 'CFTimeInterval' (aka 'Double').
Does anyone know (1) what this error means and (2) how to correct it?
CFTimeInterval is a type. It's not an instance of CFTimeInterval that you can pass into that function.
CFTimeInterval is a typealias to Double. So this function expects a value of type Double. 1.0, NaN, -1.5, Double.pi are all valid instances of Double. But what you're trying to give it is CFTimeInterval, which refers to the type itself.
This, for example, would work:
let gameOverScene = GameOverScene(size: self.size, won: true, time: 1.23)
First, let me thank everyone in the SO community in advance for your help in getting me out of this jam.
My app hits a runtime error, and I've isolated the line causing the error.
When I attempt to add two NSDecimalNumber variables use the .adding method, I receive this "unrecognized selector sent to instance" error:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSCFNumber
decimalNumberByAdding:]: unrecognized selector sent to instance
0x608002c361a0'
I've created dummy NSDecimalNumber variables to try and debug this issue, and they seem to work fine when adding. However, when working with my NSManagedObject variables (result and newTransaction) which have NSDecimalNumber variables, I run into this error.
Below is the code that is causing these issues:
//Testing with dummy variables
let a1 = NSDecimalNumber(decimal: 5.2)
let a2 = NSDecimalNumber(decimal: 10.8)
print ("a1: \(a1), a2: \(a2)") //a1: 5.2, a2: 10.8
let a3 = a1.adding(a2)
print ("a3: \(a3)") //a3: 16
//Great, everything above works fine.
//Now let's try using my NSManagedObjects, which were defined in another section
let a = result.netChange //result.netChange is of class NSDecimalNumber
let b = newTransaction.amount //newTransaction.amount is of class NSDecimalNumber
print ("a: \(a), b: \(b)") //a: 444.12, b: 22.23
let c = a.adding(b) //<---This is where the app crashes
print ("c: \(c)") //Does not print, as the app has stopped
My question: Why are my dummy variables able to add with each other, while my NSManagedObject variables cannot?
Thanks again!
A core data property of type "Double" is stored as NSNumber in the
managed object context. It is not sufficient to change the type in the
NSManagedObject subclass because the accessor methods are created
dynamically at runtime. Your code compiles, but crashes at runtime
because the variable is a NSNumber and not a NSDecimalNumber.
The solution is to set the type to "Decimal" in the Core Data model
inspector.
My Swift code has this:
#objc protocol MyDelegate {
func buttonPressed(buttonNum: Int, packet: Packet?)
}
Then my objective-c code for the delegate has this:
- (void)buttonPressed:(NSInteger)buttonNum :(Packet * _Nullable) packet {
}
But I'm getting a "function not implemented" warning. My experiments seem to indicate that there's something wrong with that nullable pointer. I.e. if there was no "?" in the Swift proto declaration and no "_Nullable" in the Object-c function then all is well.
Does anyone know what I need to do on the Objective-c side to implement that function for that proto?
The problem is not due to the nullability of the parameter, but due to the selector name.
func buttonPressed(buttonNum: Int, packet: Packet?)
should get a
buttonPressed:packet:
Objective-C function. Yours is buttonPressed:: - no label for the second parameter.
The confusion might have been caused by the fact that Swift automatically infers labels starting with the second parameter - if no label is specified, then the label is assumed to be the parameter name. This is why in Swift you'd need to call the protocol function as buttonPressed(arg1, packet: arg2).
Now you can either add the packet label to the Objective-C selector, or you can remove it from the Swift function declaration, like this:
func buttonPressed(buttonNum: Int, _ packet: Packet?)
You can then call it from Swift like buttonPressed(arg1, arg2). It's up to you which approach you choose, although I'd recommend going with the labeled one as is more clear, at least in Objective-C.
extension SKPhysicsBody {
/// anchorPoint version of init(rectangleOfSize:center:)
convenience init(rectangleOfSize s: CGSize, withAnchorPoint anchorPoint: CGPoint) {
var center = CGPoint()
center.x = (s.width / 2) - ( s.width * anchorPoint.x)
center.y = (s.height / 2 ) - ( s.height * anchorPoint.y)
self.init(rectangleOfSize: s, center: center)
}
}
I got this error on runtime
-[PKPhysicsBody initWithRectangleOfSize:withAnchorPoint:]: unrecognized selector sent to instance 0x7f9b03c4fff0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PKPhysicsBody initWithRectangleOfSize:withAnchorPoint:]: unrecognized selector sent to instance 0x7f9b03c4fff0'
This is how I call in code
// redBox is a typical SKSpriteNode()
redBox.physicsBody = SKPhysicsBody(rectangleOfSize: redBox.frame.size, withAnchorPoint: redBox.anchorPoint)
I basically want to extend the SKPhysicsBody class to provide a convenience initializer to its factory method
As #Cristik guessed in the comments, this is the same root problem as this question and this question: the public SKPhysicsBody class is a convenience interface for the private PKPhysicsBody class that provides its implementation.
In the past, this approach relied heavily on the "duck typing" behavior of Objective-C — as long as ClassA responds to all the same selectors as ClassB, you can call any of those selectors on a pointer whose static type (the type declared to the compiler in source code) is ClassB, even if the actual object at run time is really an instance of ClassA.
Swift is stricter about runtime type correctness than ObjC, so "duck typing" alone is not enough. Since iOS 9 / OS X 10.11, SpriteKit has some workarounds that allow PKPhysicsBody instances to better pretend to be SKPhysicsBody instances.
But those don't cover all cases — in particular, it doesn't catch (ObjC) [SKPhysicsBody alloc] returning a PKPhysicsBody instance, which means any attempt to add initializers to SKPhysicsBody in Swift will fail. (Because the ObjC alloc/init process is reduced to one initializer call in Swift.)
I'd consider this a bug and recommend filing it with Apple.
Edit/update: And until that bug gets fixed (it's been a year and some now), the workaround is to make your convenience "initializer" into a class method instead. (Or a global function if you must, but... ewww.)