Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Fixes Null Reference + Qdel Issue in Runechat (tgstation#50830)
Browse files Browse the repository at this point in the history
* runtimes bye bye

* rohesie wants it this way

* oranges fixies

* more rohesie suggestions

* cleanies

* on parent qdel moment
  • Loading branch information
bobbah authored May 3, 2020
1 parent 012a625 commit af67cbf
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions code/datums/chatmessage.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* * extra_classes - Extra classes to apply to the span that holds the text
* * lifespan - The lifespan of the message in deciseconds
*/
/datum/chatmessage/New(text, atom/target, mob/owner, list/extra_classes = null, lifespan = CHAT_MESSAGE_LIFESPAN)
/datum/chatmessage/New(text, atom/target, mob/owner, list/extra_classes = list(), lifespan = CHAT_MESSAGE_LIFESPAN)
. = ..()
if (!istype(target))
CRASH("Invalid target given for chatmessage")
Expand All @@ -55,6 +55,12 @@
message = null
return ..()

/**
* Calls qdel on the chatmessage when its parent is deleted, used to register qdel signal
*/
/datum/chatmessage/proc/on_parent_qdel()
qdel(src)

/**
* Generates a chat message image representation
*
Expand All @@ -68,7 +74,7 @@
/datum/chatmessage/proc/generate_image(text, atom/target, mob/owner, list/extra_classes, lifespan)
// Register client who owns this message
owned_by = owner.client
RegisterSignal(owned_by, COMSIG_PARENT_QDELETING, .proc/qdel, src)
RegisterSignal(owned_by, COMSIG_PARENT_QDELETING, .proc/on_parent_qdel)

// Clip message
var/maxlen = owned_by.prefs.max_chat_length
Expand Down Expand Up @@ -108,7 +114,7 @@
// BYOND Bug #2563917
// Construct text
var/static/regex/html_metachars = new(@"&[A-Za-z]{1,7};", "g")
var/complete_text = "<span class='center maptext [extra_classes != null ? extra_classes.Join(" ") : ""]' style='color: [tgt_color]'>[text]</span>"
var/complete_text = "<span class='center maptext [extra_classes.Join(" ")]' style='color: [tgt_color]'>[text]</span>"
var/mheight = WXH_TO_HEIGHT(owned_by.MeasureText(replacetext(complete_text, html_metachars, "m"), null, CHAT_MESSAGE_WIDTH))
approx_lines = max(1, mheight / CHAT_MESSAGE_APPROX_LHEIGHT)

Expand Down Expand Up @@ -166,7 +172,7 @@
*/
/mob/proc/create_chat_message(atom/movable/speaker, datum/language/message_language, raw_message, list/spans, message_mode)
// Ensure the list we are using, if present, is a copy so we don't modify the list provided to us
spans = spans?.Copy()
spans = spans ? spans.Copy() : list()

// Check for virtual speakers (aka hearing a message through a radio)
var/atom/movable/originalSpeaker = speaker
Expand Down

0 comments on commit af67cbf

Please sign in to comment.