Closed catabriga closed 4 weeks ago
Hi, are you trying to set an ad size manually?
I'm not changing the ad size manually.
Here are the only scripts that interact with the addon in my code:
extends Control
var ad_view : AdView
signal ad_loaded
func _ready():
#The initializate needs to be done only once, ideally at app launch.
MobileAds.initialize()
create_ad_view()
func create_ad_view() -> void:
print("create_ad_view")
var ad_switch = get_node("GameAdSwitch")
if ad_switch.are_ads_enabled():
if ad_view:
destroy_ad_view()
var unit_id = ad_switch.get_ad_unit_id()
ad_view = AdView.new(unit_id, AdSize.FULL_BANNER, AdPosition.Values.BOTTOM)
register_ad_listener()
var ad_request := AdRequest.new()
ad_view.load_ad(ad_request)
func destroy_ad_view() -> void:
print("destroy_ad_view")
if ad_view:
#always call this method on all AdFormats to free memory on Android/iOS
ad_view.destroy()
ad_view = null
func register_ad_listener() -> void:
print("register_ad_listener")
if ad_view != null:
print("ad_view not null")
var ad_listener := AdListener.new()
ad_listener.on_ad_failed_to_load = func(load_ad_error : LoadAdError) -> void:
print("_on_ad_failed_to_load: " + load_ad_error.message)
ad_listener.on_ad_clicked = func() -> void:
print("_on_ad_clicked")
ad_listener.on_ad_closed = func() -> void:
print("_on_ad_closed")
ad_listener.on_ad_impression = func() -> void:
print("_on_ad_impression")
ad_listener.on_ad_loaded = func() -> void:
print("_on_ad_loaded")
print(ad_view.get_width(), ' ', ad_view.get_height())
print(ad_view.get_width_in_pixels(), ' ', ad_view.get_height_in_pixels())
ad_loaded.emit()
ad_listener.on_ad_opened = func() -> void:
print("_on_ad_opened")
ad_view.ad_listener = ad_listener
And also this one:
extends MarginContainer
# Called when the node enters the scene tree for the first time.
func _ready():
visibility_changed.connect(_update_size)
var ad_holder = get_node("/root/GameRootNode/Ad_holder")
ad_holder.ad_loaded.connect(_update_size)
func _on_visibility_changed():
#print("_on_visibility_changed")
_update_size.call_deferred()
func _update_size():
#print("_update_size")
#var ad_holder = get_tree().get_root().find_child("Ad_holder")
var ad_holder = get_node("/root/GameRootNode/Ad_holder")
if ad_holder.ad_view:
self.custom_minimum_size.x = ad_holder.ad_view.get_width_in_pixels()
self.custom_minimum_size.y = ad_holder.ad_view.get_height_in_pixels()
else:
self.custom_minimum_size.x = 0
self.custom_minimum_size.y = 0
I have created a PR that solves this issue: https://github.com/poingstudios/godot-admob-android/pull/233
Thank you I will review
@catabriga merged, will be on v3.0.5 soon, thank you very much!
Godot version
4.2.2
Plugin version
v3.1.1
Phone information
Motorola One Vision Android 11
Issue description
Sometimes the app crashes due to a fatal exception in the admob addon. The issue appears to happen when the width of the banner is requested but the ad size has not been initialized yet. This happens because the mAdSize variable is labeled as lateinit, but it is possible for godot to try to access it before it is initialized.
Here is a stacktrace of a crash:
Steps to reproduce
The crash does not happen very frequently. To reproduce it reliably I made my app automatically change between two screens such as that one of the screens shows a banner and the other does not. This causes the banner to repeatedly load and unload, which triggers the crash after some minutes.
Additional context
No response